【二】mongo副本集添加新成员

mongo - 副本集增加新成员

1. 当前状态

C:\>mongo 127.0.0.1:2222

MongoDB shell version: 1.8.3

connecting to: 127.0.0.1:2222/test

neu:PRIMARY> rs.conf()

{

        "_id" : "neu",

        "version" : 3,

        "members" : [

                {

                        "_id" : 0,

                        "host" : "ZJNO9LZF6G8LBPS:1111"

                },

                {

                        "_id" : 1,

                        "host" : "ZJNO9LZF6G8LBPS:2222"

                },

                {

                        "_id" : 2,

                        "host" : "ZJNO9LZF6G8LBPS:9999",

                        "arbiterOnly" : true

                }

        ]

}

neu:PRIMARY> rs.status()

{

        "set" : "neu",

        "date" : ISODate("2012-12-08T02:26:33Z"),

        "myState" : 1,

        "members" : [

                {

                        "_id" : 0,

                        "name" : "ZJNO9LZF6G8LBPS:1111",

                        "health" : 1,

                        "state" : 2,

                        "stateStr" : "SECONDARY",

                        "uptime" : 109,

                        "optime" : {

                                "t" : 1354852100000,

                                "i" : 1

                        },

                        "optimeDate" : ISODate("2012-12-07T03:48:20Z"),

                        "lastHeartbeat" : ISODate("2012-12-08T02:26:32Z")

                },

                {

                        "_id" : 1,

                        "name" : "ZJNO9LZF6G8LBPS:2222",

                        "health" : 1,

                        "state" : 1,

                        "stateStr" : "PRIMARY",

                        "optime" : {

                                "t" : 1354852100000,

                                "i" : 1

                        },

                        "optimeDate" : ISODate("2012-12-07T03:48:20Z"),

                        "self" : true

                },

                {

                        "_id" : 2,

                        "name" : "ZJNO9LZF6G8LBPS:9999",

                        "health" : 1,

                        "state" : 7,

                        "stateStr" : "ARBITER",

                        "uptime" : 59,

                        "optime" : {

                                "t" : 0,

                                "i" : 0

                        },

                        "optimeDate" : ISODate("1970-01-01T00:00:00Z"),

                        "lastHeartbeat" : ISODate("2012-12-08T02:26:32Z")

                }

        ],

        "ok" : 1

}

2. 在新窗口中启动mongod进程

D:\mongodb>mongod --dbpath D:\mongodb\neu-2 --port 3333 --replSet neu

Sat Dec 08 10:37:09 [initandlisten] MongoDB starting : pid=368 port=3333 dbpath=D:\mongodb\neu-2 32-bit

** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data

**       see http://blog.mongodb.org/post/137788967/32-bit-limitations

**       with --dur, the limit is lower

Sat Dec 08 10:37:09 [initandlisten] db version v1.8.3, pdfile version 4.5

……

3. 增加成员

neu:PRIMARY> rs.add("ZJNO9LZF6G8LBPS:3333")

Sat Dec 08 10:37:42 DBClientCursor::init call() failed

Sat Dec 08 10:37:42 query failed : admin.$cmd { replSetReconfig: { _id: "neu", version: 4, members: [ { _id: 0, host: "ZJNO9LZF6G8LBPS:1111" }, { _id: 1, host: "ZJNO9LZF6G8LBPS:2222" }, { _id: 2, host: "ZJNO9LZF6G8LBPS:9999", arbiterOnly: true }, { _id: 3.0, host: "ZJNO9LZF6G8LBPS:3333" } ] } } to: 127.0.0.1:2222

shell got exception during reconfig: Error: error doing query: failed

in some circumstances, the primary steps down and closes connections on a reconfig

null

Sat Dec 08 10:37:42 trying reconnect to 127.0.0.1:2222

Sat Dec 08 10:37:42 reconnect 127.0.0.1:2222 ok

4. 查看当前状态

rs.status()

新成员初始状态为"stateStr" : "(not reachable/healthy)",然后变成"stateStr" : "STARTUP2",然后变成"stateStr" : "RECOVERING",最后当数据同步成功后,状态变为"stateStr" : "SECONDARY"。

5. 副本集最新状态

neu:PRIMARY>  rs.conf()

{

        "_id" : "neu",

        "version" : 4,

        "members" : [

                {

                        "_id" : 0,

                        "host" : "ZJNO9LZF6G8LBPS:1111"

                },

                {

                        "_id" : 1,

                        "host" : "ZJNO9LZF6G8LBPS:2222"

                },

                {

                        "_id" : 2,

                        "host" : "ZJNO9LZF6G8LBPS:9999",

                        "arbiterOnly" : true

                },

                {

                        "_id" : 3,

                        "host" : "ZJNO9LZF6G8LBPS:3333"

                }

        ]

}

neu:PRIMARY> rs.status()

{

        "set" : "neu",

        "date" : ISODate("2012-12-08T02:45:15Z"),

        "myState" : 1,

        "members" : [

                {

                        "_id" : 0,

                        "name" : "ZJNO9LZF6G8LBPS:1111",

                        "health" : 1,

                        "state" : 2,

                        "stateStr" : "SECONDARY",

                        "uptime" : 451,

                        "optime" : {

                                "t" : 1354934262000,

                                "i" : 1

                        },

                        "optimeDate" : ISODate("2012-12-08T02:37:42Z"),

                        "lastHeartbeat" : ISODate("2012-12-08T02:45:14Z")

                },

                {

                        "_id" : 1,

                        "name" : "ZJNO9LZF6G8LBPS:2222",

                        "health" : 1,

                        "state" : 1,

                        "stateStr" : "PRIMARY",

                        "optime" : {

                                "t" : 1354934262000,

                                "i" : 1

                        },

                        "optimeDate" : ISODate("2012-12-08T02:37:42Z"),

                        "self" : true

                },

                {

                        "_id" : 2,

                        "name" : "ZJNO9LZF6G8LBPS:9999",

                        "health" : 1,

                        "state" : 7,

                        "stateStr" : "ARBITER",

                        "uptime" : 451,

                        "optime" : {

                                "t" : 0,

                                "i" : 0

                        },

                        "optimeDate" : ISODate("1970-01-01T00:00:00Z"),

                        "lastHeartbeat" : ISODate("2012-12-08T02:45:14Z")

                },

                {

                        "_id" : 3,

                        "name" : "ZJNO9LZF6G8LBPS:3333",

                        "health" : 1,

                        "state" : 2,

                        "stateStr" : "SECONDARY",

                        "uptime" : 445,

                        "optime" : {

                                "t" : 1354934262000,

                                "i" : 1

                        },

                        "optimeDate" : ISODate("2012-12-08T02:37:42Z"),

                        "lastHeartbeat" : ISODate("2012-12-08T02:45:14Z")

                }

        ],

        "ok" : 1

}

————————————————

原文链接:https://blog.csdn.net/Steven_liwen/article/details/54930626

你可能感兴趣的:(【二】mongo副本集添加新成员)