下载tomcat,过程略
安装Daemon 自启动
cd /usr/local/apache-tomcat-8.0.32/bin
tar -zxvf commons-daemon-native.tar.gz
cd /usr/local/apache-tomcat-8.0.32/bin/commons-daemon-1.0.15-native-src/unix
./configure
make
cp jsvc ../..
新增tomcat用户并赋权限
useradd -r tomcat
chown -R tomcat: /usr/local/apache-tomcat-8.0.32
编写系统服务(关键)
vim /usr/lib/systemd/system/tomcatd.service
填入内容:
Description=Apache Tomcat Web Application Container
After=network.target syslog.target
[Service]
Type=forking
PIDFile=/var/run/tomcatd.pid
Environment=CATALINA_PID=/var/run/tomcatd.pid
Environment=JAVA_HOME=/usr/local/java/jdk1.8.0_74
Environment=CATALINA_HOME=/usr/local/apache-tomcat-8.0.32
ExecStart=/usr/local/apache-tomcat-8.0.32/bin/daemon.sh start
ExecStop=/usr/local/apache-tomcat-8.0.32/bin/daemon.sh stop
[Install]
WantedBy=multi-user.target
将tomcat加入系统自启动
systemctl enable tomcatd.service
测试是否能启动
ps -aux| grep tomcat
重启服务
systemctl stop tomcatd.service
systemctl start tomcatd.service