MongoDB Establish master-slave replication small case (one master one from)

Source: Internet
Author: User

It took two days to learn MongoDB, and today came into contact with MONGO's master-slave configuration, to write it down

1.

  Open two MONGO server (for a master one from, no security validation related parameters: can be viewed with mongd-help)

Mongod--bind_ip IP--port port--dbpath d:\. --replset Name

.... (from a similar port, not the same)

--BIND_IP: Server address

--Port: The ports used by the server

--DBPath: File path for storing data

--resplset:replset_name, can be arbitrary, but the master and slave two must be the same

For master:

    

Used from:
    

2.

  Open two terminals to connect two servers

MONGO--host IP--port Port

--host: The server address of the connection

--port: ... Port

Connection Master:
    

Connections from:

    

Two clients have not set up the master and slave after connecting two server ports, so the prompt is just: >

3.

  Set the primary server (which server is connected, which server to initialize)

Rs.initiate ()

    

Add replica set (add from, add in main)

Rs.add (' Host:port ')

    

4.

  To read from the server, you need to set the Rs.slaveok

Rs.slaveok ()

    

All required configurations are complete, then add a piece of data to the database in the master server

    

Then see if the data is also available from the server

    

OK, after the master-slave relationship is configured successfully, the data from the primary server is backed up every little time from the server, and if an emergency causes the primary server to hang,

From the server will automatically switch to the primary server, of course, will lose a small amount of data (which is said to be a short period of time not backed up data), when the primary server is connected again automatically become a slave server

MongoDB Establish master-slave replication small case (one master one from)

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.