CentOS7中Tomcat设置开机自启动
systemctl方式开机启动设置
配置:将以下内容添加到startup.sh、shutdown.sh、catalina.sh 当中, 并指定jdk路径,文件在/usr/local/tomcat/bin 目录下
export JAVA_HOME=/usr/local/jdk #jdk路径
export TOMCAT_HOME=/usr/local/tomcat #tomcat路径
export CATALINA_HOME=/usr/local/tomcat #tomcat路径
export CLASS_PATH=$JAVA_HOME/bin/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tool.jar
export PATH=$PATH:/usr/local/jdk/bin:/usr/local/tomcat/bin
1. 进入/lib/systemd/system
cd /lib/systemd/system
2. 创建tomcat.service
vi /lib/systemd/system/tomcat.service
3. tomcat.service中添加配置信息
[Unit]
Description=tomcat
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
保存 退出
systemctl enable tomcat.service #(设置开机自启动)
4. 操作命令
systemctl status tomcat.service #(查看服务当前状态)
systemctl start tomcat.service #(启动tomcat服务)
systemctl stop tomcat.service #(停止tomcat服务)
systemctl restart tomcat.service #(重新启动服务)
systemctl reload tomcat.service #(重新加载配置)
systemctl enable tomcat.service #(设置开机自启动)
systemctl disable tomcat.service #(停止开机自启动)
systemctl list-units --type=service #(查看所有已启动的服务)
查看服务启动状态(已启动状态)
Tomcat 访问页面
测试地址:http://192.168.1.128:8080/
5.参考命令
systemctl start *.service #启动服务
systemctl stop *.service #停止服务
systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl --failed #显示启动失败的服务
systemctl is-enabled servicename.service #查询服务是否开机启动
参考文章
优秀不够,你是否无可替代
软件测试交流QQ群:721256703,期待你的加入!!
欢迎关注我的微信公众号:软件测试君
![](https://www.cnblogs.com/images/cnblogs_com/longronglang/1061549/o_QQ%E6%88%AA%E5%9B%BE20190728134401.jpg)