推荐的方法在弹性豆茎上安装mongodb

时间:2023-01-26 11:45:54

First of all, before you downvote me, I have already taken a look at How to install mongodb in Elastic Beanstalk? dated 2014, which no longer works. as well as https://docs.mongodb.org/ecosystem/platforms/amazon-ec2/#manually-deploy-mongodb-on-ec2

首先,在你向我投票之前,我已经看过如何在Elastic Beanstalk中安装mongodb? 2014年,不再有效。以及https://docs.mongodb.org/ecosystem/platforms/amazon-ec2/#manually-deploy-mongodb-on-ec2

I have set up a new elastic beanstalk environment running on node.js with 1 ec2 micro instance '64bit Amazon Linux 2016.03 v2.1.0 running Node.js'

我已经在node.js上运行了一个新的弹性beanstalk环境,其中包含1个ec2微实例'64位运行Node.js的Amazon Linux 2016.03 v2.1.0'

I have already tried using ssh to connect into my instance and install the mongodb packages using yum command:

我已经尝试使用ssh连接到我的实例并使用yum命令安装mongodb包:

$ sudo yum install -y mongodb-org-server mongodb-org-shell mongodb-org-tools

and received this call back:

并收到此回电:

Loaded plugins: priorities, update-motd, upgrade-helper
No package mongodb-org-server available.
No package mongodb-org-shell available.
No package mongodb-org-tools available.
Error: Nothing to do

When I first ssh 'd into my instance, I received this error warning:

当我第一次进入我的实例时,我收到了此错误警告:

This EC2 instance is managed by AWS Elastic Beanstalk. Changes made via SSH 
WILL BE LOST if the instance is replaced by auto-scaling. For more information 
on customizing your Elastic Beanstalk environment, see our documentation here: 
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html

Currently my environment is set up as a single instance environment, to save on costs. However, in the future I will upgrade to an auto-scaling environment.

目前,我的环境被设置为单实例环境,以节省成本。但是,将来我将升级到自动缩放环境。

Because of this, I am asking is it recommendable to make any changes via ssh in ec2, or should I only be using EB CLI?

因此,我要求在ec2中通过ssh进行任何更改是值得推荐的,还是应该只使用EB CLI?

I have both EC2 and EB CLI installed locally, however I have never used EB CLI before. If I should be using EB, does anyone have a recommended way to install mongodb?

我在本地安装了EC2和EB CLI,但之前从未使用过EB CLI。如果我应该使用EB,有没有人有推荐的方法来安装mongodb?

1 个解决方案

#1


33  

In case anyone is looking for an answer, here is the advice I received from aws business support.

如果有人正在寻找答案,这是我从aws业务支持获得的建议。

All code deployed to Elastic Beanstalk needs to be "stateless" I.E. Never make changes directly to a running beanstalk instance using SSH or FTP.... As this will cause inconsistencies and or data lose! - Elastic Beanstalk is not designed for application that are not stateless. The environment is designed to scale up and down pending on your Network / CPU load and build new instances from a base AMI. If an instance has issues or the underlying hardware, Elastic Beanstalk will terminate these running instances and replace with new instances. Hence, why no code modification must be applied or done "directly" to an existing instance as new instances will not be aware of these direct changes. ALL changes / code needs to be either uploaded to Elastic Beanstalk console or the CLI tools and the pushed to all the running instances. More information on Elastic Beanstalk design concepts can be read at the following link http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.concepts.design.html

部署到Elastic Beanstalk的所有代码都需要是“无状态”的。切勿使用SSH或FTP直接对正在运行的beanstalk实例进行更改....因为这会导致不一致和/或数据丢失! - Elastic Beanstalk不适用于非无状态的应用程序。该环境旨在根据您的网络/ CPU负载进行扩展和缩小,并从基础AMI构建新实例。如果实例有问题或底层硬件,Elastic Beanstalk将终止这些正在运行的实例并替换为新实例。因此,为什么不必对现有实例“直接”应用或完成代码修改,因为新实例不会意识到这些直接更改。所有更改/代码都需要上传到Elastic Beanstalk控制台或CLI工具,并推送到所有正在运行的实例。有关Elastic Beanstalk设计概念的更多信息,请访问以下链接:http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.concepts.design.html

Suggested Solution: With the above in mind, if using MongoDB to store application data our recommendation would be to DE-couple the MongoDB environment from your Node.js application. I.E Create a MongoDB Server outside of Elastic Beanstalk, example launching MongoDB directly on a EC2 instance and have your Elastic Beanstalk Node.js application connect to MongoDB Server using connection settings in your app.

建议的解决方案:考虑到上述情况,如果使用MongoDB存储应用程序数据,我们的建议是从Node.js应用程序中对MongoDB环境进行DE耦合。 I.E在Elastic Beanstalk之外创建一个MongoDB服务器,例如直接在EC2实例上启动MongoDB,并让您的Elastic Beanstalk Node.js应用程序使用您应用中的连接设置连接到MongoDB服务器。

-Creating MongoDB Below is some example links that may be of use for your scenario for creating a MongoDB Server. Deploy MongoDB on EC2, https://docs.mongodb.org/ecosystem/platforms/amazon-ec2/ MongoDB node client https://docs.mongodb.org/getting-started/node/client/ MongoDB on the AWS Cloud quick start guide http://docs.aws.amazon.com/quickstart/latest/mongodb/architecture.html

- 创建MongoDB下面是一些可能用于创建MongoDB服务器的场景的示例链接。在AWS云上快速部署MongoDB,https://docs.mongodb.org/ecosystem/platforms/amazon-ec2/ MongoDB节点客户端https://docs.mongodb.org/getting-started/node/client/ MongoDB开始指南http://docs.aws.amazon.com/quickstart/latest/mongodb/architecture.html

-Adding environment variables to Elastic Beanstalk to reference your MongoDB server Once you have created your MongoDB Server you can pass the needed connection settings to your Elastic Beanstalk environment using environment variables. Example using .ebextensions .config which you can add Mongo URL / ports / users etc..

- 将环境变量添加到Elastic Beanstalk以引用MongoDB服务器创建MongoDB服务器后,可以使用环境变量将所需的连接设置传递到Elastic Beanstalk环境。使用.ebextensions .config的示例,您可以添加Mongo URL / ports / users等。

option_settings: - option_name: MONGO_DB_URL value: "Your MongoDB EC2 internal IP address"

option_settings: - option_name:MONGO_DB_URL值:“您的MongoDB EC2内部IP地址”

Information on how to use environment properties and read them from within your application can be seen below. http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html#create_deploy_nodejs_custom_container-envprop And information using .ebextensions .config can be found at the following link http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html

有关如何使用环境属性并从应用程序中读取它们的信息,请参见下文。 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html#create_deploy_nodejs_custom_container-envprop使用.ebextensions .config的信息可以在以下链接找到:http://docs.aws.amazon .COM / elasticbeanstalk /最新/ DG / ebextensions.html

Alternatively you can also set environment variable using the cli or via the AWS Console eb cli set environment variables can be read per the below link. http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-setenv.html Using AWS Console To set system properties (AWS Management Console) Open the Elastic Beanstalk console. Navigate to the management console for your environment. Choose Configuration. In the Software Configuration section, choose Edit. Under Environment Properties, create your name / values ...

或者您也可以使用cli或通过AWS控制台设置环境变量eb cli set环境变量可以通过以下链接读取。 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-setenv.html使用AWS控制台设置系统属性(AWS管理控制台)打开Elastic Beanstalk控制台。导航到您的环境的管理控制台。选择配置。在“软件配置”部分中,选择“编辑”。在“环境属性”下,创建您的名称/值...

Accessing Environment Configuration Settings Inside the Node.js environment running in AWS Elastic Beanstalk, you can access the environment variables using process.env.ENV_VARIABLE similar to the following example. process.env.MONGO_DB_URL process.env.PARAM2

访问环境配置设置在AWS Elastic Beanstalk中运行的Node.js环境中,您可以使用process.env.ENV_VARIABLE访问环境变量,类似于以下示例。 process.env.MONGO_DB_URL process.env.PARAM2

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html#create_deploy_nodejs_custom_container-envprop

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html#create_deploy_nodejs_custom_container-envprop

Summary: In summary I would recommend the following steps to integrate MongoDB with Elastic Beanstalk environments. Step 1) Create a MongoDB Server outside of Elastic Beanstalk Step 2) Create your Node.js application in Elastic Beanstalk that connect to your MongoDB server

简介:总之,我建议将MongoDB与Elastic Beanstalk环境集成以下步骤。步骤1)在Elastic Beanstalk之外创建一个MongoDB服务器步骤2)在Elastic Beanstalk中创建连​​接到MongoDB服务器的Node.js应用程序

#1


33  

In case anyone is looking for an answer, here is the advice I received from aws business support.

如果有人正在寻找答案,这是我从aws业务支持获得的建议。

All code deployed to Elastic Beanstalk needs to be "stateless" I.E. Never make changes directly to a running beanstalk instance using SSH or FTP.... As this will cause inconsistencies and or data lose! - Elastic Beanstalk is not designed for application that are not stateless. The environment is designed to scale up and down pending on your Network / CPU load and build new instances from a base AMI. If an instance has issues or the underlying hardware, Elastic Beanstalk will terminate these running instances and replace with new instances. Hence, why no code modification must be applied or done "directly" to an existing instance as new instances will not be aware of these direct changes. ALL changes / code needs to be either uploaded to Elastic Beanstalk console or the CLI tools and the pushed to all the running instances. More information on Elastic Beanstalk design concepts can be read at the following link http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.concepts.design.html

部署到Elastic Beanstalk的所有代码都需要是“无状态”的。切勿使用SSH或FTP直接对正在运行的beanstalk实例进行更改....因为这会导致不一致和/或数据丢失! - Elastic Beanstalk不适用于非无状态的应用程序。该环境旨在根据您的网络/ CPU负载进行扩展和缩小,并从基础AMI构建新实例。如果实例有问题或底层硬件,Elastic Beanstalk将终止这些正在运行的实例并替换为新实例。因此,为什么不必对现有实例“直接”应用或完成代码修改,因为新实例不会意识到这些直接更改。所有更改/代码都需要上传到Elastic Beanstalk控制台或CLI工具,并推送到所有正在运行的实例。有关Elastic Beanstalk设计概念的更多信息,请访问以下链接:http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.concepts.design.html

Suggested Solution: With the above in mind, if using MongoDB to store application data our recommendation would be to DE-couple the MongoDB environment from your Node.js application. I.E Create a MongoDB Server outside of Elastic Beanstalk, example launching MongoDB directly on a EC2 instance and have your Elastic Beanstalk Node.js application connect to MongoDB Server using connection settings in your app.

建议的解决方案:考虑到上述情况,如果使用MongoDB存储应用程序数据,我们的建议是从Node.js应用程序中对MongoDB环境进行DE耦合。 I.E在Elastic Beanstalk之外创建一个MongoDB服务器,例如直接在EC2实例上启动MongoDB,并让您的Elastic Beanstalk Node.js应用程序使用您应用中的连接设置连接到MongoDB服务器。

-Creating MongoDB Below is some example links that may be of use for your scenario for creating a MongoDB Server. Deploy MongoDB on EC2, https://docs.mongodb.org/ecosystem/platforms/amazon-ec2/ MongoDB node client https://docs.mongodb.org/getting-started/node/client/ MongoDB on the AWS Cloud quick start guide http://docs.aws.amazon.com/quickstart/latest/mongodb/architecture.html

- 创建MongoDB下面是一些可能用于创建MongoDB服务器的场景的示例链接。在AWS云上快速部署MongoDB,https://docs.mongodb.org/ecosystem/platforms/amazon-ec2/ MongoDB节点客户端https://docs.mongodb.org/getting-started/node/client/ MongoDB开始指南http://docs.aws.amazon.com/quickstart/latest/mongodb/architecture.html

-Adding environment variables to Elastic Beanstalk to reference your MongoDB server Once you have created your MongoDB Server you can pass the needed connection settings to your Elastic Beanstalk environment using environment variables. Example using .ebextensions .config which you can add Mongo URL / ports / users etc..

- 将环境变量添加到Elastic Beanstalk以引用MongoDB服务器创建MongoDB服务器后,可以使用环境变量将所需的连接设置传递到Elastic Beanstalk环境。使用.ebextensions .config的示例,您可以添加Mongo URL / ports / users等。

option_settings: - option_name: MONGO_DB_URL value: "Your MongoDB EC2 internal IP address"

option_settings: - option_name:MONGO_DB_URL值:“您的MongoDB EC2内部IP地址”

Information on how to use environment properties and read them from within your application can be seen below. http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html#create_deploy_nodejs_custom_container-envprop And information using .ebextensions .config can be found at the following link http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html

有关如何使用环境属性并从应用程序中读取它们的信息,请参见下文。 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html#create_deploy_nodejs_custom_container-envprop使用.ebextensions .config的信息可以在以下链接找到:http://docs.aws.amazon .COM / elasticbeanstalk /最新/ DG / ebextensions.html

Alternatively you can also set environment variable using the cli or via the AWS Console eb cli set environment variables can be read per the below link. http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-setenv.html Using AWS Console To set system properties (AWS Management Console) Open the Elastic Beanstalk console. Navigate to the management console for your environment. Choose Configuration. In the Software Configuration section, choose Edit. Under Environment Properties, create your name / values ...

或者您也可以使用cli或通过AWS控制台设置环境变量eb cli set环境变量可以通过以下链接读取。 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-setenv.html使用AWS控制台设置系统属性(AWS管理控制台)打开Elastic Beanstalk控制台。导航到您的环境的管理控制台。选择配置。在“软件配置”部分中,选择“编辑”。在“环境属性”下,创建您的名称/值...

Accessing Environment Configuration Settings Inside the Node.js environment running in AWS Elastic Beanstalk, you can access the environment variables using process.env.ENV_VARIABLE similar to the following example. process.env.MONGO_DB_URL process.env.PARAM2

访问环境配置设置在AWS Elastic Beanstalk中运行的Node.js环境中,您可以使用process.env.ENV_VARIABLE访问环境变量,类似于以下示例。 process.env.MONGO_DB_URL process.env.PARAM2

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html#create_deploy_nodejs_custom_container-envprop

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html#create_deploy_nodejs_custom_container-envprop

Summary: In summary I would recommend the following steps to integrate MongoDB with Elastic Beanstalk environments. Step 1) Create a MongoDB Server outside of Elastic Beanstalk Step 2) Create your Node.js application in Elastic Beanstalk that connect to your MongoDB server

简介:总之,我建议将MongoDB与Elastic Beanstalk环境集成以下步骤。步骤1)在Elastic Beanstalk之外创建一个MongoDB服务器步骤2)在Elastic Beanstalk中创建连​​接到MongoDB服务器的Node.js应用程序