无法在MongoDB中添加分片

问题描述:

我正在尝试部署mongodb分片。我已经在三台机器上部署了一套副本。但是,当我尝试将sh.addShard("test/mongodb1.example.net:27017")添加到所有三个节点时,我仍然无法使其工作。所示的误差是:无法在MongoDB中添加分片

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

另一个错误:

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

1)设置初始副本为每个节点设置(这工作正常)

a)运行这些对所有3个节点:

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

b)中主节点运行:

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

2)设置配置服务器和查询路由器三个副本集群(这工作正常)

主节点上运行:

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

3)添加碎片(问题与添加碎片)

主节点上运行:

sh.addShard("mongodb1.example.net") 
sh.addShard("mongodb2.example.net") 
sh.addShard("mongodb3.example.net") 
+0

你有没有仔细检查所有replicaset配置和状态,你开始添加碎片之前? –

对不起,迟到的回答.. Proble m是你必须通过mongoS服务给sh.addShard命令。所以你不用mongo命令连接到primary,你必须必须连接到mongos服务

所以,首先你必须启动mongos到某台机器,f.ex.一个(或全部)配置服务器是很好的候选者。

Mongos documentation

Step by step to sharding