tomcat配置开机自启 Centos 7

安素 2019年09月09日 84次浏览
  1. 为Tomcat添加启动参数pid ,在tomcat/bin 目录下面,创建setenv.sh ,tomcat启动的时候会调用
在setenv.sh增加以下内容:
#add tomcat pid  
CATALINA_PID="$CATALINA_BASE/tomcat.pid"
#add java opts  
JAVA_OPTS="-server -XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M -XX:MaxNewSize=256m"  
  1. 在/usr/lib/systemd/system目录下增加tomcat.service,内容如下:
[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment="JAVA_HOME=/usr/local/java/jdk1.8"
PIDFile=/usr/local/tomcat/tomcat.pid
ExecStart=/usr/apache/apache-tomcat-8.0.53/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

注:/usr/local/java/jdk1.8改为自己的jdk路径
   /usr/local/tomcat改为自己的tomcat路径

3.配置开机启动

systemctl enable tomcat.service

4.其它

启动tomcat:  systemctl start tomcat
 
停止tomcat:  systemctl stop tomcat
 
重启tomcat:  systemctl restart tomcat
 
修改tomcat.service文件后使其生效:systemctl daemon-reload

5.出现的错误

Job for tomcat.service failed because a configured resource limit was exceeded. See "systemctl status tomcat.service" and "journalctl -xe" for details

确保setnev.sh,tomcat.service书写正确,符号,空格要多加注意