MongoDB副本集故障测试和解决方案

一、环境

1$ cat /etc/redhat-release  2CentOS Linux release 7.0.1406 (Core)  3$ uname -a 4Linux zhaopin-2-201 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux 5$ mongo 6MongoDB shell version: 3.0.6 7connecting to: test 8rs0:PRIMARY> rs.status(); 9{ 10        "set" : "rs0", 11        "date" : ISODate("2015-09-28T07:00:05.507Z"), 12        "myState" : 1, 13        "members" : [  14                { 15                        "_id" : 0, 16                        "name" : "172.30.2.201:27017", 17                        "health" : 1, 18                        "state" : 1, 19                        "stateStr" : "PRIMARY", 20                        "uptime" : 83,  21                        "optime" : Timestamp(1443423600, 1),  22                        "optimeDate" : ISODate("2015-09-28T07:00:00Z"), 23                        "electionTime" : Timestamp(1443423535, 2),  24                        "electionDate" : ISODate("2015-09-28T06:58:55Z"), 25                        "configVersion" : 3, 26                        "self" : true 27                }, 28                { 29                        "_id" : 1, 30                        "name" : "172.30.2.203:27017", 31                        "health" : 1, 32                        "state" : 2, 33                        "stateStr" : "SECONDARY", 34                        "uptime" : 44,  35                        "optime" : Timestamp(1443423600, 1),  36                        "optimeDate" : ISODate("2015-09-28T07:00:00Z"), 37                        "lastHeartbeat" : ISODate("2015-09-28T07:00:04.918Z"), 38                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:00:05.042Z"), 39                        "pingMs" : 0, 40                        "syncingTo" : "172.30.2.201:27017", 41                        "configVersion" : 3  42                }, 43                { 44                        "_id" : 2, 45                        "name" : "172.30.2.202:27017", 46                        "health" : 1, 47                        "state" : 5, 48                        "stateStr" : "STARTUP2", 49                        "uptime" : 4, 50                        "optime" : Timestamp(0, 0),  51                        "optimeDate" : ISODate("1970-01-01T00:00:00Z"), 52                        "lastHeartbeat" : ISODate("2015-09-28T07:00:04.918Z"), 53                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:00:04.926Z"), 54                        "pingMs" : 0, 55                        "configVersion" : 3  56                } 57        ], 58        "ok" : 1  59}

二、单节点故障

1.primary节点故障

1)关闭primay节点

1rs0:PRIMARY> use admin; 2switched to db admin 3rs0:PRIMARY> db.shutdownServer(); 42015-09-28T15:00:51.828+0800 I NETWORK  DBClientCursor::init call() failed 5server should be down... 62015-09-28T15:00:51.830+0800 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed 72015-09-28T15:00:51.831+0800 I NETWORK  reconnect 127.0.0.1:27017 (127.0.0.1) ok 82015-09-28T15:00:51.831+0800 I NETWORK  DBClientCursor::init call() failed 9> 10bye

2)查看集群状态

1$ mongo 2MongoDB shell version: 3.0.6 3connecting to: test 4rs0:SECONDARY> rs.status(); 5{ 6        "set" : "rs0", 7        "date" : ISODate("2015-09-28T07:01:28.818Z"), 8        "myState" : 2, 9        "members" : [ 10                { 11                        "_id" : 0, 12                        "name" : "172.30.2.201:27017", 13                        "health" : 0, 14                        "state" : 8, 15                        "stateStr" : "(not reachable/healthy)", 16                        "uptime" : 0, 17                        "optime" : Timestamp(0, 0), 18                        "optimeDate" : ISODate("1970-01-01T00:00:00Z"), 19                        "lastHeartbeat" : ISODate("2015-09-28T07:01:27.006Z"), 20                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:00:50.935Z"), 21                        "pingMs" : 0, 22                        "lastHeartbeatMessage" : "Failed attempt to connect to 172.30.2.201:27017; couldn't connect to server 172.30.2.201:27017 (172.30.2.201), connection attempt failed", 23                        "configVersion" : -1 24                }, 25                { 26                        "_id" : 1, 27                        "name" : "172.30.2.203:27017", 28                        "health" : 1, 29                        "state" : 1, 30                        "stateStr" : "PRIMARY", 31                        "uptime" : 87, 32                        "optime" : Timestamp(1443423600, 1), 33                        "optimeDate" : ISODate("2015-09-28T07:00:00Z"), 34                        "lastHeartbeat" : ISODate("2015-09-28T07:01:26.963Z"), 35                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:01:27.078Z"), 36                        "pingMs" : 0, 37                        "electionTime" : Timestamp(1443423653, 1), 38                        "electionDate" : ISODate("2015-09-28T07:00:53Z"), 39                        "configVersion" : 3 40                }, 41                { 42                        "_id" : 2, 43                        "name" : "172.30.2.202:27017", 44                        "health" : 1, 45                        "state" : 2, 46                        "stateStr" : "SECONDARY", 47                        "uptime" : 90, 48                        "optime" : Timestamp(1443423600, 1), 49                        "optimeDate" : ISODate("2015-09-28T07:00:00Z"), 50                        "configVersion" : 3, 51                        "self" : true 52                } 53        ], 54        "ok" : 1 55}

发现集群进行了自动切换,把172.30.2.202:27017变为了primary

3)启动原来的primary

1$ sudo /opt/mongodb/bin/mongod --config /data/mongodb/conf/db0/mongodb.conf 2about to fork child process, waiting until server is ready for connections. 3forked process: 25738 4child process started successfully, parent exiting 5$ mongo 6MongoDB shell version: 3.0.6 7connecting to: test 8rs0:PRIMARY> rs.status(); 9{ 10        "set" : "rs0", 11        "date" : ISODate("2015-09-28T07:02:24.312Z"), 12        "myState" : 1, 13        "members" : [ 14                { 15                        "_id" : 0, 16                        "name" : "172.30.2.201:27017", 17                        "health" : 1, 18                        "state" : 2, 19                        "stateStr" : "SECONDARY", 20                        "uptime" : 13, 21                        "optime" : Timestamp(1443423600, 1), 22                        "optimeDate" : ISODate("2015-09-28T07:00:00Z"), 23                        "lastHeartbeat" : ISODate("2015-09-28T07:02:23.189Z"), 24                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:02:22.873Z"), 25                        "pingMs" : 0, 26                        "configVersion" : 3 27                }, 28                { 29                        "_id" : 1, 30                        "name" : "172.30.2.203:27017", 31                        "health" : 1, 32                        "state" : 1, 33                        "stateStr" : "PRIMARY", 34                        "uptime" : 185, 35                        "optime" : Timestamp(1443423600, 1), 36                        "optimeDate" : ISODate("2015-09-28T07:00:00Z"), 37                        "electionTime" : Timestamp(1443423653, 1), 38                        "electionDate" : ISODate("2015-09-28T07:00:53Z"), 39                        "configVersion" : 3, 40                        "self" : true 41                }, 42                { 43                        "_id" : 2, 44                        "name" : "172.30.2.202:27017", 45                        "health" : 1, 46                        "state" : 2, 47                        "stateStr" : "SECONDARY", 48                        "uptime" : 143, 49                        "optime" : Timestamp(1443423600, 1), 50                        "optimeDate" : ISODate("2015-09-28T07:00:00Z"), 51                        "lastHeartbeat" : ISODate("2015-09-28T07:02:23.103Z"), 52                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:02:22.990Z"), 53                        "pingMs" : 0, 54                        "configVersion" : 3 55                } 56        ], 57        "ok" : 1 58}

发现原来的primary自动切为了secondary

2.secondary节点故障

1)关闭secondary节点

1$ mongo 2MongoDB shell version: 3.0.6 3connecting to: test 4rs0:SECONDARY> use admin; 5switched to db admin 6rs0:SECONDARY> db.shutdownServer(); 72015-09-28T15:04:39.064+0800 I NETWORK  DBClientCursor::init call() failed 8server should be down... 92015-09-28T15:04:39.066+0800 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed 102015-09-28T15:04:39.067+0800 W NETWORK  Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused 112015-09-28T15:04:39.067+0800 I NETWORK  reconnect 127.0.0.1:27017 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed 122015-09-28T15:04:39.070+0800 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed 132015-09-28T15:04:39.070+0800 W NETWORK  Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused 142015-09-28T15:04:39.070+0800 I NETWORK  reconnect 127.0.0.1:27017 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed 15> 16bye

2)查看集群状态

1$ mongo 2MongoDB shell version: 3.0.6 3connecting to: test 4rs0:PRIMARY> rs.status(); 5{ 6        "set" : "rs0", 7        "date" : ISODate("2015-09-28T07:05:12.140Z"), 8        "myState" : 1, 9        "members" : [ 10                { 11                        "_id" : 0, 12                        "name" : "172.30.2.201:27017", 13                        "health" : 1, 14                        "state" : 2, 15                        "stateStr" : "SECONDARY", 16                        "uptime" : 180, 17                        "optime" : Timestamp(1443423600, 1), 18                        "optimeDate" : ISODate("2015-09-28T07:00:00Z"), 19                        "lastHeartbeat" : ISODate("2015-09-28T07:05:11.265Z"), 20                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:05:10.951Z"), 21                        "pingMs" : 0, 22                        "configVersion" : 3 23                }, 24                { 25                        "_id" : 1, 26                        "name" : "172.30.2.203:27017", 27                        "health" : 1, 28                        "state" : 1, 29                        "stateStr" : "PRIMARY", 30                        "uptime" : 353, 31                        "optime" : Timestamp(1443423600, 1), 32                        "optimeDate" : ISODate("2015-09-28T07:00:00Z"), 33                        "electionTime" : Timestamp(1443423653, 1), 34                        "electionDate" : ISODate("2015-09-28T07:00:53Z"), 35                        "configVersion" : 3, 36                        "self" : true 37                }, 38                { 39                        "_id" : 2, 40                        "name" : "172.30.2.202:27017", 41                        "health" : 0, 42                        "state" : 8, 43                        "stateStr" : "(not reachable/healthy)", 44                        "uptime" : 0, 45                        "optime" : Timestamp(0, 0), 46                        "optimeDate" : ISODate("1970-01-01T00:00:00Z"), 47                        "lastHeartbeat" : ISODate("2015-09-28T07:05:11.226Z"), 48                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:04:37.055Z"), 49                        "pingMs" : 0, 50                        "lastHeartbeatMessage" : "Failed attempt to connect to 172.30.2.202:27017; couldn't connect to server 172.30.2.202:27017 (172.30.2.202), connection attempt failed", 51                        "configVersion" : -1 52                } 53        ], 54        "ok" : 1 55}

可见单个secondary节点故障对集群没有影响

3)再启动secondary

1$ sudo /opt/mongodb/bin/mongod --config /data/mongodb/conf/db0/mongodb.conf 2about to fork child process, waiting until server is ready for connections. 3forked process: 49507 4child process started successfully, parent exiting 5$ mongo 6MongoDB shell version: 3.0.6 7connecting to: test 8rs0:SECONDARY> rs.status(); 9{ 10        "set" : "rs0", 11        "date" : ISODate("2015-09-28T07:06:41.733Z"), 12        "myState" : 2, 13        "members" : [ 14                { 15                        "_id" : 0, 16                        "name" : "172.30.2.201:27017", 17                        "health" : 1, 18                        "state" : 2, 19                        "stateStr" : "SECONDARY", 20                        "uptime" : 12, 21                        "optime" : Timestamp(1443423600, 1), 22                        "optimeDate" : ISODate("2015-09-28T07:00:00Z"), 23                        "lastHeartbeat" : ISODate("2015-09-28T07:06:40.999Z"), 24                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:06:41.233Z"), 25                        "pingMs" : 0, 26                        "lastHeartbeatMessage" : "could not find member to sync from", 27                        "configVersion" : 3 28                }, 29                { 30                        "_id" : 1, 31                        "name" : "172.30.2.203:27017", 32                        "health" : 1, 33                        "state" : 1, 34                        "stateStr" : "PRIMARY", 35                        "uptime" : 12, 36                        "optime" : Timestamp(1443423600, 1), 37                        "optimeDate" : ISODate("2015-09-28T07:00:00Z"), 38                        "lastHeartbeat" : ISODate("2015-09-28T07:06:40.999Z"), 39                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:06:41.360Z"), 40                        "pingMs" : 0, 41                        "electionTime" : Timestamp(1443423653, 1), 42                        "electionDate" : ISODate("2015-09-28T07:00:53Z"), 43                        "configVersion" : 3 44                }, 45                { 46                        "_id" : 2, 47                        "name" : "172.30.2.202:27017", 48                        "health" : 1, 49                        "state" : 2, 50                        "stateStr" : "SECONDARY", 51                        "uptime" : 13, 52                        "optime" : Timestamp(1443423600, 1), 53                        "optimeDate" : ISODate("2015-09-28T07:00:00Z"), 54                        "configVersion" : 3, 55                        "self" : true 56                } 57        ], 58        "ok" : 1 59}

重新启动后又重新连上了集群

三、多节点故障

1.primary和secondary节点同时故障

1)停掉一个secondary节点

1$ mongo 2MongoDB shell version: 3.0.6 3connecting to: test 4rs0:SECONDARY> use admin; 5switched to db admin 6rs0:SECONDARY> db.shutdownServer(); 72015-09-28T15:10:43.049+0800 I NETWORK  DBClientCursor::init call() failed 8server should be down... 92015-09-28T15:10:43.051+0800 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed 102015-09-28T15:10:43.052+0800 W NETWORK  Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused 112015-09-28T15:10:43.052+0800 I NETWORK  reconnect 127.0.0.1:27017 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed 122015-09-28T15:10:43.055+0800 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed 132015-09-28T15:10:43.055+0800 W NETWORK  Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused 142015-09-28T15:10:43.055+0800 I NETWORK  reconnect 127.0.0.1:27017 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed

2)停掉primary节点

$ mongoMongoDB shell version: 3.0.6connecting to: testrs0:PRIMARY> use admin;switched to db adminrs0:PRIMARY> db.shutdownServer();2015-09-28T15:10:53.069+0800 I NETWORK  DBClientCursor::init call() failedserver should be down...2015-09-28T15:10:53.072+0800 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed2015-09-28T15:10:53.073+0800 I NETWORK  reconnect 127.0.0.1:27017 (127.0.0.1) ok2015-09-28T15:10:53.073+0800 I NETWORK  DBClientCursor::init call() failed2015-09-28T15:10:53.076+0800 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed2015-09-28T15:10:53.076+0800 I NETWORK  reconnect 127.0.0.1:27017 (127.0.0.1) ok2015-09-28T15:10:53.888+0800 I NETWORK  Socket recv() errno:104 Connection reset by peer 127.0.0.1:270172015-09-28T15:10:53.888+0800 I NETWORK  SocketException: remote: 127.0.0.1:27017 error: 9001 socket exception [RECV_ERROR] server [127.0.0.1:27017]2015-09-28T15:10:53.888+0800 I NETWORK  DBClientCursor::init call() failed

3)查看集群状态

1$ mongo 2MongoDB shell version: 3.0.6 3connecting to: test 4rs0:SECONDARY> rs.status(); 5{ 6        "set" : "rs0", 7        "date" : ISODate("2015-09-28T07:12:10.946Z"), 8        "myState" : 2, 9        "members" : [ 10                { 11                        "_id" : 0, 12                        "name" : "172.30.2.201:27017", 13                        "health" : 1, 14                        "state" : 2, 15                        "stateStr" : "SECONDARY", 16                        "uptime" : 600, 17                        "optime" : Timestamp(1443423600, 1), 18                        "optimeDate" : ISODate("2015-09-28T07:00:00Z"), 19                        "configVersion" : 3, 20                        "self" : true 21                }, 22                { 23                        "_id" : 1, 24                        "name" : "172.30.2.203:27017", 25                        "health" : 0, 26                        "state" : 8, 27                        "stateStr" : "(not reachable/healthy)", 28                        "uptime" : 0, 29                        "optime" : Timestamp(0, 0), 30                        "optimeDate" : ISODate("1970-01-01T00:00:00Z"), 31                        "lastHeartbeat" : ISODate("2015-09-28T07:12:10.008Z"), 32                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:10:51.422Z"), 33                        "pingMs" : 0, 34                        "lastHeartbeatMessage" : "Failed attempt to connect to 172.30.2.203:27017; couldn't connect to server 172.30.2.203:27017 (172.30.2.203), connection attempt failed", 35                        "configVersion" : -1 36                }, 37                { 38                        "_id" : 2, 39                        "name" : "172.30.2.202:27017", 40                        "health" : 0, 41                        "state" : 8, 42                        "stateStr" : "(not reachable/healthy)", 43                        "uptime" : 0, 44                        "optime" : Timestamp(0, 0), 45                        "optimeDate" : ISODate("1970-01-01T00:00:00Z"), 46                        "lastHeartbeat" : ISODate("2015-09-28T07:12:09.477Z"), 47                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:10:41.112Z"), 48                        "pingMs" : 0, 49                        "lastHeartbeatMessage" : "Failed attempt to connect to 172.30.2.202:27017; couldn't connect to server 172.30.2.202:27017 (172.30.2.202), connection attempt failed", 50                        "configVersion" : -1 51                } 52        ], 53        "ok" : 1 54}

只剩下一个secondary节点,集群变得不可用了

4)解决方案

重新配置:

1rs0:SECONDARY> cfg={_id:"rs0", members:[ {_id:0,host:"172.30.2.201:27017"}] } 2{ 3        "_id" : "rs0", 4        "members" : [ 5                { 6                        "_id" : 0, 7                        "host" : "172.30.2.201:27017" 8                } 9        ] 10} 11rs0:SECONDARY> rs.reconfig(cfg, {force:true}); 12{ "ok" : 1 } 13rs0:PRIMARY> rs.status(); 14{ 15        "set" : "rs0", 16        "date" : ISODate("2015-09-28T07:14:09.350Z"), 17        "myState" : 1, 18        "members" : [ 19                { 20                        "_id" : 0, 21                        "name" : "172.30.2.201:27017", 22                        "health" : 1, 23                        "state" : 1, 24                        "stateStr" : "PRIMARY", 25                        "uptime" : 719, 26                        "optime" : Timestamp(1443423600, 1), 27                        "optimeDate" : ISODate("2015-09-28T07:00:00Z"), 28                        "electionTime" : Timestamp(1443424428, 1), 29                        "electionDate" : ISODate("2015-09-28T07:13:48Z"), 30                        "configVersion" : 71840, 31                        "self" : true 32                } 33        ], 34        "ok" : 1 35}

此时就变成了单primary节点,可以提供读写服务,然后再制作secondary节点

2.两个secondary节点故障

1)故障前状态

1rs0:PRIMARY> rs.status(); 2{ 3        "set" : "rs0", 4        "date" : ISODate("2015-09-28T07:16:06.571Z"), 5        "myState" : 1, 6        "members" : [ 7                { 8                        "_id" : 0, 9                        "name" : "172.30.2.201:27017", 10                        "health" : 1, 11                        "state" : 1, 12                        "stateStr" : "PRIMARY", 13                        "uptime" : 836, 14                        "optime" : Timestamp(1443424538, 1), 15                        "optimeDate" : ISODate("2015-09-28T07:15:38Z"), 16                        "electionTime" : Timestamp(1443424534, 1), 17                        "electionDate" : ISODate("2015-09-28T07:15:34Z"), 18                        "configVersion" : 71842, 19                        "self" : true 20                }, 21                { 22                        "_id" : 1, 23                        "name" : "172.30.2.202:27017", 24                        "health" : 1, 25                        "state" : 2, 26                        "stateStr" : "SECONDARY", 27                        "uptime" : 31, 28                        "optime" : Timestamp(1443424538, 1), 29                        "optimeDate" : ISODate("2015-09-28T07:15:38Z"), 30                        "lastHeartbeat" : ISODate("2015-09-28T07:16:06.230Z"), 31                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:16:06.089Z"), 32                        "pingMs" : 0, 33                        "configVersion" : 71842 34                }, 35                { 36                        "_id" : 2, 37                        "name" : "172.30.2.203:27017", 38                        "health" : 1, 39                        "state" : 2, 40                        "stateStr" : "SECONDARY", 41                        "uptime" : 26, 42                        "optime" : Timestamp(1443424538, 1), 43                        "optimeDate" : ISODate("2015-09-28T07:15:38Z"), 44                        "lastHeartbeat" : ISODate("2015-09-28T07:16:06.229Z"), 45                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:16:06.233Z"), 46                        "pingMs" : 0, 47                        "configVersion" : 71842 48                } 49        ], 50        "ok" : 1 51}

2)停掉两个secondary节点

在两个secondary节点分别执行:

1$ mongo 2MongoDB shell version: 3.0.6 3connecting to: test 4rs0:SECONDARY> use admin; 5switched to db admin 6rs0:SECONDARY> db.shutdownServer(); 72015-09-28T15:18:11.114+0800 I NETWORK  DBClientCursor::init call() failed 8server should be down... 92015-09-28T15:18:11.117+0800 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed 102015-09-28T15:18:11.118+0800 W NETWORK  Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused 112015-09-28T15:18:11.118+0800 I NETWORK  reconnect 127.0.0.1:27017 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed 122015-09-28T15:18:11.121+0800 I NETWORK  trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed 132015-09-28T15:18:11.121+0800 W NETWORK  Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused 142015-09-28T15:18:11.121+0800 I NETWORK  reconnect 127.0.0.1:27017 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed 15> 16bye

3)查看集群状态

1rs0:SECONDARY> rs.status(); 2{ 3        "set" : "rs0", 4        "date" : ISODate("2015-09-28T07:19:09.196Z"), 5        "myState" : 2, 6        "members" : [ 7                { 8                        "_id" : 0, 9                        "name" : "172.30.2.201:27017", 10                        "health" : 1, 11                        "state" : 2, 12                        "stateStr" : "SECONDARY", 13                        "uptime" : 1019, 14                        "optime" : Timestamp(1443424538, 1), 15                        "optimeDate" : ISODate("2015-09-28T07:15:38Z"), 16                        "configVersion" : 71842, 17                        "self" : true 18                }, 19                { 20                        "_id" : 1, 21                        "name" : "172.30.2.202:27017", 22                        "health" : 0, 23                        "state" : 8, 24                        "stateStr" : "(not reachable/healthy)", 25                        "uptime" : 0, 26                        "optime" : Timestamp(0, 0), 27                        "optimeDate" : ISODate("1970-01-01T00:00:00Z"), 28                        "lastHeartbeat" : ISODate("2015-09-28T07:19:08.371Z"), 29                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:18:10.147Z"), 30                        "pingMs" : 0, 31                        "lastHeartbeatMessage" : "Failed attempt to connect to 172.30.2.202:27017; couldn't connect to server 172.30.2.202:27017 (172.30.2.202), connection attempt failed", 32                        "configVersion" : -1 33                }, 34                { 35                        "_id" : 2, 36                        "name" : "172.30.2.203:27017", 37                        "health" : 0, 38                        "state" : 8, 39                        "stateStr" : "(not reachable/healthy)", 40                        "uptime" : 0, 41                        "optime" : Timestamp(0, 0), 42                        "optimeDate" : ISODate("1970-01-01T00:00:00Z"), 43                        "lastHeartbeat" : ISODate("2015-09-28T07:19:08.350Z"), 44                        "lastHeartbeatRecv" : ISODate("2015-09-28T07:18:34.298Z"), 45                        "pingMs" : 0, 46                        "lastHeartbeatMessage" : "Failed attempt to connect to 172.30.2.203:27017; couldn't connect to server 172.30.2.203:27017 (172.30.2.203), connection attempt failed", 47                        "configVersion" : -1 48                } 49        ], 50        "ok" : 1 51}

可见剩下的primary节点自动变为了secondary节点,集群变得不可用了

4)解决方案

1rs0:SECONDARY> cfg={_id:"rs0", members:[ {_id:0,host:"172.30.2.201:27017"}] } 2{ 3        "_id" : "rs0", 4        "members" : [ 5                { 6                        "_id" : 0, 7                        "host" : "172.30.2.201:27017" 8                } 9        ] 10} 11rs0:SECONDARY> rs.reconfig(cfg, {force:true}); 12{ "ok" : 1 } 13rs0:PRIMARY> rs.status(); 14{ 15        "set" : "rs0", 16        "date" : ISODate("2015-09-28T07:20:08.099Z"), 17        "myState" : 1, 18        "members" : [ 19                { 20                        "_id" : 0, 21                        "name" : "172.30.2.201:27017", 22                        "health" : 1, 23                        "state" : 1, 24                        "stateStr" : "PRIMARY", 25                        "uptime" : 1078, 26                        "optime" : Timestamp(1443424538, 1), 27                        "optimeDate" : ISODate("2015-09-28T07:15:38Z"), 28                        "electionTime" : Timestamp(1443424795, 1), 29                        "electionDate" : ISODate("2015-09-28T07:19:55Z"), 30                        "configVersion" : 127342, 31                        "self" : true 32                } 33        ], 34        "ok" : 1 35}

处理方法和上面的相同,也是强制将剩下的secondary节点配置为单primary节点

四、结论

1. 三节点的副本集集群,任何一台故障,集群都会进行自动切换,不影响服务
2. 三节点的副本集集群,故障任何两个节点,集群就会变的不可用,需要手动处理
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )

List的Select 和Select().tolist()

List<PersondelpnewList<Person{newPerson{Id1,Name"小明1",Age11,Sign0},newPerson{Id2,Name"小明2",Age12,

MongoDB副本集故障测试和解决方案 - HelloWorld