1.下载
下载地址:https://tomcat.apache.org/download-80.cgi
[root@centos7 ~]# wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.34/bin/apache-tomcat-8.5.34.tar.gz
[root@centos7 ~]# tar -zxvf apache-tomcat-8.5.34.tar.gz
[root@centos7 ~]# mv apache-tomcat-8.5.34 /usr/tomcat8.5
2.启动
进入/usr/tomcat8.5/bin 目录
启动
[root@centos7 ~]# ./startup.sh
查看是否启动成功(8080 已经启动成功)
[root@centos7 ~]# netstat -nltp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1632/mysqld
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1000/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1118/master
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 11118/java
tcp6 0 0 :::8009 :::* LISTEN 11118/java
tcp6 0 0 :::8080 :::* LISTEN 11118/java
tcp6 0 0 :::22 :::* LISTEN 1000/sshd
tcp6 0 0 ::1:25 :::* LISTEN 1118/master
问题:在linux上开启的tomcat使用浏览器访问不了。
主要原因在于防火墙的存在,导致的端口无法访问。
CentOS7使用firewall而不是iptables。所以解决这类问题可以通过添加firewall的端口,使其对我们需要用的端口开放。
1.使用命令 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下列显示表示没有问题。