Subscribe to Posts by Email

Subscriber Count

    591

Disclaimer

All information is offered in good faith and in the hope that it may be of use, but is not guaranteed to be correct, up to date or suitable for any particular purpose. db.geeksinsight.com accepts no liability in respect of this information or its use. This site is independent of and does not represent Oracle Corporation in any way. Oracle does not officially sponsor, approve, or endorse this site or its content and if notify any such I am happy to remove. Product and company names mentioned in this website may be the trademarks of their respective owners and published here for informational purpose only. This is my personal blog. The views expressed on these pages are mine and learnt from other blogs and bloggers and to enhance and support the DBA community and this web blog does not represent the thoughts, intentions, plans or strategies of my current employer nor the Oracle and its affiliates. If you see any issues with Content and copy write issues, I am happy to remove if you notify me. Contact Geek DBA Team, via email. admin@db.geeksinsight.com

Pages

MongoDB for Oracle DBA’s Part 7 : Adding a New Shard to existing Cluster in Standalone Server

In this post we will see how to Add a new shard shard2 and new replicaset rs1

  • Create Directories
  • Create Config Files
  • Start the instances in replicaset rs1
  • add the instances for replication to replicaset rs1
  • add the replicaset rs1 to shard

The final diagram in my single host, Mongos , MongoC, MongoD with replicaset along with shards looks like this. Best way to practice isnt 🙂

### Create directories ###

Note: See the directory shard2 and replicaset rs1, the existing one was in shard1 and rs0.

### Shard1 with Primary & Two Secondaries ###

mkdir -p /backups/data/cluster/shard2/rs1/0/logs

mkdir -p /backups/data/cluster/shard2/rs1/0/data

mkdir -p /backups/data/cluster/shard2/rs1/1/logs

mkdir -p /backups/data/cluster/shard2/rs1/1/data

mkdir -p /backups/data/cluster/shard2/rs1/2/logs

mkdir -p /backups/data/cluster/shard2/rs1/2/data

### Create Configuration file for node 1 , Note the port number & directory paths ###

Note: Look at the port numbers and replicaset name which is different than existing rs0 replicaset

vi /backups/data/cluster/shard2/rs0.conf

systemLog:

destination: file

path: "/backups/data/cluster/shard2/rs1/0/logs/rs1.log"

logAppend: true

processManagement:

pidFilePath: "/backups/data/cluster/shard2/rs1/0/shard2.pid"

fork: true

net:

bindIp: 127.0.0.1

port: 57018

storage:

engine: "mmapv1"

dbPath: "/backups/data/cluster/shard2/rs1/0/data"

directoryPerDB: true

operationProfiling:

mode: all

replication:

oplogSizeMB: 5120

replSetName: "rs1"

#### Create configuration file for node 2, Note the port number & directory paths ###

vi /backups/data/cluster/shard2/rs1.conf

systemLog:

destination: file

path: "/backups/data/cluster/shard2/rs1/1/logs/rs1.log"

logAppend: true

processManagement:

pidFilePath: "/backups/data/cluster/shard2/rs1/1/shard2.pid"

fork: true

net:

bindIp: 127.0.0.1

port: 57019

storage:

engine: "mmapv1"

dbPath: "/backups/data/cluster/shard2/rs1/1/data"

directoryPerDB: true

operationProfiling:

mode: all

replication:

oplogSizeMB: 5120

replSetName: "rs1"

#### Create configuration file for node 3, Note the port number & directory paths ###

vi /backups/data/cluster/shard2/rs2.conf

systemLog:

destination: file

path: "/backups/data/cluster/shard2/rs1/2/logs/rs1.log"

logAppend: true

processManagement:

pidFilePath: "/backups/data/cluster/shard2/rs1/2/shard2.pid"

fork: true

net:

bindIp: 127.0.0.1

port: 57020

storage:

engine: "mmapv1"

dbPath: "/backups/data/cluster/shard2/rs1/2/data"

directoryPerDB: true

operationProfiling:

mode: all

replication:

oplogSizeMB: 5120

replSetName: "rs1"

### Start the mongod instances in New Shard

mongod -f /backups/data/cluster/shard2/rs0.conf

mongod -f /backups/data/cluster/shard2/rs1.conf

mongod -f /backups/data/cluster/shard2/rs2.conf

### Add the instances to replicaset

MongoDB Enterprise mongos> mongo localhost:57018

MongoDB Enterprise mongos> rs.initiate({_id:"rs1", members: [{"_id":1, "host":"localhost:57018"},{"_id":2, "host":"localhost:57019"},{"_id":3, "host":"localhost:57020"}]})

MongoDB Enterprise mongos> rs.status()

### Add the replicat rs1 to shard2, log to mongos

MongoDB Enterprise mongos> mongo localhost:27017

MongoDB Enterprise mongos> sh.addShard("rs1/localhost:57018,localhost:57019,localhost:57020");

MongoDB Enterprise mongos> sh.status()

--- Sharding Status ---

sharding version: {

"_id" : 1,

"minCompatibleVersion" : 5,

"currentVersion" : 6,

"clusterId" : ObjectId("5834e646a2c25f3b06d65226")

}

shards:

{ "_id" : "rs0", "host" : "rs0/localhost:47018,localhost:47019,localhost:47020" }

{ "_id" : "rs1", "host" : "rs1/localhost:57018,localhost:57019,localhost:57020" }

active mongoses:

"3.2.1" : 1

balancer:

Currently enabled: yes

Currently running: no

Failed balancer rounds in last 5 attempts: 0

Migration Results for the last 24 hours:

No recent migrations

databases:

{ "_id" : "mydb", "primary" : "rs0", "partitioned" : true }

}

### And finally mongo process looks like this in my standalone server

root@wash-i-03aaefdf-restore /backups/data/cluster/shard1/rs0/1/data/foo $ ps -eaf | grep mongo

root 21615 1 6 11:42 ? 00:02:28 mongod -f /backups/data/cluster/shard1/rs0.conf

root 21678 1 5 11:43 ? 00:01:56 mongod -f /backups/data/cluster/shard1/rs1.conf

root 21744 1 5 11:43 ? 00:01:52 mongod -f /backups/data/cluster/shard1/rs2.conf

root 21827 1 0 11:43 ? 00:00:07 mongod -f /backups/data/cluster/mongoc/mongoc.conf

root 21844 1 4 11:43 ? 00:01:29 mongos -f /backups/data/cluster/mongos/mongos.conf

root 22075 1 0 11:57 ? 00:00:05 mongod -f /backups/data/cluster/shard2/rs0.conf

root 22096 1 0 11:57 ? 00:00:04 mongod -f /backups/data/cluster/shard2/rs1.conf

root 22117 1 0 11:57 ? 00:00:04 mongod -f /backups/data/cluster/shard2/rs2.conf

Comments are closed.