mongo学习- 副本集配置(事故自动转移)

一。安装mongodb

二。复制2份

三。启动

 (1)mongod --config C:\mongofuben\zhu\conf\mongodb.config --replSet haibin/127.0.0.1:27018

   (2)   mongod --config C:\mongofuben\fu1\conf\mongodb.config --port 27018 --replSet haibin/127.0.0.0:27017

   (3)运行  在admin库运行

db.runCommand({
    replSetInitiate:{
        _id:"haibin",
        members:[
            {
                _id: 0,
                host:"127.0.0.1:27017"
            },
            {
                _id:1,
                host:"127.0.0.1:27018"
            }
        ]
    }
})

  运行 rs.status() 查看状态

 

{
    "set" : "haibin",
    "date" : ISODate("2018-08-15T08:35:30.084Z"),
    "myState" : 2,
    "term" : NumberLong(5),
    "syncingTo" : "127.0.0.1:27018",
    "heartbeatIntervalMillis" : NumberLong(2000),
    "optimes" : {
        "lastCommittedOpTime" : {
            "ts" : Timestamp(1534322129, 1),
            "t" : NumberLong(5)
        },
        "appliedOpTime" : {
            "ts" : Timestamp(1534322129, 1),
            "t" : NumberLong(5)
        },
        "durableOpTime" : {
            "ts" : Timestamp(1534322129, 1),
            "t" : NumberLong(5)
        }
    },
    "members" : [ 
        {
            "_id" : 0,
            "name" : "127.0.0.1:27017",
            "health" : 1.0,
            "state" : 2,
            "stateStr" : "SECONDARY",
            "uptime" : 116,
            "optime" : {
                "ts" : Timestamp(1534322129, 1),
                "t" : NumberLong(5)
            },
            "optimeDate" : ISODate("2018-08-15T08:35:29.000Z"),
            "syncingTo" : "127.0.0.1:27018",
            "configVersion" : 2,
            "self" : true
        }, 
        {
            "_id" : 1,
            "name" : "127.0.0.1:27018",
            "health" : 1.0,
            "state" : 1,
            "stateStr" : "PRIMARY",
            "uptime" : 114,
            "optime" : {
                "ts" : Timestamp(1534322119, 1),
                "t" : NumberLong(5)
            },
            "optimeDurable" : {
                "ts" : Timestamp(1534322119, 1),
                "t" : NumberLong(5)
            },
            "optimeDate" : ISODate("2018-08-15T08:35:19.000Z"),
            "optimeDurableDate" : ISODate("2018-08-15T08:35:19.000Z"),
            "lastHeartbeat" : ISODate("2018-08-15T08:35:29.329Z"),
            "lastHeartbeatRecv" : ISODate("2018-08-15T08:35:28.311Z"),
            "pingMs" : NumberLong(0),
            "electionTime" : Timestamp(1534321966, 1),
            "electionDate" : ISODate("2018-08-15T08:32:46.000Z"),
            "configVersion" : 2
        }, 
        {
            "_id" : 2,
            "name" : "127.0.0.1:27019",
            "health" : 1.0,
            "state" : 7,
            "stateStr" : "ARBITER",
            "uptime" : 114,
            "lastHeartbeat" : ISODate("2018-08-15T08:35:29.329Z"),
            "lastHeartbeatRecv" : ISODate("2018-08-15T08:35:26.151Z"),
            "pingMs" : NumberLong(0),
            "configVersion" : 2
        }
    ],
    "ok" : 1.0
}

  (4)mongod --config C:\mongofuben\fu2\conf\mongodb.config --port 27019 --replSet haibin/127.0.0.0:27017 (添加仲裁者)

       (5)rs.addArb("127.0.0.1:27019")(见上面的返回结果)

       (6)主动结束27017端口,查看状态。

 

posted @ 2018-08-15 16:37  anxbb  阅读(162)  评论(0编辑  收藏  举报