我使用centos7X64最小化安装
CentOS-7-x86_64-Minimal-1708
没装jdk的同学,请移步【centos7 安装 jdk8】的文章
1.关闭firewall:
1 2 3
| systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机启动 firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
|
1 2 3
| [root@localhost ~]# firewall-cmd --state not running [root@localhost ~]#
|
2.安装wget
3.下载tomcat8
1
| wget http://mirrors.shuosc.org/apache/tomcat/tomcat-8/v8.5.24/bin/apache-tomcat-8.5.24.tar.gz
|
4.解压
1
| tar -zxvf apache-tomcat-8.5.24.tar.gz
|
5.移动到/usr/local
1
| mv apache-tomcat-8.5.24 /usr/local/tomcat8-node1
|
6.配置tomcat的jdk环境变量
1
| vi /usr/local/tomcat8-node1/conf/catalina.sh
|
在 OS specific support. 前面加入如下代码:
1 2
| JAVA_HOME=/usr/local/java/jdk1.8.0_151 JRE_HOME=$JAVA_HOME/jre
|
7.复制两份tomcat8-node1并重命名为tomcat8-node2,tomcat8-node3
1 2
| cp /usr/local/tomcat8-node1 /usr/local/tomcat8-node2 cp /usr/local/tomcat8-node1 /usr/local/tomcat8-node3
|
8.修改tomcat8-node1,,tomcat8-node2和tomcat8-node3端口,共三处
1 2 3
| vi /usr/local/tomcat8-node1/conf/server.xml vi /usr/local/tomcat8-node2/conf/server.xml vi /usr/local/tomcat8-node3/conf/server.xml
|
1 2 3
| <Server port="8005" shutdown="SHUTDOWN"> <Connector port="8080" protocol="HTTP/1.1" redirectPort="8443" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
|
习惯上对应改为:
1 2 3
| tomcat8-node1: 18005 18080 18009 tomcat8-node2: 28005 28080 28009 tomcat8-node3: 38005 38080 38009
|
7.配置tomcat8-node1,tomcat8-node2,tomcat8-node3开机启动
1
| 在/usr/lib/systemd/system目录下增加tomcat8-node1.service,tomcat8-node2.service,tomcat8-node3.service文件,具体内容如下:
|
1
| vi /usr/lib/systemd/system/tomcat8-node1.service
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| [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
|
1
| vi /usr/lib/systemd/system/tomcat8-node2.service
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| [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
|
1
| vi /usr/lib/systemd/system/tomcat8-node3.service
|
1 2 3 4 5 6 7 8 9 10 11 12 13
| [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
|
8.允许tomcat8-node1,tomcat8-node2,tomcat8-node3开机启动
1 2 3
| systemctl enable tomcat8-node1 systemctl enable tomcat8-node2 systemctl enable tomcat8-node3
|
9.tomcat8常见命令
1 2 3 4 5 6 7
| systemctl start tomcat8-node1.service //启动tomcat
systemctl stop tomcat8-node1.service //关闭tomcat
systemctl restart tomcat8-node1.service //重启tomcat
systemctl status tomcat8-node1.service //查看状态tomcat
|