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. QML事件处理 八

    1.MouseArea MouseArea 是一个不可见的项目,通常用来和一个可见的项目配合使用来为其提供鼠标处理.鼠标处理的逻辑可以包含在一个MouseArea项目中. MouseArea的enab ...

  2. OpenCV图像增强算法实现(直方图均衡化、拉普拉斯、Log、Gamma)

    http://blog.csdn.net/dcrmg/article/details/53677739 1. 基于直方图均衡化的图像增强   直方图均衡化是通过调整图像的灰阶分布,使得在0~255灰阶 ...

  3. Win10下安装Go开发环境

    关于Go语言有多么值得学习,这里就不做介绍了,既然看了这篇文章,想必是对有学习意向. 这里是在Windows下安装Go环境,去中文社区的下载栏目,https://studygolang.com/dl ...

  4. 20162314 《Program Design & Data Structures》Learning Summary Of The Tenth Week

    20162314 2017-2018-1 <Program Design & Data Structures>Learning Summary Of The Tenth Week ...

  5. [微信开发] - weixin4j获取网页授权后的code进而获取用户信息

    weixin4j封装好的SnsComponent组件中的方法可以执行该步骤 WeixinUserInfoController : package com.baigehuidi.demo.control ...

  6. 简单实现Ubuntu16.04 + caffe2 + CUDA9.0 + cuDNN8.0

    在Ubuntu16.04 CUDA9.0 cuDNN8.0的环境下安装caffe2 本博客比较简单,cuda9.0 cudnn8.0部分请看上一篇博客,其中详细讲了: 如何安装驱动 安装cuda 安装 ...

  7. mysql Alter 的问题

    转自:https://blog.csdn.net/c_enhui/article/details/50903351 -- 设置或删除列的默认值.该操作会直接修改.frm文件而不涉及表数据. 此操作很快 ...

  8. BZOJ 2342: 【SHOI2011】 双倍回文

    题目链接:双倍回文 回文自动机第二题.构出回文自动机,那么一个回文串是一个“双倍回文”,当且仅当代表这个串的节点\(u\)顺着\(fail\)指针往上跳,可以找到一个节点\(x\)满足\(2len_x ...

  9. POJ 1321 棋盘问题 dfs 难度:0

    http://poj.org/problem?id=1321 注意是在'#'的地方放棋子 矩阵大小不过8*8,即使是8!的时间复杂度也足以承受,可以直接dfs求解 dfs时标注当前点的行和列已被访问, ...

  10. WCF技术

      在WCF数据访问中使用缓存提高Winform字段中文显示速度 伍华聪 2014-09-06 12:50 阅读:2507 评论:1     WCF开发框架之插件化应用模式升级 伍华聪 2013-07 ...