温馨提示×

Tomcat在Debian如何停止

小樊
33
2026-08-05 08:33:44
栏目: 智能运维

在 Debian 系统上停止 Apache Tomcat 有多种方式,取决于你是如何安装和配置 Tomcat 的。下面按常见情况分别说明。


一、使用 systemctl(最常见,推荐)

如果 Tomcat 是通过 systemd 管理的(例如使用官方包或手动配置为服务):

sudo systemctl stop tomcat

注意:tomcat 可能是 tomcat9tomcat10 等,具体取决于版本,例如:

sudo systemctl stop tomcat9

查看服务名:

systemctl list-units --type=service | grep tomcat

二、使用 Tomcat 自带脚本(手动安装常见)

如果你是从 Apache 官网下载解压安装的 Tomcat:

cd /opt/tomcat/bin
./shutdown.sh

或指定完整路径:

/opt/tomcat/bin/shutdown.sh

前提:CATALINA_HOMEJAVA_HOME 已正确配置。


三、强制停止(kill 进程)

如果 shutdown.sh 无效或 Tomcat 卡死:

1. 查找进程

ps -ef | grep tomcat

或:

pgrep -f tomcat

2. 正常终止

kill PID

3. 强制终止

kill -9 PID

⚠️ 不推荐优先使用 -9,可能导致数据或会话丢失。


四、验证是否已停止

systemctl status tomcat

或:

ps -ef | grep tomcat

也可以访问:

http://localhost:8080

如果无法访问,说明已停止。


五、如果是通过 apt 安装的 Tomcat

Debian 常见包名:

  • tomcat9
  • tomcat10

停止方式:

sudo systemctl stop tomcat9

禁用开机启动(可选):

sudo systemctl disable tomcat9

总结

场景 停止方式
Debian 包安装 systemctl stop tomcat9
手动解压安装 bin/shutdown.sh
服务无响应 kill PID
查看状态 systemctl status tomcat

如果你愿意,可以告诉我:

  • Tomcat 版本
  • 安装方式(apt / 手动)
  • 是否正确配置为 systemd 服务

我可以给你更精确的命令。

0