-- 1 view the current Replica Set configuration [Mongo @ redhatB mongodb] $ mongo 127.0.0.1: 27018 MongoDB shell version: 2.2.1 Connecting to: 127.0.0.1: 27018/test Rs0: PRIMARY> rs. conf (); { "_ Id": "rs0 ", "Version": 4, "Members ":[ { "_ Id": 0, "Host": "redhatB.example.com: 27018" }, { "_ Id": 1, "Host": "redhatB.example.com: 27019" }, { "_ Id": 2, "Host": "redhatB.example.com: 27020" }, { "_ Id": 3, "Host": "redhatB.example.com: 27021" } ] } Note: "_ id": 3. -- 2 close the 27021 Node Service
[Mongo @ redhatB data04] $ ps-ef | grep 27021 Mongo 11733 1 0? At 00:00:15, mongod-f/pgdata_xc/mongodb/data04/mongodb_27021.conf Mongo 14422 2953 0 00:00:00 pts/0 mongo 127.0.0.1: 27021 Mongo 14490 4027 0 00:00:00 pts/1 grep 27021 [Mongo @ redhatB data04] $ kill 11733 -- 3 view the status of the replica set
Rs0: PRIMARY> rs. status (); { "Set": "rs0 ", "Date": ISODate ("2012-11-22T13: 57: 15Z "), "MyState": 1, "Members ":[ { "_ Id": 0, "Name": "redhatB.example.com: 27018 ", "Health": 1, "State": 1, "StateStr": "PRIMARY ", "Uptime": 21279, "Optime": Timestamp (1353589624000, 1 ), "OptimeDate": ISODate ("2012-11-22T13: 07: 04Z "), "Self": true }, { "_ Id": 1, "Name": "redhatB.example.com: 27019 ", "Health": 1, "State": 2, "StateStr": "SECONDARY ", "Uptime": 18908, "Optime": Timestamp (1353589624000, 1 ), "OptimeDate": ISODate ("2012-11-22T13: 07: 04Z "), "LastHeartbeat": ISODate ("2012-11-22T13: 57: 13Z "), "PingMs": 0 }, { "_ Id": 2, "Name": "redhatB.example.com: 27020 ", "Health": 1, "State": 2, "StateStr": "SECONDARY ", "Uptime": 18900, "Optime": Timestamp (1353589624000, 1 ), "OptimeDate": ISODate ("2012-11-22T13: 07: 04Z "), "LastHeartbeat": ISODate ("2012-11-22T13: 57: 14Z "), "PingMs": 0 }, { "_ Id": 3, "Name": "redhatB.example.com: 27021 ", "Health": 0, "State": 8, "StateStr": "(not reachable/healthy )", "Uptime": 0, "Optime": Timestamp (1353589624000, 1 ), "OptimeDate": ISODate ("2012-11-22T13: 07: 04Z "), "LastHeartbeat": ISODate ("2012-11-22T13: 55: 20Z "), "PingMs": 0, "Errmsg": "socket exception [CONNECT_ERROR] for redhatB.example.com: 27021" } ], "OK": 1 } Note: the status of the last node stateStr is not reachable/healthy ". -- 4 delete a node Rs0: PRIMARY> rs. remove ("redhatB.example.com: 27021 "); Thu Nov 22 21:58:45 DBClientCursor: init call () failed Thu Nov 22 21:58:45 query failed: admin. $ cmd {replSetReconfig: {_ id: "rs0", version: 5, members: [{_ id: 0, host: "redhatB.example.com: 27018"}, {_ id: 1, host: "redhatB.example.com: 27019"}, {_ id: 2, host: "redhatB.example.com: 27020"}]} to: 127.0.0.1: 27018 Thu Nov 22 21:58:45 Error: error doing query: failed src/mongo/shell/collection. js: 155 Thu Nov 22 21:58:45 trying reconnect to 127.0.0.1: 27018 Thu Nov 22 21:58:45 reconnect 127.0.0.1: 27018 OK Rs0: SECONDARY> Rs0: PRIMARY> -- 5 view the replica set configuration again
Rs0: PRIMARY> rs. conf (); { "_ Id": "rs0 ", "Version": 5, "Members ":[ { "_ Id": 0, "Host": "redhatB.example.com: 27018" }, { "_ Id": 1, "Host": "redhatB.example.com: 27019" }, { "_ Id": 2, "Host": "redhatB.example.com: 27020" } ] } |