一、上传Tomcat服务器


二、安装Tomcat服务器
2.1、解压tomcat服务器压缩包


2.2、配置环境变量
tomcat服务器运行时是需要JDK支持的,所以必须配置好JDK用到的那些环境变量

编辑/etc下的profile文件,加上如下内容:

export JAVA_HOME=/opt/modules/jdk1.8.0_172
export PATH=$JAVA_HOME/bin:$PATH
export CATALINA_HOME=/opt/modules/apache-tomcat-8.0.53
export PATH=$PATH:$CATALINA_HOME/bin
2.3、修改tomcat服务器的启动端口

修改将Tomcat服务器启动时使用的端口,例如改成9999

修改完server.xml文件之后,保存,退出。
三、Tomcat服务器启动和关闭
3.1、启动Tomcat服务器
进入tomcat服务器的bin目录,然后执行"./startup.sh"命令启动Tomcat服务器,如下图所示:

查看tomcat服务器的Log信息,看看tomcat服务器是否已经正常启动,进入tomcat服务器下的logs目录,打开catalina.out文件进行查看,如下图所示:

访问Tomcat服务器,如下图所示:

可以正常访问了,说明Tomcat服务器已经正常启动成功了。
如果tomcat启动不了,那么最有可能就是启动时使用的端口被其他应用程序占用了,那么可以通过如下的办法进行排查,例如查看9999端口被哪个应用程序占用了。

3.2、关闭Tomcat服务器
进入tomcat服务器的bin目录,然后执行"./shutdown.sh"命令启动Tomcat服务器,如下图所示:

查看tomcat服务器的Log信息,看看tomcat服务器是否已经正常关闭,进入tomcat服务器下的logs目录,打开catalina.out文件进行查看,如下图所示:

四、部署JavaWeb应用到Tomcat服务器
部署JavaWeb应用到Tomcat服务器就是将开放好的JavaWeb应用打包成war包,然后发布到tomcat服务器的webapps目录下

4.1、打包JavaWeb应用



项目打包成功,如下图所示:

4.2、将war包发布到tomcat服务器的webapps目录下
将JavaWeb应用打包成war包之后,要将这个war包放到tomcat服务器的webapps目录下,由于要部署的javaWeb应用使用的是JNDI数据源,所以首先要把数据库对应的驱动jar包放到tomcat服务器的lib目录下。
1、将Oracle数据库的驱动jar包上传到tomcat服务器的lib目录
如下图所示:

2、将打包好的war包上传到tomcat服务器的webapps目录
如下图所示:
上传war包到webapps目录

上传成功

Tomcat服务器自动解压缩war包

检查一下tomcat服务器是否自动在conf目录下创建了Catalina/localhost目录,在看看localhost目录下是否有tomcat服务器自动创建的oams.xml文件

五、Linux下安装Tomcat服务器使用到的命令
5.1、linux查看端口被哪个进程占用
<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">lsof -i:端口号</pre>
例如:

5.2、查看Linux服务器的版本
<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">lsb_release -a</pre>
例如:

5.3、查看当前iptables(防火墙)规则
可使用"iptables –L –n"查看当前iptables规则
例如:

5.4、添加指定端口到防火墙中
iptables -I INPUT -p 协议 --dport 端口号 -j ACCEPT
例如:
<pre style="margin-top: 0px; margin-bottom: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-family: "Courier New" !important; font-size: 12px !important;">1 iptables -I INPUT -p udp --dport 161 -j ACCEPT 2 iptables -I INPUT -p tcp --dport 8080 -j ACCEPT</pre>
网友评论