Debian部署Tomcat 注册服务并设置开机启动
在Debian系统上部署Tomcat并将其注册为服务,并设置为开机启动的步骤如下:
- 安装Tomcat:
sudo apt update
sudo apt install tomcat9 tomcat9-admin
- 创建Tomcat服务文件:
sudo nano /etc/systemd/system/tomcat.service
- 在打开的文件中添加以下内容:
[Unit]
Description=Tomcat 9 servlet container
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/default-java
Environment=CATALINA_PID=/opt/tomcat9/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat9
Environment=CATALINA_BASE=/opt/tomcat9
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
ExecStart=/opt/tomcat9/bin/startup.sh
ExecStop=/opt/tomcat9/bin/shutdown.sh
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
- 重载systemd以识别新的服务文件,启用并启动Tomcat服务:
sudo systemctl daemon-reload
sudo systemctl enable tomcat.service
sudo systemctl start tomcat.service
- 设置Tomcat自动开机启动:
sudo systemctl enable tomcat.service
完成上述步骤后,Tomcat将作为服务安装并设置为开机自启动。
评论已关闭