MongoDB replication Mechanism Instance

Source: Internet
Author: User

MongoDB Master-slave replication is a master can be more from and can master the master-slave replication. Here is the implementation of a master one from an arbiter server using a database server by providing a different port.

A Start a MongoDB service name is application, port is 1234

./mongod--replset Application--dbpath data/node1--port 1234--oplogsize 1024


Indicates that the startup was successful.
Two Open Client
./mongo--port 1234

Three Start Node2,node3

./mongod--replset Application--dbpath data/node2--port 1235--oplogsize 1024

./mongod--replset Application--dbpath data/node3--port 1236--oplogsize 1024


Four The boot port is a 1234 client
./mongo--port 1234
Five Configuration Replicas
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})

Return 1 Description Add success
Six Rs.ismaster ()

Seven Testing whether to implement master-slave replication
1. Add a record to the master server
1.1 Use Test
Db.user.insert ({_id:1,name: "Maybo"})


1.2 Open from service client
./mongo--port 1235

1.3 Queries
Use test
Db.user.find ("{}")

Discover Slaveok=false the current node needs to be clear from the node.
1.4 Rs.slaveok ()
Show collections

Indicates that master-slave replication has succeeded, but the master-slave replication takes a minute.

MongoDB replication Mechanism Instance

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.