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

最新文章

  1. 《JavaScript 代码优化指南》
  2. [转]Visual Studio技巧之打造拥有自己标识的代码模板
  3. python 读写、创建 文件
  4. 一步一步理解Paxos算法
  5. JavaScript之数组循环 forEach 循环输出数组元素
  6. Android Lock Screen Orientation
  7. Web技术导论复习大纲
  8. 关于sql server 代理(已禁用代理xp)
  9. CDbConnection failed to open the DB connection: SQLSTATE[28000] [1045] Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: YES)
  10. 芝麻HTTP:Python爬虫实战之抓取爱问知识人问题并保存至数据库
  11. 将本地代码备份到Github public repository
  12. 使用aliyun cli工具快速创建云主机
  13. Specified key was too long; max key length is 767 bytes解决方案
  14. jdk8 分隔字符串最新方法
  15. java的回调
  16. bzoj3237 cdq分治+可撤销并查集
  17. HTML编码规则
  18. Web Storage与Cookie相比存在的优势:
  19. warning:ISO C90 forbids mixed declarations and code
  20. 【LOJ】#2062. 「HAOI2016」地图

热门文章

  1. java第五天
  2. Python3.x:基础学习
  3. LINUX实践--程序破解
  4. Java第一周学习总结5311
  5. Ubuntu16.04下安装tensorflow(GPU加速)【转】
  6. 解决Tomcat端口被占用 及 启用失败等其它错误整理册
  7. [place recognition]NetVLAD: CNN architecture for weakly supervised place recognition 论文翻译及解析(转)
  8. Java语言的垃圾回收机制
  9. 使用git bush 生成github SSH公钥
  10. css括号风格