本文转载: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

CentOS7 安装tomcat为系统服务器 Systemctl管理Tomcat,并设置开机启动的更多相关文章

  1. CentOS7安装性能监控系统

    目录 系统描述. 开发环境. 开始之前. 安装influxdb数据库. 安装collectd 安装Grafana FAQ       influxdb的web界面没反应.   系统描述 想打造 New ...

  2. centos7安装docker并设置开机启动

    版本要求:查看内核版本,需大于3.10 [root@localhost ~]# uname -r -.el7.x86_64 更新内核:如果是生产机器务必慎重更新内核,避免出现不必要的问题. sudo ...

  3. CentOS7 安装 Redis 并设置开机启动

    1.下载 https://redis.io/download cd /usr/local/src wget -c http://download.redis.io/releases/redis-3.2 ...

  4. CentOS7 nginx 最简单的安装以及设置开机启动

    1. 下载tar包. 2. 解压缩tar包 3. 安装必须的部分 yum包 yum install -y gcc pcre pcre-devel openssl openssl-devel gd gd ...

  5. 源码编译安装nginx及设置开机启动项

    1.上传nginx文档:解压到/data目录下,并安装依赖包tar xf nginx-1.20.1.tar.gz -C /data/cd /data/nginx-1.20.1/ && ...

  6. windows下架设SVN服务器并设置开机启动

    原文:windows下架设SVN服务器并设置开机启动 1.安装SVN服务器,到http://subversion.apache.org/packages.html上下载windows版的SVN,并安装 ...

  7. CentOS 7.6 64位安装docker并设置开机启动

    步骤如下 安装docker.docker-compose yum -y install docker-io docker-compose 启动docker service docker start 设 ...

  8. Centos7关闭防火墙 设置开机启动

    [root@nmserver-7 ~]# systemctl stop firewalld.service [root@nmserver-7 ~]# systemctl status firewall ...

  9. CentOS7 安装MongoDB 3.0服务器

    1,下载&安装 MongoDB 3.0 正式版本发布!这标志着 MongoDB 数据库进入了一个全新的发展阶段,提供强大.灵活而且易于管理的数据库管理系统.MongoDB宣称,3.0新版本不只 ...

随机推荐

  1. JAVA统计一定范围内的质数个数

    public class TestNumber{ public static void main(String[] args){ System.out.println(roundPrimeCount( ...

  2. Oracle PL/SQL编程之过程

    1.简介 过程用于执行特定的操作,当建立过程时,既可以指定输入参数(in),也可以指定输出参数(out),通过在过程中使用输入参数,可以将数据传递到执行部分,通过使用输出参数,可以将执行部分的数据传递 ...

  3. Unity c#反射查找类中符合条件的方法并执行

    我用在了事件注册上面,再也不用一个一个去写了 下面直接上代码 using System; using System.Collections; using System.Collections.Gene ...

  4. PHP的parse_ini_file()函数,解释结构类型php.ini格式的文件

    1.直接读取,返回一维数组 如: "test.ini" 的内容: [names] me = Robert you = Peter [urls] first = "http ...

  5. 九度oj 1437 To Fill or Not to Fill 2012年浙江大学计算机及软件工程研究生机试真题

    题目1437:To Fill or Not to Fill 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1488 解决:345 题目描述: With highways availabl ...

  6. Mybatis Dao开发的两种方式(一)

     原始Dao的开发方式: 1.创建数据库配置文件db.properties jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localh ...

  7. [PY3]——找出一个序列中出现次数最多的元素/collections.Counter 类的用法

    问题 怎样找出一个序列中出现次数最多的元素呢? 解决方案 collections.Counter 类就是专门为这类问题而设计的, 它甚至有一个有用的 most_common() 方法直接给了你答案 c ...

  8. Unity3d编辑器扩展学习笔记

    编辑器扩展 1.添加菜单栏:把特性应用于静态方法 参数1:菜单名的空格后面是定义快捷键(单符号得用"_"开头,组合键%=Ctrl,#=Shift,&=Alt) 参数2:通过 ...

  9. MySql下载

    一般企业办的mysql下载不到 1.准备 注册一个orcle账号 2.跳转到http://www.mysql.com/ ,然后点击Downloads导航栏 滚动到最下面并点击[Community(GP ...

  10. ajax返回整个页面