Mongodb Study Notes 08 and mongodb Study Notes

Source: Internet
Author: User

Mongodb Study Notes 08 and mongodb Study Notes



Official documentation:
Http://docs.mongodb.org/manual/replication/

Replication sets multiple servers maintain the same data copy


Step 1: how to use a replica set

When mongod is started, you must specify the replica set name. You can set the replica set name by adding-replSet name or setting replication. replSetName in the configuration file.

For example:

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 2

Enter one of
For example:

mongo --port 27017

Then define the rs. initiate (rsconf) parameter 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 3

Initialize a replica set

rs.initiate(rsconf)




Operation on replica set


View replica set information

Default Value: _ id: 0. mongod is the primary node.

rs.status() 
Delete a node
    rs.remove(host)
Add Node
rs.add(host)rs.reconfig(rsconf)
Operations can be performed on the master node by default. If you enter the secondary node, you need to run the CRUD operation.
rs.slaveOk()


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




Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.