CentOS8上设置tomcat9开机自动启动
## 防火墙开放端口
```bash
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
```
## 添加tomcat服务
```bash
vi /usr/lib/systemd/system/tomcat.service
```
内容如下:
```
[Unit]
Description=Tomcat-9.0.50
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=oneshot
ExecStart=/xxx/apache-tomcat-9.0.50/bin/startup.sh
ExecStop=/xxx/apache-tomcat-9.0.50/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
```
开机自动启动
```bash
#重新载入修改后配置文件,让设置生效
systemctl daemon-reload
#启动服务
systemctl start tomcat.service
#设置为开机自启动
systemctl enable tomcat.service
#查看服务运行状态
systemctl status tomcat.service
```