AWS EC2 Linux实例 – 适合存储由Web服务器频繁更新和读取的文件的文件夹位置

huangapple go评论72阅读模式
英文:

AWS EC2 Linux Instance - Suitable folder location to store a file which is frequently updated and read by the web server

问题

我使用AWS EC2 Linux实例,在该实例上部署了我的Tomcat基于Java的Web服务器。

我的服务器需要频繁地读写一组“文本文件”。而且这些文件在部署新的WAR文件时不应该被覆盖。(也就是说,即使部署新的WAR文件后,现有的文本文件应该保持不变)

请为EC2实例建议适当的文件位置,以便Web服务器可以频繁访问,同时无论是否重新启动或部署新版本的WAR文件,文件夹数据都保持不变。

AWS EC2 Linux实例 – 适合存储由Web服务器频繁更新和读取的文件的文件夹位置

英文:

I use AWS EC2 Linux instance, where my tomcat Java based web server is deployed.

My server need to frequently read and write a group of "text files". And these files shouldn't be over written each time I deploy a new version of WAR file. ( Means , even after new war file deployed, the existing text files should be kept as it is )

Please suggest the suitable file location in EC instance, from where the web server can frequently access at the same time, the folder data is untouched with restart or with the deployment of new version of war.

AWS EC2 Linux实例 – 适合存储由Web服务器频繁更新和读取的文件的文件夹位置

答案1

得分: 1

假设有一个不同的用户在运行Tomcat(即一个名为 tomcat 的用户),我会将文件放在那个用户的主目录中。只需要像这样访问文件:

File file = new File(System.getProperty("user.home") + "/somedir/file.txt");

该目录应该已经存在,并且归属于与Tomcat运行的相同用户。

一个注意事项是,根据您的EC2文件系统,如果发生机器崩溃,重新创建您的环境可能会更加困难。您需要确保存储文件的目录以某种方式进行了备份。存储在EFS上会有所帮助,但可能还不够。从长远来看,您可能需要考虑使用某种类型的数据库。

英文:

Assuming that there is a different user running Tomcat (i.e. a tomcat user) I would put the files in that users home directory. It should be as easy as accessing the files with something like:

File file = new File( System.getProperty("user.home") + "/somedir/file.txt" );

The directory should already exist and be owned by the same user as Tomcat is running as.

One caveat is that, depending on your EC2 file system, it may be harder to recreate your environment in the event of a machine crash. You'll need to make sure that the directory in which you store your files is somehow backed up. Storing on EFS will help but may not be enough. Longer term you might want to think about a database of some sort.

huangapple
  • 本文由 发表于 2020年9月22日 22:39:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/64012098.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定