centos7下部署tomcat-systemctl启动

1.jdk部署和tomcat部署

yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
ls /usr/lib/jvm/
java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64

vi /etc/profile.d/jdk8.sh #配置java家环境tomcat使用

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.212.b04-0.el7_6.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile.d/jdk8.sh
java -version

wget https://mirrors.cnnic.cn/apache/tomcat/tomcat-8/v8.5.41/bin/apache-tomcat-8.5.41.tar.gz

tar xvf apache-tomcat-8.5.41.tar.gz -C /usr/local/src/ #几项根据版本号修改命令
cd /usr/local/src/apache-tomcat-8.5.41/
cd .. ; mv apache-tomcat-8.5.41/ /usr/local/tomcat ; cd

2.启动脚本准备

getent group tomcat || groupadd -r tomcat
getent passwd tomcat || useradd -r -d /opt -s /bin/nologin -g tomcat tomcat
chown -R tomcat:tomcat /usr/local/tomcat

vi /usr/local/tomcat/bin/setenv.sh

CATALINA_PID="$CATALINA_BASE/tomcat.pid"
JAVA_OPTS="-server -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=1024m -Xms512M -Xmx1024M -XX:MaxNewSize=256m"

chmod a+x /usr/local/tomcat/bin/setenv.sh

 

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

[Unit]
Description=Apache Tomcat 8
After=syslog.target network.target

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

[Install]
WantedBy=multi-user.target


systemctl enable tomcat

systemctl restart tomcat
systemctl start tomcat
systemctl stop tomcat

ps -ef | grep tomcat

top #看到tomcat是在tomcat用户下运行 的

 

参考
https://www.cnblogs.com/ieinstein/p/7096650.html

 

posted @ 2019-05-18 16:02  夜辰雪扬  阅读(666)  评论(0编辑  收藏  举报