MongoDB replication mechanism instance
MongoDB master-slave replication is a master node that can replicate multiple slave nodes and master nodes. Here, one master node and one slave server use one database server to provide different ports.
1. Start a MongoDB service named application and port 1234
./Mongod -- replSet application -- dbpath data/node1 -- port 1234 -- oplogSize 1024
Indicates that startup is successful.
2. Open the client
./Mongo -- port 1234
3. Start node2, node3
./Mongod -- replSet application -- dbpath data/node2 -- port 1235 -- oplogSize 1024
./Mongod -- replSet application -- dbpath data/node3 -- port 1236 -- oplogSize 1024
4. Start the client with port 1234
./Mongo -- port 1234
V. Configuration copy
Config = {_ id: "application", members: []}
Config. members. push ({_id: 0, host: "localhost: 1234 "})
config.members.push({_id:1,host:"localhost:1235"})
Config. members. push ({_ id: 2, host: "localhost: 1236", arbiterOnly: true })
1 indicates that the instance is successfully added.
Vi. rs. isMaster ()
7. Test whether master-slave replication is implemented
1. Add a record to the master server
1.1 use test
Db. user. insert ({_ id: 1, name: "maybo "})
1.2 open the slave service client
./Mongo -- port 1235
1.3 Query
Use test
Db. user. find ("{})
It is found that slaveOk = false the current node needs to specify the slave Node
1.4 rs. slaveOk ()
Show collections
It indicates that the master-slave replication is successful, but the master-slave replication takes one time.
For more MongoDB tutorials, see the following:
CentOS compilation and installation of php extensions for MongoDB and mongoDB
CentOS 6 install MongoDB and server configuration using yum
Install MongoDB2.4.3 in Ubuntu 13.04
MongoDB beginners must read (both concepts and practices)
MongoDB Installation Guide for Ubunu 14.04
MongoDB authoritative Guide (The Definitive Guide) in English [PDF]
Nagios monitoring MongoDB sharded cluster service practice
Build MongoDB Service Based on CentOS 6.5 Operating System
MongoDB details: click here
MongoDB: click here
This article permanently updates the link address: