如何允许Tomcat War应用程序在文件夹中写入

发布于 2025-02-09 15:18:21 字数 385 浏览 3 评论 0原文

我想为我的web应用程序部署为战争root.war以写入/var/var/www/html/static/static/images,以便它可以写入上载并将其转换为该文件夹,因此Nginx可以静态地使用。当前,它不起作用,并且触发java.nio.file.filesystemexception异常以及filesystem均已读取消息。

但是文件系统不是只读的,并且状况良好。该文件夹已经是chmod ded 777

额外信息: Tomcat设置正在使用带有托管磁盘的Ubuntu 18.04 Azure VM运行。该文件夹位于Ext4格式驱动器上

I'd like for my webapp which is deployed as a war ROOT.war to have write access to /var/www/html/static/images so that it can write uploaded and converted images to that folder so nginx can serve it statically. Currently it doesn't work and triggers a java.nio.file.FileSystemException exception together with the Filesystem is read-only message.

But the filesystem is not read-only and is in great condition. The folder has already been chmodded 777.

Extra info:
The tomcat setup is running on an Ubuntu 18.04 Azure VM with managed disk. The folder is residing on an Ext4 formatted drive

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

聊慰 2025-02-16 15:18:21

让我们从:CHMOD 777非常适合测试,但绝对不适合现实世界,您不应该习惯这种设置。宁愿在授予世界写入权限之前正确设置所有者/组。

编辑:一个类似的问题刚刚出现在Tomcat邮件列表上,Emmanuel Bourg指出 Debian Tomcat是由Systemd 打磨的。阅读您的/usr/usr/usr/share/doc/doc/doc/tomcat9/readme。 Debian 包含此段落:

tomcat由SystemD打磨,只有写入访问权限
以下目录:

  • /var/lib/tomcat9/conf/catalina(实际上/etc/tomcat9/catalina
  • /var/lib/tomcat9/logs(实际上/var/var/log/tomcat9
  • /var/lib/tomcat9/webApps
  • /var/lib/tomcat9/work(实际上/var/cache/tomcat9

如果需要对其他目录的写入访问权限
必须被覆盖。这是通过创建Override.conf文件来完成的
/etc/systemd/system/tomcat9.service.d/中包含:

[服务]

readwritePath =/path/to/to/directory/

随后必须重新启动该服务:

  systemctl守护程序 - 重加载
  SystemCtl重新启动tomcat9
 

Edit 2022:请注意,这些是2019年路径 - 验证以后版本的文件位置。从评论到这个答案(谢谢 v h and ng sek long)这里有一些更新:

在当前的Ubuntu文件中:sudo vi /etc/systemd/system/multi-user.target.wants/tomcat9.service –&nbsp; vh Feb 26,2022年2月26日,19:55 < /p>

Mine(Ubuntu 20)已安装在此处/lib/systemd/system/tomcat9.service SMH每个人都使用不同的路径。 - &nbsp; ng sek long 2022年3月28日,8:36

编辑结束,继续段落无法解决OP的问题,但应该留在:

如果 - 所有事物都经过测试-Tomcat 应该是否有对该目录的写入访问权限,但没有它,错误消息将我指向一个假设:

  • tomcat可以作为root运行吗?
  • 该目录通过NFS安装?

是没有写入的?

NFS的默认配置是根部在该外部文件系统上没有任何权限(或者 匹配您正在运行的内容,您应该停止以root 的态度运行tomcat,而宁愿将其作为无私人用户运行。然后,您可以将有关目录上的权限设置为可以由tomcat-user编写的权限,并且可以由Nginx读取,并且完成了。

作为root运行tomcat是灾难的秘诀:您不希望从Internet可用的过程作为root运行。

如果这些条件不符合您的配置:对配置进行详细说明。我仍然为其他可能在以后找到这个问题/答案的人坚持此描述。

Let's start with: chmod 777 is great for testing, but absolutely unfit for the real world and you shouldn't get used to this setting. Rather set the owner/group correctly, before you give world write permissions.

Edit: A similar question just came up on the Tomcat mailing list, and Emmanuel Bourg pointed out that Debian Tomcat is sandboxed by systemd. Read your /usr/share/doc/tomcat9/README.Debian which contains this paragraph:

Tomcat is sandboxed by systemd and only has write access to the
following directories:

  • /var/lib/tomcat9/conf/Catalina (actually /etc/tomcat9/Catalina)
  • /var/lib/tomcat9/logs (actually /var/log/tomcat9)
  • /var/lib/tomcat9/webapps
  • /var/lib/tomcat9/work (actually /var/cache/tomcat9)

If write access to other directories is required the service settings
have to be overridden. This is done by creating an override.conf file
in /etc/systemd/system/tomcat9.service.d/ containing:

[Service]

ReadWritePaths=/path/to/the/directory/

The service has to be restarted afterward with:

  systemctl daemon-reload
  systemctl restart tomcat9

Edit 2022: Note that these are the 2019 paths - validate the file locations for later versions. From the comments to this answer (thank you to V H and Ng Sek Long) here are some updates:

In current Ubuntu file is here: sudo vi /etc/systemd/system/multi-user.target.wants/tomcat9.service – V H Feb 26, 2022 at 19:55

Mine (Ubuntu 20) is installed here /lib/systemd/system/tomcat9.service smh everybody use a different path. – Ng Sek Long Mar 28, 2022 at 8:36

End of edit, continuing with the passage that didn't solve OP's problem, but should stay in:

If - all things tested - Tomcat should have write access to that directory, but doesn't have it, the error message points me to an assumption: Could it be that

  • Tomcat is running as root?
  • The directory is mounted through NFS?

The default configuration for NFS is that root has no permissions whatsoever on that external filesystem (or was it no write-permission? this is ancient historical memory - look up "NFS root squash" to get the full story)

If this is a condition that matches what you are running, you should stop running Tomcat as root, and rather run it as an unprivileged user. Then you can set the permissions on the directory in question to be writeable by your tomcat-user, and readable by nginx, and you're done.

Running Tomcat as root is a recipe for disaster: You don't want a process that's available from the internet to run as root.

If these conditions don't meet your configuration: Elaborate on the configuration. I'd still stand by this description for others who might find this question/answer later.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文