Elastic Beanstalk 中的 Mongos 安装/设置 [英] Mongos Install/Setup in Elastic Beanstalk

查看:26
本文介绍了Elastic Beanstalk 中的 Mongos 安装/设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

展望分片之路,我们希望能够拥有多个 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 文件中的其他条目可能会导致它以我想要的方式启动.但我不能用 Mongos 做到这一点.如果我安装 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?

我们不打算立即执行此操作,但我们需要做一些准备,好像我没有准备好这些部分,事后我需要完全重建我的 beanstalk 服务器.我宁愿立即部署,安装所有软件.

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

这个文件的作用是:-

运行 4 个容器命令(这些在创建服务器之后但在部署 WAR 之前运行.它们是:-

Runs 4 container commands (these are run after the server is created but before the WAR is deployed. These are: -

  1. 启用 root 访问权限 - 这是sudo"命令 afaik 所必需的.
  2. 安装 Mongo - 使用 yum 命令将 mongo 安装为服务.我们只需要mongos",但这还没有从 mongo 服务器中分离出来.这可能会在未来发生变化.
  3. 将 mongod 的配置更改为关闭" - 这意味着如果服务器重新启动,则 mongod 程序不会在服务器重新启动时运行.
  4. 创建脚本来运行 mongos.请注意第 4 步中的 $MONGO_CONFIG_IPS,您可以使用 Elastic Beanstalk 中的配置页面将它们传入.这将在服务器重新启动时运行.
  5. 设置执行权限.这些原因我做了 4/5 而不是放入文件:部分是它没有从环境变量创建 IP 地址.
  6. 运行在第 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 地址 - 每个弹性 beanstalk 中都不需要更新,这真的很酷.但是,如果您不想创建区域,您可以简单地在 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 in configDB 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆