pull/63/head
bennojoy 11 years ago
parent 9afa3c5a22
commit 01f0c6454e
  1. 18
      mongodb/README.md
  2. 6
      mongodb/playbooks/test.yml
  3. 17
      mongodb/playbooks/testsharding.yml
  4. 5
      mongodb/roles/common/handlers/main.yml
  5. 27
      mongodb/roles/common/templates/iptables.j2
  6. 3
      mongodb/roles/mongos/templates/enablesharding.j2

@ -4,7 +4,9 @@ Deploying a shared production ready MongoDB cluster with Ansible
In this example we demonstrate how we can orchestrate the deployment of a production grade MongoDB Cluster. The functionality of this example includes:
1) Deploying a N node MongoDB cluster, which has N shards and N replication nodes.
2) Scale out capability. Expand the Cluster by adding nodes to the cluster.
3) Security, All the mongodb process are secured using the best practices.
###Deployment Architecture.
@ -34,7 +36,7 @@ Once the cluster is deployed, if we want to scale the cluster, Ansible configure
3) Adds a new shard to the mongos service pointing to the new replication set.
#### Pre-Requesites
#### Pre-requisite
1) Update the group_vars/all file which contains site specific parmaters, especially the section which contains the mapping of the hostname's and the ports that it should use for the mongod process. Please do make sure the ansible hostname matches the same. Also dont forget to add the variable when adding a new node.
@ -48,19 +50,19 @@ The inventory file looks as follows:
[mongoservers]
mongo1
mongo2
mongo3
mongo3
#The list of servers where replication should happen, including the master server.
[replicationservers]
mongo1
mongo2
mongo3
mongo3
#The list of mongodb configuration servers, make sure it is 1 or 3
[mongocservers]
mongo1
mongo2
mongo3
mongo3
#The list of servers where mongos servers would run.
[mongosservers]
@ -109,9 +111,11 @@ and issue the command to query the status of replication set, we should get a si
"ok" : 1
}
we can check the status of the Shards as follows: connect to the mongos service 'mongos --host <ip of mongos server> --port 8888'
and issue the following command to get the status of the Shards.
mongos> sh.status()
--- Sharding Status ---
@ -162,20 +166,20 @@ To add a new node to the configured MongoDb Cluster, setup the inventory file as
[mongoservers]
mongo1
mongo2
mongo3
mongo3
mongo4
#The list of servers where replication should happen, make sure the new node is listed here.
[replicationservers]
mongo4
mongo1
mongo2
mongo2
#The list of mongodb configuration servers, make sure it is 1 or 3
[mongocservers]
mongo1
mongo2
mongo3
mongo3
#The list of servers where mongos servers would run.
[mongosservers]

@ -0,0 +1,6 @@
---
- hosts: mongoservers
tasks:
- name: test
debug: msg="hello- ${mongod_ports.${item}}"
with_items: ${groups.mongoservers}

@ -0,0 +1,17 @@
---
# The playbook creates a new database test and populates data in the database to test the sharding.
- hosts: $servername
user: root
tasks:
- name: Create a new database and user
mongodb_user: login_user=admin login_password=${mongo_admin_pass} login_port=${mongos_port} database=test user=admin password=${mongo_admin_pass} state=present
- name: Pause for the user to get created and replicated
pause: minutes=3
- name: Execute the collection creation script
command: /usr/bin/mongo localhost:${mongos_port}/test -u admin -p ${mongo_admin_pass} /tmp/testsharding.js
- name: Enable sharding on the database and collection
command: /usr/bin/mongo localhost:${mongos_port}/admin -u admin -p ${mongo_admin_pass} /tmp/enablesharding.js

@ -0,0 +1,5 @@
---
# Handler for mongod
- name: restart iptables
service: name=iptables state=restarted

@ -0,0 +1,27 @@
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
{% if 'mongocservers' in group_names %}
-A INPUT -p tcp --dport 7777 -j ACCEPT
{% endif %}
{% if 'mongosservers' in group_names %}
-A INPUT -p tcp --dport 8888 -j ACCEPT
{% endif %}
{% if 'mongoservers' in group_names %}
{% for host in groups['mongoservers'] %}
-A INPUT -p tcp --dport {{ mongod_ports[host] }} -j ACCEPT
{% endfor %}
{% endif %}
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

@ -0,0 +1,3 @@
db.runCommand( { enableSharding : "test" } )
db.runCommand( { shardCollection : "test.test_collection", key : {"number":1} })