1、设置Tomcat开机自启
在/etc/systemd/system路径下创建tomcat.service文件
命令:vim /etc/systemd/system/tomcat.service
将以下内容添加到omcat.service中:
bash
[Unit]
Description=tomcat-server
After=network.target
[Service]
Type=forking
Environment="JAVA_HOME=/opt/jdk1.6.0_45" #jdk安装目录
ExecStart=/home/apache-tomcat-7.0.100/bin/startup.sh #tomcat安装目录
ExecStop=/home/apache-tomcat-7.0.100/bin/shutdown.sh #tomcat安装目录
ExecReload=/bin/kill -s HUP $MAINPID
User=root
Group=root
[Install]
WantedBy=multi-user.target
2、重新加载 systemd 的配置
bash
systemctl daemon-reload
3、启用Tomcat服务
bash
systemctl enable tomcat.service
4、使用以下命令启动 Tomcat 服务,测试之前记得停止运行的tomcat
bash
systemctl start tomcat.service
5、查看启动状态,如下图:
bash
systemctl status tomcat.service
