一:问题描述
今天在初始化mongodb副本集时报错:
[root@ser6-51 ~]# mongo
MongoDB shell version: 2.6.9
connecting to: test
> use admin;
switched to db admin
> config = { _id:"MyReplset", members:[
... {_id:0,host:"192.168.6.51:27017"},
... {_id:1,host:"192.168.6.52:27017"},
... {_id:2,host:"192.168.6.70:27017"}]
... }
{
"_id" : "MyReplset",
"members" : [
{
"_id" : 0,
"host" : "192.168.6.51:27017"
},
{
"_id" : 1,
"host" : "192.168.6.52:27017"
},
{
"_id" : 2,
"host" : "192.168.6.70:27017"
}
]
}
> rs.initiate(config);
{
"ok" : 0,
"errmsg" : "couldn't initiate : need all members up to initiate, not ok : 192.168.6.52:27017"
}
二:出错原因
mongodb没有启动或者没有开放防火墙端口
添加一行:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPT
重启防火墙
[root@ser6-52 mongodb]# /etc/init.d/iptables restart
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
--本篇文章参考自:Mongodb2.4.3集群安装笔记