Set up MongoDB master-slave Copying (master-slave)

Source: Internet
Author: User
Tags mongodb
Master-slave replication is a feature of MongoDB database, which improves the disaster-tolerant capability of database by data backup. However, since master-slave replication does not automatically implement failover features, MongoDB has developed a new replication model in version 1.6: Replicate Sets. MongoDB recommends that you do not use the Master-slave mode to back up your data. But for learning, we can still understand the master-slave copy mode of MongoDB.
1. Download the latest version of MongoDB from MongoDB's official website and extract it to a directory.
2. Under the MongoDB folder, create the/data/master and/data/slave directories.
3. Start the primary node (master) server and run the following command:
Mongod--dbpath/data/master--port 10000--master

After the above command is executed, MongoDB generates the data files and log files under Data/master.
4. Start the server from the node (Slave) and run the following command:

Mongod--dbpath/data/slave--port 10001--slave--source

After the above command is executed, the data file and log files are also generated under Data/slave and the associated information with master is created under the sources table under the local database. 5. Test whether the master-slave copy (Master-slave) is effective.   
Use MONGO localhost:10000 to open the master database and insert a test statement: Db.test.find ();   Db.test.insert ({"Host": "1000"}); Db.test.find ();      using "MONGO localhost:10001" to open the slave database, running Db.test.find () will find that the queried data is the same as the data queried from the master database.
Run Db.test.insert ({"Girl": "Lili"}), the not master is displayed. This is because the master-slave replication mode only allows data to be updated from the master database, not from the slave database. As a result, when master fails, the disadvantage of being unable to convert a primary node from a node is a burst of leakage.
    

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.