1、centos7 使用 systemctl 替换了 service命令
查看全部服务命令:
systemctl list-unit-files --type service
查看服务
systemctl status name.service
启动服务
systemctl start name.service
停止服务
systemctl stop name.service
重启服务
systemctl restart name.service增加开机启动
systemctl enable name.service
删除开机启动
systemctl disable name.service
其中.service 可以省略。
2、增加tomcat.service
1、修改tomcat文件配置
vim /etc/init.d/tomcat
【注意】:将JAVA_HOME和CATALINA_HOME配置成自己的地址
#!/bin/bash
#
# tomcat startup script for the Tomcat server
#
# chkconfig: 2345 10 90
# description: start the tomcat deamon
#
# Source function library
. /etc/rc.d/init.d/functions
prog=tomcat
JAVA_HOME=/usr/local/jdk1.8.0_161
export JAVA_HOME
CATALANA_HOME=/opt/apache-tomcat-8.5.24/
export CATALINA_HOME
case "$1" in
start)
echo "Starting Tomcat..."
$CATALANA_HOME/bin/startup.sh
;;
stop)
echo "Stopping Tomcat..."
$CATALANA_HOME/bin/shutdown.sh
;;
restart)
echo "Stopping Tomcat..."
$CATALANA_HOME/bin/shutdown.sh
sleep 2
echo
echo "Starting Tomcat..."
$CATALANA_HOME/bin/startup.sh
;;
*)
echo "Usage: $prog {start|stop|restart}"
;;
esac
exit 0
2、配置
chmod 755 /etc/init.d/tomcat
使用chkconfig --add
命令添加服务
[root
@localhost
~]# chkconfig --add tomcat
完成。
使用命令进行tomcat 服务的启动和停止
service tomcat start 启动tomcat服务
service tomcat stop 停止tomcat服务