安装tomcat
Windows 系统中下载网址:http://tomcat.apache.org/download-80
选择core 下的tar.gz版本

下载后通过ssh
将文件考入linux系统

解压tomcat安装到 /usr/local目录下
tar -xvf apache-tomcat-8.5.32.tar.gz -C/usr/local
-C 选项的作用是:指定需要解压到的目录。



解压完成后
访问tomcat路径 到bin 目录下执行sh startup.sh或者./startup.sh 开启tomcat

查看当前tomcat是否运行以及端口号
使用ps -ef | grep tomcat查看tomcat进程是否启动
第一步:先查看tomcat占用的进程号
ps -ef|grep tomcat

第二步:根据进程号1581,查看进程所占用的端口
netstat -nltp

由此得知,tomcat的进程号是1581,并得到端口号8080
Tomcat默认端口
8005端口是用来关闭TOMCAT服务的端口。
8080端口,负责建立HTTP连接。在通过浏览器访问Tomcat服务器的Web应用时,使用的就是这个连接器。
8009端口,负责和其他的HTTP服务器建立连接。在把Tomcat与其他HTTP服务器集成时,就需要用到这个连接器。
关闭tomcat
同样在tomcat的bin目录下,使用sh shutdown.sh可以关闭tomcat
修改tomcat端口号:
到tomcat的conf目录下
vim server.xml
在这里 把 port 改成你想要的端口号

在实际CentOS实际操作中 发现无法实现外部 访问linux内部
主要原因在于防火墙的存在,导致的端口无法访问。
CentOS7使用firewall而不是iptables。所以解决这类问题可以通过添加firewall的端口,使其对我们需要用的端口开放。
[if !supportLists]1. [endif]使用命令 firewall-cmd --state查看防火墙状态。得到结果是running或者not running

2.在running 状态下,向firewall 添加需要开放的端口
命令为 firewall-cmd --permanent --zone=public --add-port=8080/tcp //永久的添加该端口。去掉--permanent则表示临时。

4.firewall-cmd --reload //加载配置,使得修改有效。

5.使用命令 firewall-cmd --permanent --zone=public --list-ports //查看开启的端口,出现8080/tcp这开启正确

6.再次使用外部浏览器访问,这出现tomcat的欢迎界面。

补充(CentOS7以下有专门的防火墙操作命令):
开启防火墙的命令
systemctl start firewalld.service
关闭防火墙的命令
systemctl stop firewalld.service
开机自动启动
systemctl enable firewalld.service
关闭开机自动启动
systemctl disable firewalld.service
查看防火墙状态
systemctl status firewalld
网友评论