Reputation: 3165
I have 3 nodes for sharding and configserver (sharding servers run on standard port 27017 and configserver running on port 27019)
stage-mongo1-tmp, stage-mongo2-tmp, and stage-mongo3-tmp
and a query router
stage-query0-mongo
in my current setup.
Sharding is working perfect as expected.
--- Sharding Status ---
sharding version: {
"_id" : 1,
"version" : 3,
"minCompatibleVersion" : 3,
"currentVersion" : 4,
"clusterId" : ObjectId("5321a5cc8a18e5280f7c9d5a")
}
shards:
{ "_id" : "shard0000", "host" : "stage-mongo1-tmp:27017" }
{ "_id" : "shard0001", "host" : "stage-mongo2-tmp:27017" }
{ "_id" : "shard0002", "host" : "stage-mongo3-tmp:27017" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "testdb", "partitioned" : true, "primary" : "shard0000" }
testdb.testcollection
shard key: { "_id" : "hashed" }
chunks:
shard0001 28
shard0002 31
shard0000 28
too many chunks to print, use verbose if you want to force print
Now, I was enabling replica set on these nodes. I logged in to stage-mongo1-tmp, and ran
rs.initiate()
and added stage-mongo2-tmp and stage-mongo3-tmp as the replica members as
rs.add("stage-mongo2-tmp")
Log files says replication enabled and elected one primary. rs.conf() was showing good output
[rsBackgroundSync] replSet syncing to: stage-mongo1-tmp:27017
[rsSync] oplog sync 2 of 3
[rsSyncNotifier] replset setting oplog notifier to stage-mongo1-tmp:27017
[rsSync] replSet initial sync building indexes
[rsSync] replSet initial sync cloning indexes for : ekl_omniscient
[rsSync] build index ekl_omniscient.serviceability { _id: "hashed" }
[rsSync] build index done. scanned 571242 total records. 3.894 secs
replSet RECOVERING
replSet initial sync done
replSet SECONDARY
However, when I test the High-availability by taking one node down, mongos on the query node is returning error saying
mongos> show dbs;
Thu Mar 13 20:17:04.394 listDatabases failed:{
"code" : 11002,
"ok" : 0,
"errmsg" : "exception: socket exception [CONNECT_ERROR] for stage-mongo1-tmp:27017"} at src/mongo/shell/mongo.js:46
When I connect to one of the other node, one has automatically elected as primary. But still, my queries are returning errors. What am I doing wrong here in replica set? Why is it not high-available? Do I need to add more servers to make it high-available? I am looking for a minimum set of servers to implement this.
Upvotes: 0
Views: 448
Reputation: 3165
Figured out. We add shard for the replica set.
sh.addShard("rs0/:port,..)
Once this is done, we need to enable sharding on db level and collection level. This would enable sharding and replica.
Upvotes: 1