首页 技术 正文
技术 2022年11月9日
0 收藏 505 点赞 2,568 浏览 1371 个字

本文转载:http://blog.chinaunix.net/uid-24648266-id-5729891.html

CentOS7开始,从/etc/init.d脚本改为了systemctl管理服务。

亲自测试成功。

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. [Service]
  5. Type=forking
  6. Environment=”JAVA_HOME=/home/jdk/jdk1.7.0_79″
  7. PIDFile=/home/tomcat/apache-tomcat-7.0.47/tomcat.pid
  8. ExecStart=/home/tomcat/apache-tomcat-7.0.47/bin/startup.sh
  9. ExecReload=/bin/kill -s HUP $MAINPID
  10. ExecStop=/bin/kill -s QUIT $MAINPID
  11. PrivateTmp=true
  12. [Install]
  13. WantedBy=multi-user.target

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

3.设置为开机启动

  1. 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  

启动tomcat服务

systemctl start tomcat.service

设置开机自启动

systemctl enable tomcat.service

停止开机自启动

systemctl disable tomcat.service

查看服务当前状态

systemctl status tomcat.service

重新启动服务

systemctl restart tomcat.service

查看所有已启动的服务

systemctl list-units --type=service
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,087
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,562
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,821
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905