One: Problem description
Today in initializing MongoDB replica set times wrong:
[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"
} Two: Cause of the error
MongoDB does not start or does not have an open firewall port
Three: The solution to open MongoDB. The reason I went wrong here is that there is no open firewall port. Vi/etc/sysconfig/iptables
Add a line:
-A input-m state--state new-m tcp-p TCP--dport 27017-j ACCEPT
Restarting the firewall
[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]
--This article references from: Mongodb2.4.3 cluster installation Notes