1. master-slave replication is the most common replication method for MongoDB. This method is flexible, the most basic setting method for backup, fault recovery, and read expansion is to create one master node and one or more slave nodes. Each slave node needs to know the address of the master node. After running mongodmaster, the master server is started. Run mongodslavesourcemaster_add
1. master-slave replication is the most common replication method for MongoDB. This method is flexible, the most basic setting method for backup, fault recovery, and read expansion is to create one master node and one or more slave nodes. Each slave node needs to know the address of the master node. After running mongod master, the master server is started. Run mongod slave source master_add
Slave 1. Master-slave replication is the most common replication method for MongoDB. This method is flexible and can be used for backup, fault recovery, read scaling, etc.
2. The most basic setting method is to create a master node and one or more slave nodes. Each slave node must know the address of the master node. After running mongod-master, the master server is started. Run mongod-slave-source master_address to start the slave server. master_address is the address of the master node above.
4. Create two folders under drive F to store data of the master node and slave node respectively.
5. Start a master node
Mongod -- dbpath = f:/master -- port 27107-master (the port number can be automatically specified, but it is better to be larger)
6. Start a slave Node
Mongod -- dbpath = f:/slave -- port 20000 -- slave -- source localhost: 27017
7. Start two clients to connect the master node and slave node respectively.
Mongo localhost: 27017
Run the following 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 (); Db. c2.insert ({name: "lisi"}); at this time, it is found that |
Conclusion: master-slave Replication
A only performs query operations on the slave Node After Master B goes down, slave nodes cannot be replaced automatically. This type of cluster is only used to back up data |