MongoDB replica Set Primary-Secondary switchover Experiment

Source: Internet
Author: User

MongoDB replica Set Primary-Secondary switchover Experiment

1. Create a directory for the replica Section

[Root @ bakdbserver ~] # Mkdir-p/var/lib/mongo/dbs/node1

[Root @ bakdbserver ~] # Mkdir-p/var/lib/mongo/dbs/node2

[Root @ bakdbserver ~] # Mkdir-p/var/lib/mongo/dbs/node3

2. Start the replica set

Node 1:

[Root @ bakdbserver ~] # Mongod -- dbpath/var/lib/mongo/dbs/node1 -- port 10001 -- nojournal -- replSet blort

 

Node 2 and 3:

Mongod -- dbpath/var/lib/mongo/dbs/node2 -- port 10002 -- nojournal -- replSet blort

Mongod -- dbpath/var/lib/mongo/dbs/node3 -- port 10003 -- nojournal -- replSet blort

3. initialize the replica set

Rs. initiate ({"_ id": "blort", "members ":[

{"_ Id": 1, "host": "bakdbserver: 10001 "},

{"_ Id": 2, "host": "bakdbserver: 10002 "},

{"_ Id": 3, "host": "bakdbserver: 10003 "},

]})

 

Reconnect nodes to view the master and slave roles:

 

You can also run the rs. status () command to view the Master/Slave role status.

 

4. Test Data Replication

Insert data on port 10001 of the master node:

 

View on replica Node

 

The discovery cannot be performed on the replica node to view data, which is different from the Master-Slave replication (Master-Slave) architecture.



5. Simulate master-copy Switch

The current master node is a 10001 port Process

 

Kill the master node process and simulate a master node failure.

[Root @ bakdbserver slave] # kill-9 15940

Log on to a replica Node

 

 

You can see that the master node has been converted to copy 3, that is, port 10003.

Login copy 3 Port 10003:

 

We can see that the data has been synchronized.

5. Restart faulty node 1

Delete data before Node 1

 

Restart

 

View Node 1 Status

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.