在安装成功后并能正常访问的基础上,设置开机自动启动
[root@localhost ~]# vim /etc/rc.d/rc.local
[root@localhost ~]# vim /usr/lib/systemd/system/tomcat.service
[root@localhost ~]# systemctl enable tomcat.service
Created symlink /etc/systemd/system/multi-user.target.wants/tomcat.service → /usr/lib/systemd/system/tomcat.service.
[root@localhost ~]#
1、修改bin目录下的catalina.sh
文件,添加如下内容
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
进入到/usr/local/tomcat/apache-tomcat-9.0.38/bin
下执行命令vim catalina.sh
2、创建文件tomcat.service
vim /usr/lib/systemd/system/tomcat.service
添加下面的内容,注意修改JAVA_HOME和tomcat路径
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment="JAVA_HOME=/usr/local/jdk/jdk1.8.0_161"
PIDFile=/usr/local/tomcat/apache-tomcat-9.0.38/tomcat.pid
ExecStart=/usr/local/tomcat/apache-tomcat-9.0.38/bin/startup.sh
ExecStop=/bin/kill -s QUIT $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
3、设置开机自启
systemctl enable tomcat.service
systemctl daemon-reload #重新载入修改后配置文件,让设置生效
systemctl start tomcat.service #启动服务
systemctl enable tomcat.service #设置为开机自启动
systemctl status tomcat.service #查看服务运行状态
然后将虚拟机关机,再开机就会发现tomcat已经可以访问了