Cluster of MongoDB nodes

MongoDB is a database that is really well-adapted to real-time data analytics. In this tutorial we will deploy multiple servers, and glue them together.

Requirements for this use case

  • Add a Network Domain
  • Add an Ethernet network
  • Deploy multiple servers servers
  • Monitor these servers
  • Add mongoDB to the servers
  • Create a cluster of configuration servers
  • Add sharding servers

Fittings plan

Copy the text below and put it in a text file named fittings.yaml:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
 ---
 locationId: EU8 # London in Europe
 regionId: dd-eu

 blueprints:

   - mongo: mongo_config mongo_mongos mongo_shard

   - mongo_config:

       domain: &domain
         name: MongoFox
         service: essentials
         ipv4: 12

       ethernet: &ethernet
         name: mongofox.servers
         subnet: 192.168.20.0

       nodes:

         - mongo_config0[1..3]:

             glue:
               - internet 22

             cloud-config:
               disable_root: false
               ssh_pwauth: True
               packages:
                 - ntp

               write_files: # replica set for configuration servers

                 - path: /etc/mongod.conf.sed
                   content: |
                      s/#sharding:/sharding:\n   clusterRole: configsvr\nreplication:\n  replSetName: configReplSet/

               runcmd:
                 - "sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927"
                 - echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
                 - sudo apt-get update
                 - sudo apt-get install -y mongodb-org
                 - cp -n /etc/mongod.conf /etc/mongod.conf.original
                 - sed -i -f /etc/mongod.conf.sed /etc/mongod.conf
                 - sudo service mongod restart

   - mongo_mongos:

       domain: *domain
       ethernet: *ethernet

       nodes:

         - mongo_mongos01:

             glue:
               - internet 22

             cloud-config:
               disable_root: false
               ssh_pwauth: True
               packages:
                 - ntp

               write_files: # replica set for mongos servers

                 - path: /etc/mongod.conf.sed
                   content: |
                      s/#sharding:/sharding:\n   configDB: "configReplSet/{{mongo_config01}}:27019,{{mongo_config02}}:27019,{{mongo_config03}}:27019"/

               runcmd:
                 - "sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927"
                 - echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
                 - sudo apt-get update
                 - sudo apt-get install -y mongodb-org
                 - cp -n /etc/mongod.conf /etc/mongod.conf.original
                 - sed -i -f /etc/mongod.conf.sed /etc/mongod.conf
                 - sudo service mongod restart

   - mongo_shard:

       domain: *domain
       ethernet: *ethernet

       nodes:

         - mongo_shard0[1..2]:

             glue:
               - internet 22

             cloud-config:
               disable_root: false
               ssh_pwauth: True
               packages:
                 - ntp

               write_files: # replica set for sharding servers

                 - path: /etc/mongod.conf.sed
                   content: |
                      s/#sharding:/sharding:\n   clusterRole: shardsvr/

               runcmd:
                 - "sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927"
                 - echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
                 - sudo apt-get update
                 - sudo apt-get install -y mongodb-org
                 - cp -n /etc/mongod.conf /etc/mongod.conf.original
                 - sed -i -f /etc/mongod.conf.sed /etc/mongod.conf
                 - sudo service mongod restart

Deployment commands

$ python -m plumbery fittings.yaml deploy

These commands build fittings as per the provided plan, start servers and bootstrap them. The last command will display the name and password used to configure the database.

You can check status of servers like this:

$ python -m plumbery fittings.yaml ping

Follow-up commands

TO BE COMPLETED

Destruction commands

The more servers you have, the more costly it is. Would you like to stop the invoice?

$ python -m plumbery fittings.yaml stop
$ python -m plumbery fittings.yaml destroy