mongodb是复制的主要人物

时间:2016-11-24 07:48:40

标签: mongodb replication

如何从辅助复制中显示哪一个是主mongodb机器,而不必强制登录到每台机器并检查?

运行ismaster命令只提供当前机器是次要的

rs0:SECONDARY> db.runCommand("ismaster")
{
        "hosts" : [
                "dbRby1:27017",
                "dbRby2:27017",
                "dbKrstd1:27017"
        ],
        "setName" : "rs0",
        "setVersion" : 5,
        "ismaster" : false,
        "secondary" : true,
        "me" : "dbRby1:27017",
        "maxBsonObjectSize" : 16777216,
        "maxMessageSizeBytes" : 48000000,
        "maxWriteBatchSize" : 1000,
        "localTime" : ISODate("2016-11-24T07:36:09.855Z"),
        "maxWireVersion" : 4,
        "minWireVersion" : 0,
        "ok" : 1
}

或者使用rc.conf(),我看不到

rs0:SECONDARY> rs.conf()
{
        "_id" : "rs0",
        "version" : 5,
        "protocolVersion" : NumberLong(1),
        "members" : [
                {
                        "_id" : 0,
                        "host" : "dbRby1:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 2,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 1,
                        "host" : "dbRby2:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

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

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                }
        ],
        "settings" : {
                "chainingAllowed" : true,
                "heartbeatIntervalMillis" : 2000,
                "heartbeatTimeoutSecs" : 10,
                "electionTimeoutMillis" : 10000,
                "getLastErrorModes" : {

                },
                "getLastErrorDefaults" : {
                        "w" : "majority",
                        "wtimeout" : 5000
                },
                "replicaSetId" : ObjectId("5811ec4c70c224f06fba884b")
        }
}

1 个答案:

答案 0 :(得分:0)

rs.status()会将所需信息提供为@Xenwar