MongoDB deployment experiment series of articles, MongoDB as a NoSQL Database, has continued to heat up in recent years, more and more enterprises are trying to replace the original Database with MongoDB
MongoDB deployment experiment series of articles, MongoDB as a NoSQL Database, has continued to heat up in recent years, more and more enterprises are trying to replace the original Database with MongoDB
MongoDB has been widely used as a NoSQL Database in recent years. More and more enterprises are trying to use MongoDB instead of the original Database. MongoDB also performs well in clusters, sharding, and replication. I will introduce various MongoDB deployment experiments.
Article 2 MongoDB Replica Set automatic replication of Replica Set, which consists of seven parts
1. initialize the file directory
2. Start the Replica Set
3. Failed to simulate PRIMARY and SECONDARY Automatic Switch
4. Repair failed nodes
5. Restore failed nodes and add them to SECONDARY
6. delete a Replica Set Node
7. Add a new Replica Set Node
System Environment Introduction:
Ubuntu 12.04. LTS 64bit Server
Initialize the file directory
~ Pwd
/Home/conan/dbs
~ Mkdir node1 node2 node3
~ Ls-l
Drwxrwxr-x 2 conan 4096 May 31 14:21 node1
Drwxrwxr-x 2 conan 4096 May 31 14:21 node2
Drwxrwxr-x 2 conan 4096 May 31 14:21 node3
Start Replica Set
Start node1, node2, node3
Mongod -- dbpath/home/conan/dbs/node1 -- port 10001 -- replSet blort -- nojournal -- fork -- logpath/home/conan/dbs/node1.log
Mongod -- dbpath/home/conan/dbs/node2 -- port 10002 -- replSet blort -- nojournal -- fork -- logpath/home/conan/dbs/node2.log
Mongod -- dbpath/home/conan/dbs/node3 -- port 10003 -- replSet blort -- nojournal -- fork -- logpath/home/conan/dbs/node3.log
Replica set Initialization
~ Mongo localhost: 10001
MongoDB shell version: 2.4.3
Connecting to: localhost: 10001/test
> Rs. initiate ({_ id: "blort", members :[
{_ Id: 1, host: "localhost: 10001 "},
{_ Id: 2, host: "localhost: 10002 "},
{_ Id: 3, host: "localhost: 10003 "},
]})
{
"Info": "Config now saved locally. shocould come online in about a minute .",
"OK": 1
}
View log information: node1 is changed to PRIMARY, node2, and node3 are two SECONDARY
Fri May 31 14:26:44. 728 [conn2] ******
Fri May 31 14:26:44. 728 [conn2] replSet info saving a newer config version to local. system. replset
Fri May 31 14:26:44. 741 [conn2] replSet saveConfigLocally done
Fri May 31 14:26:44. 741 [conn2] replSet replSetInitiate config now saved locally. shocould come online in about a minute.
Fri May 31 14:26:44. 741 [conn2] command admin. $ cmd command: {replSetInitiate: {_ id: "blort", members: [{_ id: 1.0, host: "localhost: 10001"}, {_ id: 2.0, host: "localhost: 10002"}, {_ id: 3.0, host: "localhost: 10003"}]} ntoreturn: 1 keyUpdates: 0 locks (micros) W: 646741 reslen: 112 652 ms
Fri May 31 14:26:53. 682 [rsStart] replSet I am localhost: 10001
Fri May 31 14:26:53. 682 [rsStart] replSet STARTUP2
Fri May 31 14:26:53. 683 [rsHealthPoll] replSet member localhost: 10002 is up
Fri May 31 14:26:53. 684 [rsHealthPoll] replSet member localhost: 10003 is up
Fri May 31 14:26:54. 285 [initandlisten] connection accepted from 127.0.0.1: 46469 #3 (3 connections now open)
Fri May 31 14:26:54. 683 [rsSync] replSet SECONDARY
Use the mongo client to view settings
Node1 connection
~ Mongo localhost: 10001
MongoDB shell version: 2.4.3
Connecting to: localhost: 10001/test
Blort: PRIMARY> rs. status ()
{
"Set": "blort ",
"Date": ISODate ("2013-05-31T06: 34: 12Z "),
"MyState": 1,
"Members ":[
{
"_ Id": 1,
"Name": "localhost: 10001 ",
"Health": 1,
"State": 1,
"StateStr": "PRIMARY ",
"Uptime": 659,
"Optime ":{
"T": 1369981604,
"I": 1
},
"OptimeDate": ISODate ("2013-05-31T06: 26: 44Z "),
"Self": true
},
{
"_ Id": 2,
"Name": "localhost: 10002 ",
"Health": 1,
"State": 2,
"StateStr": "SECONDARY ",
"Uptime": 439,
"Optime ":{
"T": 1369981604,
"I": 1
},
"OptimeDate": ISODate ("2013-05-31T06: 26: 44Z "),
"LastHeartbeat": ISODate ("2013-05-31T06: 34: 11Z "),
"LastHeartbeatRecv": ISODate ("1970-01-01T00: 00: 00Z "),
"PingMs": 0,
"SyncingTo": "localhost: 10001"
},
{
"_ Id": 3,
"Name": "localhost: 10003 ",
"Health": 1,
"State": 2,
"StateStr": "SECONDARY ",
"Uptime": 439,
"Optime ":{
"T": 1369981604,
"I": 1
},
"OptimeDate": ISODate ("2013-05-31T06: 26: 44Z "),
"LastHeartbeat": ISODate ("2013-05-31T06: 34: 11Z "),
"LastHeartbeatRecv": ISODate ("1970-01-01T00: 00: 00Z "),
"PingMs": 0,
"SyncingTo": "localhost: 10001"
}
],
"OK": 1
}