You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 20.04系统下如何设置Tomcat 9以指定用户运行?

Ubuntu 20.04 官方源安装的 Tomcat 9 默认采用 systemd 进行服务管理,原 Tomcat 7 中从 /etc/default/tomcat7 读取运行用户的逻辑已经废弃,因此你添加的环境变量不会生效,运行用户直接定义在 systemd 服务单元配置中。

配置步骤如下:

  1. 先停止当前运行的 Tomcat 9 服务
sudo systemctl stop tomcat9
  1. 编辑 Tomcat 9 的 systemd 覆盖配置(该方式可避免后续 apt 升级 Tomcat 包时覆盖自定义配置)
sudo systemctl edit tomcat9

在弹出的编辑器中输入以下内容,将 your_custom_user、your_custom_group 替换为你实际要使用的用户和用户组:

[Service]
User=your_custom_user
Group=your_custom_group

输入完成后保存退出编辑器。

  1. 递归修改 Tomcat 9 相关目录的权限,避免启动时出现权限报错
sudo chown -R your_custom_user:your_custom_group /var/lib/tomcat9 /etc/tomcat9 /var/log/tomcat9 /var/cache/tomcat9
  1. 重载 systemd 配置使修改生效
sudo systemctl daemon-reload
  1. 启动 Tomcat 9 服务
sudo systemctl start tomcat9

配置完成后可执行 ps aux | grep tomcat9 查看进程所有者,确认是否已切换为你指定的用户。


内容的提问来源于stack exchange,提问作者Borea Deitz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.20 14:45:04