使用centos7X64最小化安装
CentOS-7-x86_64-Minimal-1708
1.配置防火墙:
关闭防火墙和加入放行端口二选一
1.1 直接关闭防火墙
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
[root@localhost ~]# firewall-cmd --state
not running
[root@localhost ~]#
1.2 加入放行端口
firewall-cmd --zone=public --add-port=80/tcp --permanent #添加放行端口(--permanent永久生效,没有此参数重启后失效)
firewall-cmd --reload #刷新防火墙 使其生效
firewall-cmd --zone=public --list-ports #查看防火墙放行端口列表
[root@localhost ~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent #(--permanent永久生效,没有此参数重启后.效)
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --zone=public --list-ports
80/tcp 8080/tcp
[root@localhost ~]#
表示成功
2.安装wget
yum -y install wget
3.下载tomcat8
wget http://mirrors.shuosc.org/apache/tomcat/tomcat-8/v8.5.24/bin/apache-tomcat-8.5.24.tar.gz
4.解压
tar -zxvf apache-tomcat-8.5.24.tar.gz
5.移动到/usr/local
mv apache-tomcat-8.5.24 /usr/local/tomcat8
6.配置tomcat的jdk环境变量
yum -y install vim
vim /usr/local/tomcat8/bin/catalina.sh
在 OS specific support. 前面加入如下代码:
JAVA_HOME=/usr/local/java/jdk1.8.0_151
JRE_HOME=$JAVA_HOME/jre
7.配置tomcat8开机启动
在/usr/lib/systemd/system目录下增加tomcat8.service文件,内容如下:
vi /usr/lib/systemd/system/tomcat8.service
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=oneshot
ExecStart=/usr/local/tomcat8/bin/startup.sh
ExecStop=/usr/local/tomcat8/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
8.允许tomcat8开机启动
systemctl enable tomcat8
9.tomcat8常见命令
systemctl start tomcat8.service //启动tomcat
systemctl stop tomcat8.service //关闭tomcat
systemctl restart tomcat8.service //重启tomcat
systemctl status tomcat8.service //查看状态tomcat