简体   繁体   中英

Unable to addShard in MongoDB

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")

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM