Centos7安装Tomct9设置服务

1.下载apache-tomcat-9.0.2.tar.gz安装文件

wget http://apache.mirror.rafal.ca/tomcat/tomcat-9/v9.0.2/bin/apache-tomcat-9.0.2.tar.gz

2.解压文件

tar -xzvf apache-tomcat-9.0.2.tar.gz

3.重命名为tomcat,并移到/usr/local/下

mv apache-tomcat-9.0.2 tomcat

mv tomcat /usr/local/

4.在/usr/lib/systemd/system下新增tomcat.service

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

内容如下所示:

[Unit]

Description=Apache Tomcat 9

After=syslog.target network.target remote-fs.target nss-lookup.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

5.重载一下服务单元

systemctl daemon-reload

6.在/usr/local/tomcat/bin目录下创建setenv.sh 配置,catalina.sh启动的时候会调用,同时配置java内存参数

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

添加内容如下:

#add java env

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.151-1.b12.el7_4.x86_64

export JRE_HOME=$JAVA_HOME/jre

#add tomcat pid

CATALINA_PID="$CATALINA_BASE/tomcat.pid"

#add java opts

JAVA_OPTS="-server -XX:PermSize=256M -XX:MaxPermSize=1024m -Xms512M -Xmx1024M -XX:MaxNewSize=256m"

7.授权

groupadd tomcat

useradd -g tomcat tomcat

chown -R tomcat:tomcat /usr/local/tomcat

8.管理tomcat服务

#配置开机启动

systemctl enable tomcat

#启动tomcat

systemctl start tomcat

#停止tomcat

systemctl stop tomcat

#重启tomcat

systemctl restart tomcat

#查看tomcat状态

systemctl status tomcat

#查看控制台

tail -f -n 200 /usr/local/tomcat/logs/catalina.out

9.开放端口

systemctl start firewalld

systemctl enable firewalld

firewall-cmd --permanent --zone=public --add-port=8080/tcp

firewall-cmd --reload

firewall-cmd --list-all

你可能感兴趣的:(Centos7安装Tomct9设置服务)