如何允许Tomcat War App写入文件夹 [英] How to allow Tomcat war app to write in folder

查看:232
本文介绍了如何允许Tomcat War App写入文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望部署为战争ROOT.war的Web应用程序具有对/var/www/html/static/images的写权限,以便它可以将上载和转换后的图像写入该文件夹,以便nginx可以静态地为其提供服务.当前,它不起作用,同时触发java.nio.file.FileSystemException异常和Filesystem is read-only消息.

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 an triggers an java.nio.file.FileSystemException exception together with the Filesystem is read-only message.

但是文件系统不是只读的,并且状态良好.该文件夹已被更改为777.

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

其他信息: Tomcat安装程序在具有托管磁盘的Ubuntu 18.04 Azure VM上运行.该文件夹位于Ext4格式化的驱动器上

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

推荐答案

让我们开始:chmod 777非常适合测试,但是绝对不适合实际应用,您不应该习惯这种设置.在授予世界写权限之前,应正确设置所有者/组.

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.

Tomcat邮件列表上也出现了类似的问题,Emmanuel Bourg指出 Debian Tomcat被systemd沙箱化.阅读您的/usr/share/doc/tomcat9/README. Debian 其中包含以下段落:

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被systemd沙盒化,并且仅具有对 以下目录:

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

  • /var/lib/tomcat9/conf/Catalina(实际上是/etc/tomcat9/Catalina)
  • /var/lib/tomcat9/logs(实际上是/var/log/tomcat9)
  • /var/lib/tomcat9/webapps
  • /var/lib/tomcat9/work(实际上是/var/cache/tomcat9)

  • /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)

如果需要对其他目录的写访问权,请进行服务设置 必须被覆盖.这是通过创建override.conf文件来完成的 在/etc/systemd/system/tomcat9.service.d/中,包含:

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

编辑结束,继续解决无法解决OP问题的段落,但应保留在以下位置:

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

如果-经过测试的所有内容-Tomcat 应该对该目录具有写访问权,但没有该目录,则错误消息向我提出了一个假设:是否可能是

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是否以root用户身份运行?
  • 目录是通过NFS挂载的吗?

NFS的默认配置是root在该外部文件系统上没有任何权限(或者是否没有写权限?这是古老的历史记忆-查找"NFS root squash"以获取完整的故事)

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)

如果这符合您所运行的条件,则应停止以root用户身份运行Tomcat ,而应以非特权用户身份运行它.然后,您可以将有关目录的权限设置为可由您的tomcat用户写入,并由nginx读取,然后就可以完成.

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.

以root身份运行Tomcat会带来灾难:您不希望Internet上可用的进程以root身份运行.

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.

这篇关于如何允许Tomcat War App写入文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆