6. mongodb for non-relational databases (Nosql): Cluster (master-slave replication)

Source: Internet
Author: User
1. master-slave replication is the most common replication method for MongoDB. This method is flexible, the most basic setting method for backup, fault recovery, and read expansion is to create one master node and one or more slave nodes. Each slave node needs to know the address of the master node. After running mongodmaster, the master server is started. Run mongodslavesourcemaster_add

1. master-slave replication is the most common replication method for MongoDB. This method is flexible, the most basic setting method for backup, fault recovery, and read expansion is to create one master node and one or more slave nodes. Each slave node needs to know the address of the master node. After running mongod master, the master server is started. Run mongod slave source master_add

Slave 1. Master-slave replication is the most common replication method for MongoDB. This method is flexible and can be used for backup, fault recovery, read scaling, etc.

2. The most basic setting method is to create a master node and one or more slave nodes. Each slave node must know the address of the master node. After running mongod-master, the master server is started. Run mongod-slave-source master_address to start the slave server. master_address is the address of the master node above.

4. Create two folders under drive F to store data of the master node and slave node respectively.

5. Start a master node

Mongod -- dbpath = f:/master -- port 27107-master (the port number can be automatically specified, but it is better to be larger)

6. Start a slave Node

Mongod -- dbpath = f:/slave -- port 20000 -- slave -- source localhost: 27017

7. Start two clients to connect the master node and slave node respectively.

Mongo localhost: 27017

Run the following command:

Use toto

For (var I = 1; I <= 10000; I ++ ){

Db. c2.insert ({name: "zhangsan", age: I });

}

Mongo localhost: 20000

Show dbs;

Use toto

Db. c2.find ();

Db. c2.insert ({name: "lisi"}); at this time, it is found that

Conclusion: master-slave Replication

A only performs query operations on the slave Node

After Master B goes down, slave nodes cannot be replaced automatically.

This type of cluster is only used to back up data


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.