1. Master-slave replication is MongoDB The most commonly used replication method, which is very flexible and can be used for backup, failure recovery, read extension, etc.
2 The most basic way to set up is to establish a master node and one or more slave nodes, each from the node to know the address of the master node. The primary server is started by running Mongod–master. Running mongod–slave–source master_address initiates the slave server, where master_address is the address of the primary node above.
4 respectively in F : Create two folders under disk to store the data from the master node and the slave node, respectively
5 Start a master node
mongod--dbpath=f:/master--port 27107–master (port number can be specified automatically, but preferably larger)
6 start a Slave node
Mongod--dbpath=f:/slave--port 20000--slave--source localhost:27017
7 start two clients, connecting the master node and the slave node respectively
MONGO localhost:27017
Execute 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 (); < Span style= "Font-family:calibri" >db.c2.insert ({name: "Lisi"}); This time found to add not to go in |
Conclusion: Master-slave replication
A only query operations from nodes B after the primary node is down, the slave node cannot be automatically replaced. This cluster is only used to back up data |
6. Non-relational database (NOSQL) MongoDB: Cluster (master-slave replication)