在docker中搭建了一个mongon集群,先将其初始化的过程记录一下。
   进入到容器中,通过mongo进入MONGON,
use admin
config = {_id: "mongo",members:[{_id:0,host:"host3:27017",priority:2},{_id:1,host:"host2:27017",priority:1},{_id:2,host:"host1:27017",priority:1}]}
rs.initiate(config);
执行完毕后返回{ "ok" : 1 },初始化成功。
   查看节点状态:
mongo:PRIMARY> rs.status();
{
        "set" : "mongo",
        "date" : ISODate("2016-12-29T03:21:07.256Z"),
        "myState" : 1,
        "members" : [
                {
                        "_id" : 0,
                        "name" : "host3:27017",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 10748,
                        "optime" : Timestamp(1482981408, 1),
                        "optimeDate" : ISODate("2016-12-29T03:16:48Z"),
                        "electionTime" : Timestamp(1482981412, 1),
                        "electionDate" : ISODate("2016-12-29T03:16:52Z"),
                        "configVersion" : 1,
                        "self" : true
                },
                {
                        "_id" : 1,
                        "name" : "host2:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 258,
                        "optime" : Timestamp(1482981408, 1),
                        "optimeDate" : ISODate("2016-12-29T03:16:48Z"),
                        "lastHeartbeat" : ISODate("2016-12-29T03:21:06.953Z"),
                        "lastHeartbeatRecv" : ISODate("2016-12-29T03:21:06.952Z"),
                        "pingMs" : 0,
                        "lastHeartbeatMessage" : "could not find member to sync from",
                        "configVersion" : 1
                },
                {
                        "_id" : 2,
                        "name" : "host1:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 258,
                        "optime" : Timestamp(1482981408, 1),
                        "optimeDate" : ISODate("2016-12-29T03:16:48Z"),
                        "lastHeartbeat" : ISODate("2016-12-29T03:21:06.953Z"),
                        "lastHeartbeatRecv" : ISODate("2016-12-29T03:21:06.951Z"),
                        "pingMs" : 0,
                        "lastHeartbeatMessage" : "could not find member to sync from",
                        "configVersion" : 1
                }
        ],
        "ok" : 1
}

参考:http://blog.csdn.net/wik_123/article/details/52762085

无觅关联推荐,快速提升流量