使用systemctl管理tomcat9——以普通用户运行tomcat9——设置tomcat9开机自启

注: apache-tomcat-9.0.24的commons-daemon-native.tar.gz压缩包中缺少configure文件,可以从 apache-tomcat-9.0.24中获取commons-daemon-native.tar.gz压缩包并使用

1.编译jsvc文件

cd /usr/local/apache-tomcat-9.0.24/bin/
tar zxvf commons-daemon-native.tar.gz
cd commons-daemon-1.1.0-native-src/unix/
./configure
make
cp jsvc /usr/local/apache-tomcat-9.0.24/bin/

2.创建Tomcat用户并修改文件夹权限

useradd -M -s /sbin/nologin tomcat
            //-M是不创建家目录   -s是指定账户的shell
chown -R tomcat /usr/local/apache-tomcat-9.0.24/
            //-R是递归修改该文件夹及文件夹下的所有文件夹及文件的权限

3.配置用systemd启动方式的脚本

vim /usr/lib/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking
EnvironmentFile=/usr/local/apache-tomcat-9.0.24/conf/tomcat.conf
ExecStart=/usr/local/apache-tomcat-9.0.24/bin/daemon.sh start
ExecStop=/usr/local/apache-tomcat-9.0.24/bin/daemon.sh stop
SuccessExitStatus=143
User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target

4.创建参数配置文件

vim /usr/local/apache-tomcat-9.0.24/conf/tomcat.conf
JAVA_HOME="/usr/local/java/jdk1.8.0_221"
CATALINA_BASE="/usr/local/apache-tomcat-9.0.24"
CATALINA_HOME="/usr/local/apache-tomcat-9.0.24"
TOMCAT_USER="tomcat"
#JAVA_OPTS="-Xminf0.1 -Xmaxf0.3" > 调优使用

5.使用systemctl测试管理tomcat

systemctl start tomcat          
                //开启tomcat
systemctl stop tomcat
                //关闭tomcat
systemctl restart tomcat
               //重启tomcat

6.设置tomcat9开机自启

systemctl enable tomcat

发表评论

电子邮件地址不会被公开。 必填项已用*标注