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)