Loading... 首先在 `/etc/init.d` 创建名称为`tomcat`的文件 加入以下文件 二者都可以 ```css #!/bin/sh # chkconfig: 345 99 10 # description: Auto-starts tomcat # /etc/init.d/tomcatd # Tomcat auto-start # Source function library. . /etc/init.d/functions # source networking configuration. . /etc/sysconfig/network RETVAL=0 export JAVA_HOME=/usr/local/java/jdk1.8.0_171 export CATALINA_HOME=/usr/local/tomcat-9/apache-tomcat-9.0.8 export CATALINA_BASE=/usr/local/tomcat-9/apache-tomcat-9.0.8 start() { if [ -f $CATALINA_HOME/bin/startup.sh ]; then echo $"Starting Tomcat" $CATALINA_HOME/bin/startup.sh RETVAL=$? echo " OK" return $RETVAL fi } stop() { if [ -f $CATALINA_HOME/bin/shutdown.sh ]; then echo $"Stopping Tomcat" $CATALINA_HOME/bin/shutdown.sh RETVAL=$? sleep 1 ps -fwwu tomcat | grep apache-tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9 echo " OK" # [ $RETVAL -eq 0 ] && rm -f /var/lock/... return $RETVAL fi } case "$1" in start) start ;; stop) stop ;; restart) echo $"Restaring Tomcat" $0 stop sleep 1 $0 start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 ;; esac exit $RETVAL ``` ```css #!/bin/bash # chkconfig: 2345 55 25 # description: tomcat Service ### BEGIN INIT INFO # Provides: tomcat # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts tomcat # Description: starts the tomcat ### END INIT INFO path=/tomcat/bin cd $path bash daemon.sh $1 ``` `修改文件的执行权限,使用命令chmod 777 tomcat` `将其添加到系统服务,使用命令:chkconfig --add tomcat` `service tomcat start/stop/restart 启动关闭重启` `使用chkconfig --list查看服务是否添加成功` 至此,linux环境下配置tomcat开机自动启动就成功了。重启后会发现tomcat已自动启动。 但是,如果你又不想让它自动启动了,可以使用`chkconfig tomcat on/off`切换开机启动关闭 最后修改:2021 年 06 月 16 日 © 允许规范转载 打赏 赞赏作者 微信 赞 0 如果觉得我的文章对你有用,请随意赞赏
此处评论已关闭