Master-Slave pairing of MongoDB database with data Migration example

Source: Internet
Author: User

Data center in the operation of a variety of hardware, power, network failures and other problems, need to design a good system to isolate, minimize the impact on the upper application, continue to provide services; if business interruption occurs, it should be resumed as soon as possible. With master-slave backup design, when the main application system fails, the standby machine can take over the application in time and maintain the continuity of the business.


With the following basic application architecture as an example, the database has a single point of vulnerability, you can consider the use of MongoDB to master-slave support features designed to Master-slave deployment, complete the architecture optimization. (MongoDB master-Slave synchronization through the intranet to achieve the best efficiency, if only through the public network for master-slave synchronization, will affect efficiency.) )

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/5C/18/wKiom1UaWY-jEcnhAAHjqqP1tAU345.jpg "title=" 1.png " alt= "Wkiom1uawy-jecnhaahjqqp1tau345.jpg"/>

Can be implemented directly using the MONGODB Image: first open the image of the master, then open the slave mirror, and then run the following script in MongoDB slave for master-slave pairing:


1. Script Storage path:/root/mongo_slave.sh

2. How to configure (run the following command):bash/root/mongo_slave.sh

A) Enter the interactive mode and ask if you want to continue (enter Yes here): This server is master. Do you need change to slave? (yes/no)

b) required to enter the remote master IP address, where you need to fill in the master Intranet Ip:please enter your master IP?

I. Note: When filling in the intranet IP, please determine whether the master-slave image of the intranet interoperability, and master 27017 MongoDB service port is open, otherwise it will lead to master-slave failure. Otherwise, an error message appears: "Error:connect to <IP> 27017 (TCP) Failed:connection refused"

II. NOTE: It is also feasible to enter the public network IP, but the master-slave synchronization to achieve maximum efficiency, the transmission speed of the public network will affect the efficiency of master-slave synchronization.

c) The master root password is required for master/slave configuration:

The authenticity of host ' 121.199.54.209 (121.199.54.209) ' can ' t be established.

RSA key fingerprint is fe:17:21:c7:22:b7:10:90:91:85:76:ed:81:30:b8:7d.

Is you sure want to continue connecting (yes/no)?

Enter Yes, and then enter the root password of the master image.

3. Auto Restart: Enter the correct master root password and the MongoDB will be restarted automatically when the configuration is completed. when the word "slave create successed" appears, the configuration is successful.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/5C/13/wKioL1UaWyqh9LV1AADiS_5nQ4U407.jpg "title=" 2.png " alt= "Wkiol1uawyqh9lv1aadis_5nq4u407.jpg"/>

4. View:Less/alidata/log/mongodb/mongod.log

You can see in the log that the master and slave have started synchronizing

2014-08-04t17:34:33.205+0800 [Replslave] Build Index On:local.me properties: {v:1, key: {_id:1}, Name: "_id_", NS: " Local.me "}

2014-08-04t17:34:33.205+0800 [Replslave] added index to empty collection

2014-08-04t17:34:33.205+0800 [Replslave] Build Index On:local.sources properties: {v:1, key: {_id:1}, Name: "_id_", NS: "Local.sources"}

2014-08-04t17:34:33.206+0800 [Replslave] added index to empty collection

2014-08-04t17:34:33.208+0800 [Replslave] repl:syncing from host:10.171.228.64:27017


5. After the master and slave configuration, from the vault password: When the/root/mongo_slave.sh script is successfully run for master-slave configuration, the password of the primary library is reinitialized once, and the password from the vault is consistent with the password of the main library at this time. The words "and the main library the same password" are seen in the/alidata/account.log from the library.


View MongoDB Master-Slave environment Image:>> main environment << | >> from the Environment <<


————————


Example: Migrating a project to a data disk

If we need to consider migrating the project from the system disk to the data disk, the entire process is referenced as follows:

(A mirrored deployment project typically exists in the/alidata/server/mongodb/data directory of the system disk)

1. Stop MongoDB:

/etc/init.d/mongod stop


2, mount/dev/xvdb1/mnt/#将第一块数据盘挂载至mnt目录下, can also be mounted to other data disks according to your own needs.

#mnt为数据盘的挂载目录, depending on your needs, the data disk can also be mounted in other directories.

Mkdir-p/mnt/mongodb


3, Cp-a/alidata/server/mongodb/data/*/mnt/mongodb/data/


4, vim/etc/mongod.conf Edit, will file the following content:

Dbpath=/alidata/server/mongodb/data

Modified to:

Dbpath=/mnt/mongodb/data/

Chown mongod.mongod/mnt/mongodb/data/-R


5. Start MongoDB

/etc/init.d/mongod start


————————


View MongoDB Master-Slave environment Image:>> main environment << | >> from the Environment <<

Master-Slave pairing of MongoDB database with data Migration example

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.