简体   繁体   English

使用 Java 修改 AWS 文件?

[英]Using Java to modify AWS file?

I would like to build a centOS 7 instance on AWS and install Apache to build web server.我想在 AWS 上构建一个 centOS 7 实例并安装 Apache 来构建 web 服务器。 After that, I would like to modify the config file, /etc/hosts and /etc/httpd/conf.d/test.conf where test.conf is created by me.之后,我想修改配置文件 /etc/hosts 和 /etc/httpd/conf.d/test.conf 其中 test.conf 是我创建的。

Can I use java to modify the file directly?可以直接用java修改文件吗? Or I should create the file and replace the old file on instance?或者我应该创建文件并替换实例上的旧文件? I am little bit confused for the feasibility.我对可行性有点困惑。 Please someone help.请有人帮忙。

There seem to be a few questions here, so I've split them out.这里似乎有几个问题,所以我把它们分开了。

Q: Can I use programming language X to modify a file on the local filesystem?问:我可以使用编程语言 X 来修改本地文件系统上的文件吗?
A: Yes, with very few exceptions.答:是的,除了极少数例外。 For Java, yes (if the instance has a JRE).对于 Java,是(如果实例具有 JRE)。

Q: Should I use Java?问:我应该使用 Java 吗?
A: Probably not the first choice (you could probably do what you need in a shell script at launch).答:可能不是第一选择(您可能在启动时在 shell 脚本中执行您需要的操作)。

Q: Should I create the Apache config files dynamically or build them into an AMI ?问:我应该动态创建 Apache 配置文件还是将它们构建到AMI中?
A: Difficult to answer without more information.答:没有更多信息很难回答。 There are pros and cons to AMIs. AMI 有利有弊。 If it's simple and quick to create/modify the files on launch, then I'd do it that way.如果在启动时创建/修改文件简单快捷,那么我会这样做。

DevOps is a big subject and there are many options available to you for bootstrapping EC2 instances. DevOps 是一个很大的主题,您可以使用许多选项来引导 EC2 实例。 Pre-baked AMIs is one option.预烘焙 AMI 是一种选择。 Another simple option that you might consider is to write userdata scripts , that run at launch time, and that set up the instance for you (see simple nginx example ).您可能会考虑的另一个简单选项是编写在启动时运行的userdata 脚本,并为您设置实例(参见简单的nginx 示例)。 They can install software, modify config files, start services, and other things.他们可以安装软件、修改配置文件、启动服务和其他事情。 They can also pull collateral such as pre-staged config files from S3, which can be a handy option.他们还可以从 S3 中提取诸如预先准备好的配置文件之类的附属品,这可能是一个方便的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM