1,centos7 使用 systemctl 替换了 service命令

参考:redhat文档:
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Services.html#sect-Managing_Services_with_systemd-Services-List

查看全部服务命令:
systemctl list-unit-files --type service
查看服务
systemctl status name.service
启动服务
systemctl start name.service
停止服务
systemctl stop name.service
重启服务
systemctl restart name.service增加开机启动
systemctl enable name.service
删除开机启动
systemctl disable name.service
其中.service 可以省略。

添加环境变量:

## JAVA
export JAVA_HOME=/usr/local/java/jdk
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ## TOMCAT
export CATALINA_HOME=/usr/local/tomcat ## PATH
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:$JAVA_HOME/bin:$CATALINA_HOME/bin

catalina.sh加载环境变量

head ./bin/catalina.sh

#!/bin/sh

. /etc/profile

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0

2,tomcat增加启动参数

 把apache-tomcat 解压为 /usr/local/tomcat

tomcat 需要增加一个pid文件

在tomca/bin 目录下面,增加 setenv.sh 配置,添加可执行权限,catalina.sh启动的时候会调用,同时配置java内存参数,注意这里的pid文件路径要与systemctl脚本里的pid文件一致

#add tomcat pid
CATALINA_PID="$CATALINA_HOME/tomcat.pid" #add java opts
JAVA_OPTS="-server -XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M -XX:MaxNewSize=256m"

3,增加tomcat.service

在/usr/lib/systemd/system目录下增加tomcat.service,目录必须是绝对目录。

cat /usr/lib/systemd/system/tomcat.service


[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target


[Service]
Type=forking
PIDFile=/usr/local/tomcat/tomcat.pid
ExecStart=/usr/local/tomcat/bin/catalina.sh start
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true


[Install]
WantedBy=multi-user.target

 

[unit]配置了服务的描述,规定了在network启动之后执行。[service]配置服务的pid,服务的启动,停止,重启。[install]配置了使用用户。

4,使用tomcat.service

配置开机启动

systemctl enable tomcat

启动tomcat
systemctl start tomcat
停止tomcat
systemctl stop tomcat
重启tomcat
systemctl restart tomcat

因为配置pid,在启动的时候会再tomcat根目录生成tomcat.pid文件,停止之后删除。

同时tomcat在启动时候,执行start不会启动两个tomcat,保证始终只有一个tomcat服务在运行。

多个tomcat可以配置在多个目录下,互不影响

# Systemd unit file for default tomcat
#
# To create clones of this service:
# DO NOTHING, use tomcat@.service instead. [Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target [Service]
Type=simple
EnvironmentFile=/etc/tomcat/tomcat.conf
Environment="NAME="
EnvironmentFile=-/etc/sysconfig/tomcat
ExecStart=/usr/libexec/tomcat/server start
SuccessExitStatus=
User=tomcat
Group=tomcat [Install]
WantedBy=multi-user.target
grep -v "^#" /etc/tomcat/tomcat.conf

TOMCAT_CFG_LOADED="" TOMCATS_BASE="/var/lib/tomcats/" JAVA_HOME="/usr/lib/jvm/jre" CATALINA_HOME="/usr/share/tomcat" CATALINA_TMPDIR="/var/cache/tomcat/temp" SECURITY_MANAGER="false"
cat /etc/sysconfig/tomcat
# Service-specific configuration file for tomcat. This will be sourced by
# the SysV init script after the global configuration file
# /etc/tomcat/tomcat.conf, thus allowing values to be overridden in
# a per-service manner.
#
# NEVER change the init script itself. To change values for all services make
# your changes in /etc/tomcat/tomcat.conf
#
# To change values for a specific service make your edits here.
# To create a new service create a link from /etc/init.d/<your new service> to
# /etc/init.d/tomcat (do not copy the init script) and make a copy of the
# /etc/sysconfig/tomcat file to /etc/sysconfig/<your new service> and change
# the property values so the two services won't conflict. Register the new
# service in the system as usual (see chkconfig and similars).
# # Where your java installation lives
#JAVA_HOME="/usr/lib/jvm/java" # Where your tomcat installation lives
#CATALINA_BASE="/usr/share/tomcat"
#CATALINA_HOME="/usr/share/tomcat"
#JASPER_HOME="/usr/share/tomcat"
#CATALINA_TMPDIR="/var/cache/tomcat/temp" # You can pass some parameters to java here if you wish to
#JAVA_OPTS="-Xminf0.1 -Xmaxf0.3" # Use JAVA_OPTS to set java.library.path for libtcnative.so
#JAVA_OPTS="-Djava.library.path=/usr/lib64" # What user should run tomcat
#TOMCAT_USER="tomcat" # You can change your tomcat locale here
#LANG="en_US" # Run tomcat under the Java Security Manager
#SECURITY_MANAGER="false" # Time to wait in seconds, before killing process
#SHUTDOWN_WAIT="" # Whether to annoy the user with "attempting to shut down" messages or not
#SHUTDOWN_VERBOSE="false" # Connector port is for this tomcat instance
#CONNECTOR_PORT="" # If you wish to further customize your tomcat environment,
# put your own definitions here
# (i.e. LD_LIBRARY_PATH for some jdbc drivers)
cat /usr/libexec/tomcat/server
#!/bin/bash . /usr/libexec/tomcat/preamble MAIN_CLASS=org.apache.catalina.startup.Bootstrap FLAGS="$JAVA_OPTS"
OPTIONS="-Dcatalina.base=$CATALINA_BASE \
-Dcatalina.home=$CATALINA_HOME \
-Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS \
-Djava.io.tmpdir=$CATALINA_TMPDIR \
-Djava.util.logging.config.file=${LOGGING_PROPERTIES} \
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" if [ "$1" = "start" ] ; then
FLAGS="${FLAGS} $CATALINA_OPTS"
if [ "${SECURITY_MANAGER}" = "true" ] ; then
OPTIONS="${OPTIONS} \
-Djava.security.manager \
-Djava.security.policy==${CATALINA_BASE}/conf/catalina.policy"
fi
run start
elif [ "$1" = "stop" ] ; then
run stop
fi

CentOS7 tomcat systemctl脚本的更多相关文章

  1. Centos7 自定义systemctl服务脚本

    序言篇: 之前工作环境一直使用Centos6版本,脚本一直在使用/etc/init.d/xxx:系统升级到Cento7后,虽然之前的启动脚本也可以使用,但一直没有使用systemctl 的自定义脚本. ...

  2. Linux学习笔记之Centos7 自定义systemctl服务脚本

    0x00 概述 之前工作环境一直使用Centos6版本,脚本一直在使用/etc/init.d/xxx:系统升级到Cento7后,虽然之前的启动脚本也可以使用,但一直没有使用systemctl 的自定义 ...

  3. [转]CentOS7利用systemctl添加自定义系统服务

    原文:https://www.cnblogs.com/saneri/p/7778756.html CentOS7自定义系统服务 CentOS7的服务systemctl脚本存放在:/usr/lib/sy ...

  4. CentOS7利用systemctl添加自定义系统服务【转】

    systemctl enable name.service 设置开机启 systemctl disable name.service 删除开机启动指令 systemctl list-units --t ...

  5. tomcat监控脚本(监控进程,测试接口,告警动作为发送邮件)

    服务器环境:centos7.2 64位 tomcat8.5.6 tomcat 监控功能共需要两个脚本,如下: initMonitor.sh #!/bin/sh #初始化监控脚本相关变量 export ...

  6. CentOS7 使用systemctl来管理服务

    1.建立service文件 以tomcat为例 , 建立tomcat.service文件 #服务说明 [Unit] #服务描述 Description=Tomcat Service #前置需要启动的服 ...

  7. CentOS7使用systemctl添加自定义服务

    一.简介 Centos7开机第一个程序从init完全换成了systemd这种启动方式,同centos 5 6已经是实质差别.systemd是靠管理unit的方式来控制开机服务,开机级别等功能. 在/u ...

  8. 基于CentOS7系统添加自定义脚本服务及参数说明【转】

    概述 centos6如果要添加自定义脚本服务只需要把脚本放到/etc/init.d然后授权后用chkconfig添加后就可以管理了,那么centos7又是怎么添加自定义脚本服务呢? CentOS7添加 ...

  9. centos7初始化bashshell脚本

    centos7初始化bashshell脚本 #!/bin/bash if [[ "$(whoami)" != "root" ]]; then echo &quo ...

随机推荐

  1. PHP多进程学习(二)__fork起多个子进程,父进程的阻塞与非阻塞

    先简单来了解一下多进程 [来初步了解一下PHP多进程及简单demo] php的多进程是不是可以无限制的fork子进程?fork调用的一个奇妙之处就是它仅仅被调用一次,却能够返回两次,它可能有三种不同的 ...

  2. 20145219《网络对抗》PC平台逆向破解

    20145219<网络对抗>PC平台逆向破解 shellcode注入 1.shellcode shellcode是一段代码,溢出后,执行这段代码能开启系统shell. 2.构造方法 (1) ...

  3. JQuery实现锚点平滑滚动

    一般使用锚点来跳转到页面指定位置的时候,会生硬地立即跳转到指定位置,但是有些时候我们想要平滑地过渡到指定的位置,那么可以使用JQuery简单的实现这个效果: 比如,这里我们将通过点击<a> ...

  4. zabbix3.2源码升级至3.4

    安装见:https://www.cnblogs.com/LuckWJL/p/9037007.html 一.下载3.4版本安装包 二.停ZabbixServer [root@wcy ~]# /etc/i ...

  5. SpringBoot与Dubbo整合上篇

    最近学习了一下dubbo,是阿里巴巴公司的一个开源服务框架.目前我们公司实现两个不同系统的之间通信,是采用了Oracle的OSB作为服务的管理(即企业服务总线的一种实现),服务提供方在OSB上注册业务 ...

  6. Codeforces Round #417 (Div. 2) D. Sagheer and Kindergarten(树中判祖先)

    http://codeforces.com/contest/812/problem/D 题意: 现在有n个孩子,m个玩具,每次输入x y,表示x孩子想要y玩具,如果y玩具没人玩,那么x就可以去玩,如果 ...

  7. Qt5获取网卡/IP等信息

    参考网址:http://blog.csdn.net/wjs1033/article/details/22697063 1.环境 Win7x64.Qt5.5.1(x86).vs2013_ultimate ...

  8. 《WAP》第一次作业:团队亮相

    一.队名:WAP! 二.团队成员组长 组员 : 201571030302/杜有海 201571030327/乌勒扎 201571030304/郝明宇 201571030318/马麒 组长: 20157 ...

  9. Spring IOC 源码简单分析 01 - BeanFactory

    ### 准备 ## 目标 了解 Spring IOC 的基础流程 ## 相关资源 Offical Doc:http://docs.spring.io/spring/docs/4.3.9.RELEASE ...

  10. Numpy np.array 相关常用操作

    https://www.cnblogs.com/oftenlin/p/7856389.html