CentOS7 安装tomcat7.x为系统服务器 Systemctl管理Tomcat

1.首先,需要为tomcat配置pid。

bin/catalina.sh

 
  1. # Copy CATALINA_BASE from CATALINA_HOME if not already set

  2. [ -z "$CATALINA_BASE" ] && CATALINA_BASE="$CATALINA_HOME"

  3. # 设置pid。一定要加在CATALINA_BASE定义后面,要不然pid会生成到/下面

  4. CATALINA_PID="$CATALINA_BASE/tomcat.pid"

 

tomcat.pid文件与bin目录平级。

 

2.创建tomcat.service文件

/lib/systemd/system/tomcat.service 

 
  1. [Unit]

  2. Description=Tomcat

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

  4.  
  5. [Service]

  6. Type=forking

  7.  
  8. Environment="JAVA_HOME=/home/jdk/jdk1.7.0_79"

  9.  
  10. PIDFile=/home/tomcat/apache-tomcat-7.0.47/tomcat.pid

  11. ExecStart=/home/tomcat/apache-tomcat-7.0.47/bin/startup.sh

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

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

  14. PrivateTmp=true

  15.  
  16. [Install]

  17. WantedBy=multi-user.target

 

Environment="JAVA_HOME=/home/jdk/jdk1.7.0_79" 这里要配置环境变量,在/etc/profile中的配置在系统服务中不生效。

 

3.设置为开机启动

systemctl enable tomcat.service  

 

4.其它

修改tomcat.service文件后需要执行下面命令使其生效:
systemctl daemon-reload

查询tomcat 进程  ps -ef | grep "tomcat"| grep -v grep

如果多个tomcat,则拷贝到不同的目录,使用不同的端口。tomcat.service文件名不同即可。

例如:tomcat1.service tomcat2.service tomcat3.service

 

 

启动nginx服务

systemctl start nginx.service

设置开机自启动

systemctl enable nginx.service

停止开机自启动

systemctl disable nginx.service

查看服务当前状态

systemctl status nginx.service

重新启动服务

systemctl restart nginx.service

查看所有已启动的服务

systemctl list-units --type=service

 

转自:https://blog.csdn.net/nimasike/article/details/51896100#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值