CentOS6 Tomcat 自启动服务脚本

 在文件夹"/etc/init.d"中新建文件"tomact8"

#!/bin/sh
# 
# tomcat startup script for the Tomcat server 
# 
# chkconfig: 345 80 20 
# description: start the tomcat deamon 
# 
# Source function library 
. /etc/rc.d/init.d/functions 

prog=tomcat8
export JAVA_HOME=/usr/java/jdk1.8.0_202
export CATALANA_HOME=/opt/tomcat/apache-tomcat-8.5.42-1
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 3
  echo 
  echo "Starting Tomcat..." 
  $CATALANA_HOME/bin/startup.sh 
  ;; 
*) 
  echo "Usage: $prog {start|stop|restart}" 
  ;; 
esac 
exit 0

 

之后授权:

chmod a+x /etc/init.d/tomcat8

再加入启动服务:

chkconfig --add tomcat8

运行服务命令:

service tomcat8 start #启动

service tomcat8 stop #停止

 

 

如果需要部署多个tomcat集群:

1.需要将tomcat目录复制多份并修改端口不冲突;

2.启动脚本"/etc/init.d/tomcat8",可以设置不同名称,如"/etc/init.d/tomcat8-1","/etc/init.d/tomcat8-2","/etc/init.d/tomcat8-3",并设置CATALANA_HOME为不同tomcat目录

你可能感兴趣的:(Tomcat,Linux)