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!