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. 怎样在linux下对U盘进行格式化和分区

    说明,为了不做无用功,首先必须卸载要分区的设备,分区才能执行成功.通过命令umount /media/?? 或者umount /mnt/??? 看你的实际情况,这一步必不可少.1.首先通过命令fdis ...

  2. TED #01#

    Laura Vanderkam: How to gain control of your free time 1.我们总是不缺乏时间去做重要的事情,即便我们再忙; “我没时间” 的同义词是“我不想做” ...

  3. 2017-2018-1 JaWorld 团队作业--冲刺6

    2017-2018-1 JaWorld 团队作业--冲刺6(20162308) 实现 由于我在冲刺部分负责的是类之间的耦合,所以我就介绍一下本次游戏的总体实现. 我们定义了Sprite类,即精灵类,游 ...

  4. 课堂练习——Hash 20162305

    课堂练习--Hash 20162305 课堂练习要求 利用除留余数法为下列关键字集合的存储设计hash函数,并画出分别用开放寻址法和拉链法解决冲突得到的空间存储状态(散列因子取0.75) 关键字集合: ...

  5. 关于Cooperation.GTST

    Cooperation.GTST团队项目简介 我们打算利用Android Studio开发一款博客园的Android APP,初步设想能够实现在Android手机平台使用博客园的相关功能,后续想法会在 ...

  6. 转 已知两点坐标和半径求圆心坐标程序C++

      数学思想:利用圆方程和直线方程 已知两点坐标和半径求圆心坐标程序 #include <iostream> #include <fstream> #include <c ...

  7. maven3官网下载地址

    maven3官网下载地址:https://archive.apache.org/dist/maven/maven-3/

  8. UOJ #185【ZJOI2016】 小星星

    题目链接:小星星 首先有个暴力很好想.令\(f_{i,j,S}\)表示把\(i\)这棵子树对应到原图中的\(S\)集合,\(i\)号点对应到了\(j\)号点的方案数.这玩意儿复杂度是\(O(3^nn^ ...

  9. tenserflow models包的安装

    1.下载 models包 https://github.com/tensorflow/models 2.将models包拷贝到本机Python包的安装地址即可,本机Python包的安装地址的查看方式可 ...

  10. UVA-1614 Hell on the Markets(贪心+推理) (有待补充)

    题目大意:一个整数序列a,1≤a[i]≤i.问能否通过在一些元素前加上负号,使得整个序列和为0. 题目分析:贪心.贪心策略:每次都先选最大的元素加负号(或保留,不加负号). 贪心依据:对于1≤a[i] ...