简体   繁体   English

如何从 EB 获取我的 EC2 实例以停止重新安装 java 7?

[英]How do I get my EC2 instance from EB to stop re-installing java 7?

So, basically I have an EC2 instance that was created by Elastic Beanstalk and about every week I have been SSHing into it to uninstall java 7 and install java 8. The elastic beanstalk environment is set up for Node.js, but I have a separate java program that needs to be instantiated.所以,基本上我有一个由 Elastic Beanstalk 创建的 EC2 实例,大约每周我都会通过 SSH 连接到它来卸载 java 7 并安装 java 8。弹性 beanstalk 环境是为 Node.js 设置的,但我有一个单独的需要实例化的java程序。 I tried putting commands to install java 8 in rc.local but that didn't work at all.我尝试在 rc.local 中放置安装 java 8 的命令,但这根本不起作用。 The file is now back to its default state.该文件现在恢复到其默认状态。 Is there somewhere where I can set up the instance to default to Java 8?有什么地方可以将实例设置为默认为 Java 8? Is there a way to just keep the installation that I install via SSH?有没有办法只保留我通过 SSH 安装的安装? Please help, my site keeps going down because of this and I'm not really sure what to do about it and google was not much help.请帮忙,我的网站因此而不断下降,我不确定该怎么做,谷歌也没有太大帮助。

.ebextensions is how I would do this: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html .ebextensions 是我这样做的方式: https ://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html

.ebextensions run anytime an ec2 instance is created; .ebextensions 在任何时候创建 ec2 实例时运行; so script the uninstall of java 7 and install of java 8, and you're good to go.所以编写java 7的卸载和java 8的安装脚本,你很高兴。

More info...更多信息...

It sounds like you understand that every now and again, EB automatically destroys your ec2 instance and replaces it.听起来您明白,EB 会时不时地自动销毁您的 ec2 实例并替换它。 Often this is done on a weekly basis;通常每周进行一次; take a look at the EB console -> Configuration -> Managed updates.查看 EB 控制台 -> 配置 -> 托管更新。 You'll probably find that it says你可能会发现它说

Managed updates: enabled

Weekly update window: [some date/time here]

This is a good thing.这是一件好事。 EB is automatically installing important security and other updates for you. EB 会自动为您安装重要的安全更新和其他更新。 When it does this, it may replace your ec2 instances.当它这样做时,它可能会替换您的 ec2 实例。 Which means: the ec2 instance that you manually installed java 8 on is destroyed, and a brand new machine is created.这意味着:您手动安装 java 8 的 ec2 实例被销毁,并创建了一台全新的机器。 This brand new machine has the default java 7 installed on it...and now you again have to SSH manually into this new instance and install 8.这台全新的机器上安装了默认的 java 7……现在您再次必须手动通过 SSH 连接到这个新实例并安装 8。

What you need is a script that will run on all new ec2 instances that EB decides to create for you;您需要的是一个脚本,该脚本将在 EB 决定为您创建的所有新 ec2 实例上运行; this script will follow the steps you are taking each time you manually SSH into your ec2 instance.每次手动通过 SSH 连接到 ec2 实例时,此脚本将遵循您正在执行的步骤。 Note that even if you turned off managed updates, it's still possible (even likely) that ec2 instances get destroyed.请注意,即使您关闭了托管更新,ec2 实例仍有可能(甚至很可能)被破坏。 This is a tenant of good infrastructure design;这是一个拥有良好基础设施设计的租户; if an ec2 instance has a problem for any reason, your infrastructure should automatically in the background:如果 ec2 实例因任何原因出现问题,您的基础设施应自动在后台:

1.) Start a new ec2 instance 1.) 启动一个新的 ec2 实例

2.) Provision the new ec2 instance 2.) 提供新的 ec2 实例

3.) Reroute your website traffic to the new instance 3.) 将您的网站流量重新路由到新实例

4.) Decommission the old ec2 instance 4.) 停用旧的 ec2 实例

So, in an .ebextensions file, create a script that will uninstall java 7 and install java 8 and you'll be all set.因此,在 .ebextensions 文件中,创建一个脚本,该脚本将卸载 java 7 并安装 java 8,您将大功告成。

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

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