MongoDB Learning Note--Replication copy set

Source: Internet
Author: User



Official documents:
http://docs.mongodb.org/manual/replication/

Replication sets multiple servers maintain the same copy of data


How to use the replication set first step

Start Mongod is to specify the replica set name, either by adding –replset name or by setting the Replication.replsetname setting in the configuration file

Like what:

mongod --port 270217 --dbpath /mongo/database --logpath /mongo/log/mongo.log --replSet repl_test --smallfiles &mongod --port 270218 --dbpath /mongo2/database --logpath /mongo2/log/mongo.log --replSet repl_test --smallfiles &mongod --port 270219 --dbpath /mongo3/database --logpath /mongo3/log/mongo.log --replSet repl_test --smallfiles &


Step Two

into one of the
Like what:

mongo --port 27017

Then define the parameters of Rs.initiate (rsconf) rsconf

rsconf = {    _id:‘repl_test‘,    members:    [        {            _id:0,host:‘127.0.0.1:27017‘                },        {            _id:1,host:‘127.0.0.1:27018‘                },        {            _id:2,host:‘127.0.0.1:27019‘                },    ]}


Step Three

Initializing a replication set

rs.initiate(rsconf)




Operation on a replica set


viewing replication Set Information

Default _id:0 The Mongod primary node

Delete a node
    rs.remove(host)
Adding nodes
rs.add(host)rs.reconfig(rsconf)
Default access to the primary node can be manipulated, if you enter the secondary node, want to do crud operations need to run
rs.slaveOk()


If the primary node goes down, one of the remaining nodes will automatically become the master node




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

MongoDB Learning Note--Replication copy set

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.