MongoDB master-slave replication configuration, mongodb master-slave Replication

Source: Internet
Author: User

MongoDB master-slave replication configuration, mongodb master-slave Replication

The configuration in the mongoDB configuration file shows how to configure it. Here we use the configuration file to configure master/slave for master-slave replication:

1. Master/Slave Server Configuration:

1. master server configuration file: master. conf

Port = 27017

# Master server port

Dbpath = E: \ DB \ mongodb \ data

# Main service process data storage directory

Logpath = mongodb. log

# Main service log storage directory

Master = true

# Configuration-based service

Logappend = true

# Append the log instead of clearing the original log and then add

MaxConns = 1024

# Maximum number of database connections

 

2. slave server configuration file: slave. conf

Port = 27018

# Slave server port

Dbpath = E: \ DB \ mongodb \ data \ slavepath

# Store data from service process Directories

Logpath = mongodbslave. log

# Store service logs in a directory

Logappend = true

# Append logs

Slave = true

# Configure as a slave Service

Source = 127.0.0.1: 27017

# Synchronized master service address

Autoresync = true

# Automatic synchronization

 

3. Start the master server:

 

4. Start the slave server:

 

5. Connect the client to the master server and perform the following operations:

 

6. Add and save the data on the master:


7. Client connection to the slave server:


8. query from database data


From the query results, we can see that the data in the database is synchronized with the master database.

You can also view the log for the connection status.

Here we have performed a replication between the master and a slave, and the replication deployment method is still complicated. Learn more in the next article!

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.