一. 创建 Tomcat 的管理脚本 (1)首先,在系统的/lib/systemd/system/目录下创建tomcat.service文件: # vim /lib/systemd/system/tomcat1.service [Unit] Description=tomcat1 service After=network.target [Service] Type=forking ExecStart=/opt/tomcat1/bin/startup.sh ExecReload=/opt/tomcat1/bin/startup.sh -s reload ExecStop=/opt/tomcat1/bin/shutdown.sh PrivateTmp=true [Install] WantedBy=multi-user.target (2)保存脚本文件后设置文件的执行权限 # chmod a+x /lib/systemd/system/tomcat1.service 二. 指定Tomcat的启动JRE路径 # vim /opt/tomcat1/bin/setclasspath.sh # ----------------------------------------------------------------------------- # Set JAVA_HOME or JRE_HOME if not already set, ensure any provided settings # are valid and consistent with the selected start-up options and set up the # endorsed directory. 在这里面添加 #自己的java路径 export JAVA_HOME=/opt/jdk1.8.0_221/ #自己的jre路径 export JRE_HOME=/opt/jdk1.8.0_221/jre # ----------------------------------------------------------------------------- 三. 使用 systemctl 设置开机自启动 配置完脚本以后,就可以使用以下命令设置开机自启动等操作了 systemctl enable tomcat1.service # 设置开机自启动 systemctl disable tomcat1.service # 停止开机自启动 systemctl start tomcat1.service  # 启动 tomcat 服务 systemctl stop tomcat1.service  # 停止服务 systemctl status tomcat1.service # 查看服务当前状态 systemctl list-units --type=tomcat # 查看所有已启动的服务 systemctl list-unit-files (查看开机启动项) systemctl list-unit-files | grep 程序名称 (查看某些服务开机启动状态) systemctl list-unit-files | grep enable (查看哪些为开机启动服务) 一. 创建 Tomcat 的管理脚本 (1)首先,在系统的/lib/systemd/system/目录下创建tomcat.service文件: # vim /lib/systemd/system/tomcat2.service [Unit] Description=tomcat2 service After=network.target [Service] Type=forking ExecStart=/opt/tomcat2/bin/startup.sh ExecReload=/opt/tomcat2/bin/startup.sh -s reload ExecStop=/opt/tomcat2/bin/shutdown.sh PrivateTmp=true [Install] WantedBy=multi-user.target 2)保存脚本文件后设置文件的执行权限 # chmod a+x /lib/systemd/system/tomcat2.service 二. 指定Tomcat的启动JRE路径 # vim /opt/tomcat2/bin/setclasspath.sh # ----------------------------------------------------------------------------- # Set JAVA_HOME or JRE_HOME if not already set, ensure any provided settings # are valid and consistent with the selected start-up options and set up the # endorsed directory. 在这里面添加 #自己的java路径 export JAVA_HOME=/opt/jdk1.8.0_221/ #自己的jre路径 export JRE_HOME=/opt/jdk1.8.0_221/jre # ----------------------------------------------------------------------------- 三. 使用 systemctl 设置开机自启动 配置完脚本以后,就可以使用以下命令设置开机自启动等操作了 systemctl enable tomcat2.service # 设置开机自启动 systemctl disable tomcat2.service # 停止开机自启动 systemctl start tomcat2.service  # 启动 tomcat 服务 systemctl stop tomcat2.service  # 停止服务 systemctl status tomcat2.service # 查看服务当前状态 systemctl list-units --type=tomcat # 查看所有已启动的服务 systemctl list-unit-files (查看开机启动项) systemctl list-unit-files | grep 程序名称 (查看某些服务开机启动状态) systemctl list-unit-files | grep enable (查看哪些为开机启动服务) 参考文档: https://help.fanruan.com/finereport/doc-view-2934.html