Mongos Install/Setup in Elastic Beanstalk

前端 未结 2 1357
不知归路
不知归路 2020-12-07 16:13

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

相关标签:
2条回答
  • 2020-12-07 16:40

    I couldn't get @bobmarksie's solution to work, but thanks to anowak and avinci here for this .ebextensions/aws.config file:

    files:
      "/home/ec2-user/install_mongo.sh" :
        mode: "0007555"
        owner: root
        group: root
        content: |
          #!/bin/bash
          echo "[MongoDB]
          name=MongoDB Repository
          baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
          gpgcheck=0
          enabled=1" | tee -a /etc/yum.repos.d/mongodb.repo
          yum -y update
          yum -y install mongodb-org-server mongodb-org-shell mongodb-org-tools
    
    commands:
      01install_mongo:
        command: ./install_mongo.sh
        cwd: /home/ec2-user
        test: '[ ! -f /usr/bin/mongo ] && echo "MongoDB not installed"'
    
    services:
      sysvinit:
        mongod:
          enabled: true
          ensureRunning: true
          commands: ['01install_mongo']
    
    0 讨论(0)
  • 2020-12-07 16:45

    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
    

    What this file does is: -

    • Creates a "mongodb.repo" file (see http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux/).

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

    1. Enable root access - this is required for "sudo" commands afaik.
    2. Install Mongo - install mongo as a service using the yum command. We only need "mongos" but this has not been separated yet from the mongo server. This may change in future.
    3. Change config for mongod to "off" - this means if the server restarts the mongod program isn't run if the server restarts.
    4. Create script to run mongos. Note the $MONGO_CONFIG_IPS in step 4, you can pass these in using the configuration page in Elastic Beanstalk. This will run on a server reboot.
    5. Set permissions to execute. These reason I did 4/5 as opposed to putting into into a files: section is that it did not create the IP addresses from the environment variable.
    6. Run script created in step 4.

    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


    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.

    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 &"
    
    0 讨论(0)
提交回复
热议问题