如果辅助失败,MongoDb主副本将成为辅助副本

时间:2016-02-26 11:30:30

标签: mongodb replicaset

我有2个mongo复制品。一个是主要的,第二个是次要的。如果我停止辅助副本,主要副本将成为辅助副本,我将失去写入权限。

以下是我的配置:

replica:PRIMARY> rs.status()
{
        "set" : "replica",
        "date" : ISODate("2016-02-26T11:27:50.140Z"),
        "myState" : 1,
        "members" : [
                {
                        "_id" : 1,
                        "name" : "192.168.5.44:27017",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 80,
                        "optime" : Timestamp(1456486069, 1),
                        "optimeDate" : ISODate("2016-02-26T11:27:49Z"),
                        "electionTime" : Timestamp(1456485992, 1),
                        "electionDate" : ISODate("2016-02-26T11:26:32Z"),
                        "configVersion" : 82935,
                        "self" : true
                },
                {
                        "_id" : 2,
                        "name" : "192.168.5.34:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 79,
                        "optime" : Timestamp(1456486067, 2),
                        "optimeDate" : ISODate("2016-02-26T11:27:47Z"),
                        "lastHeartbeat" : ISODate("2016-02-26T11:27:48.874Z"),
                        "lastHeartbeatRecv" : ISODate("2016-02-26T11:27:48.930Z"),
                        "pingMs" : 1,
                        "syncingTo" : "192.168.5.44:27017",
                        "configVersion" : 82935
                }
        ],
        "ok" : 1
}

replica:SECONDARY> rs.status()
{
        "set" : "replica",
        "date" : ISODate("2016-02-26T11:21:38.574Z"),
        "myState" : 2,
        "syncingTo" : "192.168.5.44:27017",
        "members" : [
                {
                        "_id" : 1,
                        "name" : "192.168.5.44:27017",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 1306,
                        "optime" : Timestamp(1456485695, 3),
                        "optimeDate" : ISODate("2016-02-26T11:21:35Z"),
                        "lastHeartbeat" : ISODate("2016-02-26T11:21:36.602Z"),
                        "lastHeartbeatRecv" : ISODate("2016-02-26T11:21:37.412Z"),
                        "pingMs" : 0,
                        "electionTime" : Timestamp(1456484393, 1),
                        "electionDate" : ISODate("2016-02-26T10:59:53Z"),
                        "configVersion" : 82935
                },
                {
                        "_id" : 2,
                        "name" : "192.168.5.34:27017",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 1306,
                        "optime" : Timestamp(1456485697, 1),
                        "optimeDate" : ISODate("2016-02-26T11:21:37Z"),
                        "syncingTo" : "192.168.5.44:27017",
                        "configVersion" : 82935,
                        "self" : true
                }
        ],
        "ok" : 1
}
replica:SECONDARY> cfg = rs.conf()
{
        "_id" : "replica",
        "version" : 82935,
        "members" : [
                {
                        "_id" : 1,
                        "host" : "192.168.5.44:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 2,
                        "tags" : {

                        },
                        "slaveDelay" : 0,
                        "votes" : 1
                },
                {
                        "_id" : 2,
                        "host" : "192.168.5.34:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : 0,
                        "votes" : 1
                }
        ],
        "settings" : {
                "chainingAllowed" : true,
                "heartbeatTimeoutSecs" : 10,
                "getLastErrorModes" : {

                },
                "getLastErrorDefaults" : {
                        "w" : 1,
                        "wtimeout" : 0
                }
        }
}

即使我关闭了主副本,次要也不会成为主副本。

如果您需要任何其他详细信息,请通知我。 谢谢你的帮助!

1 个答案:

答案 0 :(得分:2)

MongoDB需要多数成员才能完成选举。在2成员复制集中,两个成员必须可用于达到大多数成员。如果一个人失败,另一个人就不能当选为初选。