0

I am trying to deploy mongodb sharding. I have deployed a replica set in three machines. However, I still can't seem to make it work when I try to sh.addShard("test/mongodb1.example.net:27017") to all the three nodes. The error shown is:

2016-11-09T16:02:46.704+0800 W NETWORK  [conn105] No primary detected for set team3

Another error:

{
  "ok" : 0,
  "errmsg" : "could not find host matching read preference { mode: \"primary\" } for set test",
  "code" : 133
}

1) Set up initial replica set for each node (This works fine)

a) Run these for all 3 nodes:

mkdir /temp/data/team3
./mongod --replSet "team3" --dbpath /temp/data/team3
./mongo --host <mongodb[x].example.net>  

b) Primary node runs:

rs.initiate()
rs.add("mongodb2.example.net")
rs.add("mongodb3.example.net")

2) Setting up configuration server and query router for Three replica cluster (This works fine)

Primary node runs:

mkdir /temp/data/config_rs
./mongod --configsvr --replSet "config_rs" --dbpath /temp/data/config_rs
./mongo --host mongodb1.example.net --port 27019

3) Add shards (Problem with adding shard)

Primary node runs:

sh.addShard("mongodb1.example.net")
sh.addShard("mongodb2.example.net")
sh.addShard("mongodb3.example.net")
Vince Bowdren
  • 8,326
  • 3
  • 31
  • 56
stackyyflow
  • 767
  • 3
  • 11
  • 30

1 Answers1

0

Sorry for late answer.. Problem is that you must give those sh.addShard commands thru mongoS service. So you don't connect to primary with mongo command, you must connect to mongos service.

So, first you must start mongos to some machine, f.ex. one (or all) config servers are good candidates.

Mongos documentation

Step by step to sharding

JJussi
  • 1,540
  • 12
  • 12