在Elastic Beanstalk中安装/设置Mongos [英] Mongos Install/Setup in Elastic Beanstalk
问题描述
在分片的过程中,我们希望能够有多个mongos实例.建议似乎是在每个应用程序服务器上放置mongos.我当时以为只是在他们自己的服务器上进行负载平衡,但是本文 http://craiggwilson.com/2013/10/21/load-balanced-mongos/表示存在此问题.
Looking down the road at sharding, we would like to be able to have multiple mongos instances. The recommendation seems to be to put mongos on each application server. I was thinking I'd just load balance them on their own servers, but this article http://craiggwilson.com/2013/10/21/load-balanced-mongos/ indicates that there are issue with this.
因此,我将其返回到应用程序服务器上.但是,我们正在使用Elastic Beanstalk.我可以以软件包安装的形式安装Mongo.但是,这给Mongos带来了一个问题.我还无法找出如何使用mongodb.conf文件使mongos启动.对于复制的服务器或配置服务器,conf文件中的其他条目可能会使它以我想要的方式启动.但是我对蒙哥斯无法做到这一点.如果我安装了Mongo,它实际上会以mongodb的形式启动.我需要终止这种行为,并使其以Mongos的身份启动,指向我的配置服务器.
So I'm back to having it on the application servers. However, we are using Elastic Beanstalk. I could install Mongo on this as a package install. But, this creates an issue with Mongos. I have not been able to find out how to get a mongos startup going using the mongodb.conf file. For replicated servers, or config servers, additional entries in the conf file can cause it to start up the way I want. But I can't do that with Mongos. If I install Mongo, it actually starts up as mongodb. I need to kill that behaviour, and get it to start as Mongos, pointed at my config servers.
我所能想到的是:
杀死mongodb启动脚本,该脚本以普通"模式自动启动数据库. 创建一个新的upstart脚本,启动mongos,指向配置服务器.
Kill the mongodb startup script, that autostarts the database in 'normal' mode. Create a new upstart script that starts up mongos, pointed at the config servers.
对此有何想法?还是有人知道我是否只是呆板,可以将一个新的mongodb.conf文件复制到beantalk上,该服务器将以mongos的身份启动服务器?
Any thoughts on this? Or does anyone know if I'm just being obtuse, and I can copy a new mongodb.conf file into place on beanstalk that will start up the server as mongos?
我们并没有计划立即进行此操作,但是我们需要做一些准备,好像我没有适当的准备,事后我需要完全重建我的beantalk服务器.我宁愿部署并安装所有软件.
We are not planning on doing this right off the bat, but we need to prepare somewhat, as if I don't have the pieces in place, I'll need to completely rebuild my beanstalk servers after the fact. I'd rather deploy ready to go, with all the software installed.
推荐答案
我创建了一个名为".ebextensions"的文件夹和一个名为"aws.config"的文件.该文件的内容如下:-
I created a folder called ".ebextensions" and a file called "aws.config". The contents of this file is as follows: -
files:
"/etc/yum.repos.d/mongodb.repo":
mode: "000644"
content: |
[MongoDB]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
enabled=1
container_commands:
01_enable_rootaccess:
command: echo Defaults:root \!requiretty >> /etc/sudoers
02_install_mongo:
command: yum install -y mongo-10gen-server
ignoreErrors: true
03_turn_mongod_off:
command: sudo chkconfig mongod off
04_create_mongos_startup_script:
command: sudo sh -c "echo '/usr/bin/mongos -configdb $MONGO_CONFIG_IPS -fork -logpath /var/log/mongo/mongos.log --logappend' > /etc/init.d/mongos.sh"
05_update_mongos_startup_permissions:
command: sudo chmod +x /etc/init.d/mongos.sh
06_start_mongos:
command: sudo bash /etc/init.d/mongos.sh
此文件的作用是:-
- 创建一个"mongodb.repo"文件(请参见运行4个容器命令(这些命令在创建服务器之后但在部署WAR之前运行.它们是:-
Runs 4 container commands (these are run after the server is created but before the WAR is deployed. These are: -
- 启用root用户访问权限-这是"sudo"命令afaik所必需的.
- 安装Mongo-使用yum命令将mongo作为服务安装.我们只需要"mongos",但这尚未与mongo服务器分离.将来可能会改变.
- 将mongod的配置更改为关闭"-这意味着如果服务器重新启动,则如果服务器重新启动,mongod程序将不会运行.
- 创建脚本以运行mongos.请注意步骤4中的$ MONGO_CONFIG_IPS,您可以使用Elastic Beanstalk中的配置页面将它们传递给我们.这将在服务器重新启动时运行.
- 设置执行权限.这些原因是我做4/5而不是放入文件中:部分是它没有根据环境变量创建IP地址.
- 运行在步骤4中创建的脚本.
这对我有用.我的WAR文件只是连接到本地主机,所有流量都通过路由器.我偶然发现了几天,因为Amazon AWS和MongoDB中的文档都很薄.
This works for me. My WAR file simply connects to localhost and all the traffic goes through the router. I stumbled about for a couple of days on this as the documentation is fairly slim in both Amazon AWS and MongoDB.
http://docs.aws.amazon. com/elasticbeanstalk/latest/dg/customize-containers-ec2.html
更新:-如果您对我的旧答案有疑问,请尝试以下操作-它适用于Mongo的版本3,目前正在我们的生产MongoDB集群中使用.
UPDATE: - If you are having problems with my old answer, please try the following - it works for version 3 of Mongo and is currently being used in our production MongoDB cluster.
此版本更高级,因为它使用内部DNS(通过AWS Route53)-请注意
mongo-cfg1.internal ...
.这是推荐的最佳实践,非常值得使用Route53设置您的专用区域.这意味着,如果其中一个MongoDB Config实例出现问题,您可以替换损坏的实例并更新Route53中的私有IP地址-每个弹性beantalk中都不需要更新,这真的很酷.但是,如果您不想创建区域,则只需在configDB
属性中插入IP地址即可(如我的第一个示例).This version is more advanced in that it uses internal DNS (via AWS Route53) - note the
mongo-cfg1.internal ...
. This is recommended best practices and well worth setting up your private zone using Route53. This means if there's an issue with one of the MongoDB Config instances you can replace the broken instance and update the private IP address in Route53 - no updates required in each elastic beanstalk which is really cool. However, if you don't want to create a zone you can simply insert the IP addresses inconfigDB
attribute (like my first example).files: "/etc/yum.repos.d/mongodb.repo": mode: "000644" content: | [mongodb-org-3.0] name=MongoDB Repository baseurl=http://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.0/x86_64/ gpgcheck=0 enabled=1 "/opt/mongos.conf": mode: "000755" content: | net: port: 27017 operationProfiling: {} processManagement: fork: "true" sharding: configDB: mongo-cfg1.internal.company.com:27019,mongo-cfg2.internal.company.com:27019,mongo-cfg3.internal.company.com:27019 systemLog: destination: file path: /var/log/mongos.log container_commands: 01_install_mongo: command: yum install -y mongodb-org-mongos-3.0.2 ignoreErrors: true 02_start_mongos: command: "/usr/bin/mongos -f /opt/mongos.conf > /dev/null 2>&1 &"
这篇关于在Elastic Beanstalk中安装/设置Mongos的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!