我正在尝试部署mongodb分片。我在三台机器中部署了一个副本集。但是,当我尝试sh.addShard("test/mongodb1.example.net:27017")
所有三个节点时,我仍然无法使其工作。显示的错误是:
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 :(得分:0)
很抱歉迟到的答案..问题是你必须通过mongoS服务提供那些sh.addShard命令。因此,您不使用mongo命令连接到primary,必须连接到mongos服务。
所以,首先你必须启动mongos到某台机器,f.ex。一个(或所有)配置服务器是很好的候选者。