測試機器環境:
VMware Workstation 10 虛擬機html
內存:1Gjava
Linux版本:CentOS MinimalCD 7-1804linux
~]# tar xf apache-tomcat-9.0.20.tar.gz
~]# tar xf jdk-8u211-linux-x64.tar.gz
~]# mv apache-tomcat-9.0.20 tomcat
~]# mv jdk1.8.0_211/ jdk
~]# cd tomcat/bin/ ~]# tar xf commons-daemon-native.tar.gz ~]# cd commons-daemon-1.1.0-native-src//unix/ ~]# yum install gcc -y ~]# ./configure --with-java=/opt/jdk ~]# make ~]# cp jsvc ../.. ~]# cd ../..
~]# vi daemon.sh
找到apache
# JAVA_HOME=/opt/jdk-1.6.0.22tomcat
修改成tcp
JAVA_HOME=/opt/jdk測試
[Unit]spa
Description=Apache Tomcat 9unix
After=network.targetcode
[Service]
Type=forking
ExecStart=/opt/tomcat/bin/daemon.sh startup
ExecStop=/opt/tomcat/bin/daemon.sh stop
[Install]
WantedBy=multi-user.target
這裏我是用了daemon.sh文件來管理tomcat的啓動和關閉,也能夠直接使用jsvc來,實際上daemon最後也是調用jsvc來運行的
Systemd 入門教程
http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html
~]# useradd -r -s /sbin/nologin tomcat
受權tomcat用戶對tomcat文件夾有管理權
~]# chown -R tomcat: /opt/tomcat
~]# firewall-cmd --zone=public --add-port=8080/tcp --permanent ~]# firewall-cmd --reload
systemctl daemon-reload 從新裝載
systemctl start tomcat 啓動tomcat
systemctl stop tomcat 中止tomcat
~]# systemctl enable tomcat.service
OK到此tomcat安裝完畢