1.下载tomcat
wget https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.21/bin/apache-tomcat-9.0.21.tar.gz
解压
tar zxvf apcahe-tomcat-9.0.21.tar.gz
mv apache-tomcat-9.0.21 /usr/local/tomcat
启动
/usr/local/tomcat/bin/startup.sh
2.设置开机自启动
新建tomcat.service文档
vim /etc/systemd/system/tomcat.service
加入以下内容
[Unit]
Description=tomcat
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/tomcat/bin/startup.sh
ExecStop=/usr/local/tomcat/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
执行以下命令使刚刚编写的service生效
systemctl daemon-reload
# 设定开机启动
systemctl enable tomcat
# 启动服务
systemctl start tomcat
# 停止服务
systemctl stop tomcat
# 重启服务
systemctl restart tomcat
# 取消开机启动
systemctl disable tomcat
# 查看服务状态
systemctl status tomcat