我使用centos7X64最小化安装
CentOS-7-x86_64-Minimal-1708
没装jdk的同学,请移步【centos7 安装 jdk8 的正确姿势 并设置开机自启】的文章
关闭防火墙和加入放行端口二选一
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
[root@localhost ~]# firewall-cmd --state
not running
[root@localhost ~]#
firewall-cmd --zone=public --add-port=18080/tcp --permanent #添加放行端口(--permanent永久生效,没有此参数重启后失效)
firewall-cmd --zone=public --add-port=28080/tcp --permanent #添加放行端口(--permanent永久生效,没有此参数重启后失效)
firewall-cmd --zone=public --add-port=38080/tcp --permanent #添加放行端口(--permanent永久生效,没有此参数重启后失效)
firewall-cmd --reload #刷新防火墙 使其生效
firewall-cmd --zone=public --list-ports #查看防火墙放行端口列表
[root@localhost ~]# firewall-cmd --zone=public --add-port=18080/tcp --permanent #添加放行端口(--permanent永久生效,没有此参数重启后失效)
success
[root@localhost ~]# firewall-cmd --zone=public --add-port=28080/tcp --permanent #添加放行端口(--permanent永久生效,没有此参数重启后失效)
success
[root@localhost ~]# firewall-cmd --zone=public --add-port=38080/tcp --permanent #添加放行端口(--permanent永久生效,没有此参数重启后失效)
success
[root@localhost ~]# firewall-cmd --reload #刷新防火墙 使其生效
success
[root@localhost ~]# firewall-cmd --zone=public --list-ports #查看防火墙放行端口列表
80/tcp 8080/tcp 18080/tcp 28080/tcp 38080/tcp
[root@localhost ~]#
yum -y install wget
wget http://mirrors.shuosc.org/apache/tomcat/tomcat-8/v8.5.24/bin/apache-tomcat-8.5.24.tar.gz
tar -zxvf apache-tomcat-8.5.24.tar.gz
mv apache-tomcat-8.5.24 /usr/local/tomcat8-node1
vi /usr/local/tomcat8-node1/bin/catalina.sh
在 OS specific support. 前面加入如下代码:
JAVA_HOME=/usr/local/java/jdk1.8.0_151
JRE_HOME=$JAVA_HOME/jre
cp /usr/local/tomcat8-node1 /usr/local/tomcat8-node2
cp /usr/local/tomcat8-node1 /usr/local/tomcat8-node3
vi /usr/local/tomcat8-node1/conf/server.xml
vi /usr/local/tomcat8-node2/conf/server.xml
vi /usr/local/tomcat8-node3/conf/server.xml
<Server port="8005" shutdown="SHUTDOWN">
<Connector port="8080" protocol="HTTP/1.1" redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
习惯上对应改为:
tomcat8-node1: 18005 18080 18009
tomcat8-node2: 28005 28080 28009
tomcat8-node3: 38005 38080 38009
在/usr/lib/systemd/system目录下增加tomcat8-node1.service,tomcat8-node2.service,tomcat8-node3.service文件,具体内容如下:
vi /usr/lib/systemd/system/tomcat8-node1.service
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=oneshot
ExecStart=/usr/local/tomcat8-node1/bin/startup.sh
ExecStop=/usr/local/tomcat8-node1/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
vi /usr/lib/systemd/system/tomcat8-node2.service
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=oneshot
ExecStart=/usr/local/tomcat8-node2/bin/startup.sh
ExecStop=/usr/local/tomcat8-node2/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
vi /usr/lib/systemd/system/tomcat8-node3.service
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=oneshot
ExecStart=/usr/local/tomcat8-node3/bin/startup.sh
ExecStop=/usr/local/tomcat8-node3/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
systemctl enable tomcat8-node1
systemctl enable tomcat8-node2
systemctl enable tomcat8-node3
systemctl start tomcat8-node1.service #启动tomcat
systemctl stop tomcat8-node1.service #关闭tomcat
systemctl restart tomcat8-node1.service #重启tomcat
systemctl status tomcat8-node1.service #查看状态tomcat
systemctl enable tomcat8-node1.service #允许开机自启