MongoDB replica set maintenance

Source: Internet
Author: User

Reprinted from http://www.cnblogs.com/spnt/

After the MongoDB replica set is configured, maintenance is indispensable and the maintenance content is not much, mainly because of the current status and Addition and deletion of nodes.

 

Before maintenance, let's talk about the synchronization mechanism of the MongoDB replica set.

The purpose of data replication is to maximize data availability and prevent the whole site from being inaccessible due to spof. MongoDB replica sets can be written by only one server at a time, the master-slave replication of the replica set is also an asynchronous synchronization process. The slave side obtains logs from the primary side, then perform the operations recorded in the log in full order on the user (this log does not record the query operations). This log is the oplog in the local database. RS table, which is relatively large on 64-bit machines by default, accounting for 5% of the disk size, oplog. the RS size can be set in the startup parameter -- oplogsize 1000, in MB.

We recommend that you set this value to a greater value in the production environment to prevent synchronization failures.

 

Now officially speaking about maintenance commands

1. view the synchronization status

Run dB. printslavereplicationinfo () to view the slave latency.

Source: slave database IP address and port

Syncedto: Current synchronization status and the last synchronization time

It can be seen from the above that when the database content remains unchanged, it is not synchronized, and the database changes will be synchronized immediately.

2. add or delete nodes

1. Add nodes

MongoDB can seamlessly add nodes without stopping services. The command is also very simple and can be completed in two steps.

1. Start a new MongoDB instance and specify the replica set.

2. Add the replica set to the "string"

Start a new process. I use the mongodb4 directory, port 4444, and then run the Add command.

Command Format: Rs. Add ("IP + port number ")

Note: This command can only be used in the master database. You can see that I have reconnected to the master database with the port number 3333.

Then check the status

We can see that 4444 has been added as a slave database to the replica set.

You can also find that there is an extra attribute: statestr and errmsg, which indicate the current synchronization status and progress.

Statestr: Recovering // indicates that the data is being synchronized,

Secondary // indicates that the synchronization is successful and can be used properly.

2. delete a node

For various reasons, I want to delete a node and leave the server idle.

Then run the Rs. Remove ("IP + port") command to remove the node.

Now I have removed the 4444 node that I just added.

4444 has been deleted.

The basic maintenance of replica sets is so much that it can meet most of the requirements.

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.