FIELD NOTES / WLDANDAN

Happy Coding, Happy Life

Systems, software & the craft of making things work.

EST.
2013

INDEX / NOSQL

NoSQL

· NoSQL

How to setup mongo shard

To simulate the process of production deployment of MongoDB, I used Vagrant to create a couples of VMs, and exprienced the journey of deployment mongo step by step as follow mentioned.

Mongo Shard Concepts

Before dived into the code, we can review the concepts related to Mongo Shard, it needs 3 components logically at least.

a) Config Server

The config server processes are mongod instances that store the cluster’s metadata. You designate a mongod as a config server using the –configsvr option. Each config server stores a complete copy of the cluster’s metadata.

b) Query Server

The query server are lightweight mongos instances and do not require data directories. You can run a mongos instance on a system that runs other cluster components, such as on an application server or a server running a mongod process. By default, a mongos instance runs on port 27017.

· NoSQL

How to setup mongo repliSet

Create one mongo repliSet

mkdir -p /srv/mongodb/rs0-0 /srv/mongodb/rs0-1 /srv/mongodb/rs0-2

Run instances

mongod --port 27017 --dbpath /srv/mongodb/rs0-0 --replSet rs0 --smallfiles --oplogSize 128
mongod --port 27018 --dbpath /srv/mongodb/rs0-1 --replSet rs0 --smallfiles --oplogSize 128
mongod --port 27019 --dbpath /srv/mongodb/rs0-2 --replSet rs0 --smallfiles --oplogSize 128

Enable replicaSet

mongo --port 27017
rs.initiate()
rs.conf()
rs.status()