Mongo server cluster configuration Learning 1 master-slave Replication

Source: Internet
Author: User
Mongo server cluster configuration Learning 1. Master-slave replication is the most common and simple replication operation for MongoDB. It is often used for data backup and troubleshooting. The following figure shows the simplest server architecture of master-slave replication. I will use an experiment to implement the MongoDB master-slave replication experiment environment: windows operating system (one machine starts multiple Mongo

Mongo server cluster configuration Learning 1. Master-slave replication is the most common and simple replication operation for MongoDB. It is often used for data backup and troubleshooting. The following figure shows the simplest server architecture of master-slave replication. I will use an experiment to implement the MongoDB master-slave replication experiment environment: windows operating system (one machine starts multiple Mongo

Mongo server cluster configuration Learning 1-master-slave Replication

Master-slave replication is the most common and simple replication operation for MongoDB. It is often used for data backup and troubleshooting.

The following figure shows the simplest master-slave replication server architecture.


I will implement MongoDB master-slave replication in an experimental way.
Lab environment: windows OS (one machine starts multiple MongoDB databases), MongoDB 2.4
Note:
1. MongoDB is started as a configuration file
2. Run the saved bat file instead of entering the command in CMD each time.
Steps:
1. Configure and start the master node. The port is 10001, which is the configured file structure.

The content of config. cnf is
Dbpath = D: \ apsaradb for mongodb \ test \ copy \ 10001 \ Data
Bind_ip = 127.0.0.1
Port = 10001
Master = true
Use startup. bat to start the master node: mongod-f config. cnf
Start shell: mongo 127.0.0.1: 10001 with shell. bat
If the master parameter is true, it indicates that this is the master node.
2. Configure slave database, port 10002
The content of config. cnf is
Dbpath = D: \ apsaradb for mongodb \ test \ copy \ 10002 \ Data
Bind_ip = 127.0.0.1
Port = 10002
Slave = true
Source = 127.0.0.1: 10001
Start slave node with startup. bat: mongod-f config. cnf
Start shell: mongo 127.0.0.1: 10002 with shell. bat
Set the slave parameter to the slave node and the source address to the master node of the slave database.
3. perform the following verification: add the set baseinfo to the person database on the master node 10001 and add a document

At this time, we can see that the same data has been copied from the node.

4. Other parameters
-- Only slave node configuration, only copying a specific database
-- Autoresync slave node configuration. If the data of the master node is different from that of the slave node, the slave node is automatically re-synchronized. If you configure this node, you can add a new node to the master node that has been running for a period of time. Then, the new node synchronizes all the data of the previous master node, instead of synchronizing data from the current time.
-- Slavedelay slave node configuration, slave database delay synchronization time of the master database
-- Fastsync slave node configuration, which starts from the node with the database snapshot of the master node, can speed up the startup.
-- Oplogsize: the size of the oplog on the master node. The master node writes the database operation logs in the oplog. You can refer to the oplog on the master node for copying operations to adjust the log size as needed. If you do not specify the oplogsize, mongod will allocate 5% of the available disk space to him. The minimum 32-bit host space is 50 MB, and the minimum 64-bit host space is 1 GB.
Dynamically add and delete Master/Slave nodes
First, let's see where the master node is configured for the slave node. In the sources collection of the local database of the slave node, view the information as follows:

Now start a common node, with no Master/Slave configured and port set to 10003.
Dbpath = D: \ apsaradb for mongodb \ test \ copy \ 10003 \ Data
Bind_ip = 127.0.0.1
Port = 10003
Slave = true
After the startup, dynamically add 10003 to the master-slave architecture to form the following structure:

Execute the following script in shell 10003.
Use local
Db. sources. insert ({"host": "Wagner. 0.0.1: 10001 "})
In this way, 10003 is used as the slave node of 10001.
Delete the master-slave relationship and use db. sources. remove ({"host": "127.0.0.1: 10001 "})

Master node to slave Node
To permanently transfer A corrupted and unavailable master node A to slave Node B, follow these steps:
1. Disable node
2. Stop Mongod on Node B.
3. Back up and move the files in the dbpath directory of Node B.
Note: deleting local. * is irrevocable. Exercise caution when performing this step.
4. Restart Mongod with the -- master parameter on Node B.
Change master and slave nodes
There is A master node A and A slave Node B. If you want to change their roles, perform the following steps. Assume that A is healthy and can be updated and available.
If A is not healthy, but the hardware is good (power failure, server crash, etc.), skip steps 1 and 2 and replace all the files with B in step 2.
If A is healthy, the hardware is poor. replace A with A new machine. You can follow the instructions in the previous section.
1. Pause using the fsync command on
2. Confirm that B is in synchronization node
3. Disable Node B
4. Back up and move all data files from the DBPATH directory of B, and delete the existing data local. sources.
5. Use the master option to start B.
6. Write Data to B and use oplog to set the new synchronization start time.
7. Disable B. B has a new set of local data when it is restarted.
8. Disable A and copy the dbpath directory file of B to dbpath of.
9. Use the master option to start B
10. Start A with the usual slave option, but the fastsync parameter must be included.

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.