今天爱分享给大家带来centos8 如何将tomcat设置服务运行【详细教程】,希望能够帮助到大家。
将tomcat作为服务运行
与其手动启动和停止Tomcat服务器,不如将其设置为作为服务运行
新建tomcat.service
sudo vi /etc/systemd/system/tomcat.service
内容如下
[Unit] Description=Tomcat9 After=network.target [Service] Type=forking User=tomcat Group=tomcat Environment="JAVA_HOME=/usr/lib/jvm/jre" Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom" Environment="CATALINA_BASE=/opt/tomcat/latest" Environment="CATALINA_HOME=/opt/tomcat/latest" Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid" Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC" ExecStart=/opt/tomcat/latest/bin/startup.sh ExecStop=/opt/tomcat/latest/bin/shutdown.sh [Install] WantedBy=multi-user.target
加载新服务
sudo systemctl daemon-reload
启动Tomcat
sudo systemctl enable --now tomcat
开启防火墙8080端口
查看开放的端口列表 sudo firewall-cmd --zone=public --list-ports 开启8080端口 sudo firewall-cmd --add-port=8080/tcp --permanent sudo firewall-cmd --reload