Centos7命令行安装Tomcat以及配置防火墙开放端口
【转载】Centos 7 yum安装tomcat 命令:
系统环境
CentOS Linux release 7.2.1511 (Core)
一、搭建准备:
1、先到tomcat官网https://tomcat.apache.org/查看下载路径
2、安装wget
[root@ecs-19cb ~]# yum install -y wget
3、确认是否安装成功
[root@ecs-19cb ~]# rpm -qa | grep wget wget-1.14-15.el7_4.1.x86_64
4、wget下载
[root@ecs-19cb ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.17/bin/apache-tomcat-9.0.17.tar.gz [root@ecs-19cb ~]# ll total 9272 -rw-r--r-- 1 root root 9471519 Jan 19 04:03 apache-tomcat-9.0.4.tar.gz
5、选择yum安装tomcat需要的jdk,就不用再手动配置环境变量。
[root@ecs-19cb ~]# yum -y install java-1.8*
6、查看版本
[root@ecs-19cb ~]# java -version openjdk version "1.8.0_161" OpenJDK Runtime Environment (build 1.8.0_161-b14) OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
二、解压并启动:
1、解压
[root@ecs-19cb ~]# tar -zxvf apache-tomcat-9.0.4.tar.gz [root@ecs-19cb ~]# ll total 9276 drwxr-xr-x 9 root root 4096 Feb 3 13:59 apache-tomcat-9.0.4 -rw-r--r-- 1 root root 9471519 Jan 19 04:03 apache-tomcat-9.0.4.tar.gz
2、启动tomcat,显示tomcat started就是成功启动
[root@ecs-19cb ~]# ll total 9276 drwxr-xr-x 9 root root 4096 Feb 3 13:59 apache-tomcat-9.0.4 -rw-r--r-- 1 root root 9471519 Jan 19 04:03 apache-tomcat-9.0.4.tar.gz [root@ecs-19cb ~]# cd apache-tomcat-9.0.4/ [root@ecs-19cb apache-tomcat-9.0.4]# ./bin/startup.sh Using CATALINA_BASE: /root/apache-tomcat-9.0.4 Using CATALINA_HOME: /root/apache-tomcat-9.0.4 Using CATALINA_TMPDIR: /root/apache-tomcat-9.0.4/temp Using JRE_HOME: /usr Using CLASSPATH: /root/apache-tomcat-9.0.4/bin/bootstrap.jar:/root/apache-tomcat-9.0.4/bin/tomcat-juli.jar Tomcat started.
3、关闭防火墙
[root@ecs-19cb etc]# systemctl stop firewalld [root@ecs-19cb etc]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:firewalld(1)
4、查看tomcat默认端口8080是否开启
[root@ecs-19cb ~]# netstat -ntlp 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:111 0.0.0.0:* LISTEN 1/systemd tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1528/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1123/master tcp 0 0 127.0.0.1:32001 0.0.0.0:* LISTEN 1541/java tcp6 0 0 :::8009 :::* LISTEN 11809/java tcp6 0 0 :::111 :::* LISTEN 1/systemd tcp6 0 0 :::8080 :::* LISTEN 11809/java tcp6 0 0 :::22 :::* LISTEN 1528/sshd tcp6 0 0 ::1:25 :::* LISTEN 1123/master tcp6 0 0 127.0.0.1:8005 :::* LISTEN 11809/java
三、浏览器打开:http://ip:8080
Centos 7 firewall 命令:
查看已经开放的端口:
firewall-cmd --list-ports
开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:
–zone #作用域
–add-port=80/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
重启防火墙
firewall-cmd --reload #重启firewall
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
原参考博文:tomcat安装:https://blog.csdn.net/tladagio/article/details/79246417
将tomcat服务添加以及自启动:https://blog.csdn.net/taozibug/article/details/80269008
防火墙配置: https://www.cnblogs.com/eaglezb/p/6073739.html
参考博文中使用的是yum安装,比较方便,而且很详细,这里mark一下,感谢原创作者的的分享。
GGSDDU