A.在/usr/lib/systemd/system/目录下新建文件tomcat7.service,内容如下:

  1. [Unit]  

  2. Description=Tomcat7  

  3. After=syslog.target network.target remote-fs.target nss-lookup.target  

  4.      

  5. [Service]  

  6. Type=forking  

  7. Environment='JAVA_HOME=/usr/jdk1.7.0_72'  

  8. Environment='CATALINA_PID=/usr/apache-tomcat-7.0.70/bin/tomcat.pid'  

  9. Environment='CATALINA_HOME=/usr/apache-tomcat-7.0.70/'  

  10. Environment='CATALINA_BASE=/usr/apache-tomcat-7.0.70/'  

  11. Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'  

  12.   

  13. WorkingDirectory=/usr/apache-tomcat-7.0.70/  

  14.   

  15. ExecStart=/usr/apache-tomcat-7.0.70/bin/startup.sh  

  16. ExecReload=/bin/kill -s HUP $MAINPID  

  17. ExecStop=/bin/kill -s QUIT $MAINPID  

  18. PrivateTmp=true  

  19.      

  20. [Install]  

  21. WantedBy=multi-user.target  



B,设置为开启机启动:systemctl enable tomcat7


C,启停服务

1,启动服务:systemctl start tomcat7

2,停止服务:systemctl stop tomcat7

3,重启服务:systemctl restart tomcat7