MongoDB Replica set schema building

Source: Internet
Author: User

Create a Directory

Mkdir-p/DATA/R0/DATA/R1/DATA/R2

Declaring an instance

./bin/mongod--port 27017--dbpath/home/workspace/data/r0/--smallfiles--replset RSA--fork--logpath/home/workspace/ Logs/mongo0.log
./bin/mongod--port 27018--dbpath/home/workspace/data/r1/--smallfiles--replset RSA--fork--logpath/home/workspace/ Logs/mongo1.log
./bin/mongod--port 27019--dbpath/home/workspace/data/r2/--smallfiles--replset RSA--fork--logpath/home/workspace/ Logs/mongo2.log

Add configuration

rsconf = {
_id: ' RSA ',
Members
[
{_id:0,
Host: ' 192.168.87.131:27017 '
},
{_id:1,
Host: ' 192.168.87.131:27018 '
},
{_id:2,
Host: ' 192.168.87.131:27019 '
}
]
}
Rs.initiate (rsconf);

Test
    • Connecting child nodes:./bin/mongo--port 27017
    • Use test
    • Db.test.user ({uid:1,name: ' Liliy '})
    • Switch to from library:./bin/mongo--port 27019
    • Use test
    • Show Tables:Error:listCollections failed: {"note": "From ExecCommand", "OK": 0, "errmsg": "Not Master"}
    • Rs.slaveok ();
    • Show tables

In MongoDB you can only add the MONGO service to the replica set through the master node, judging whether the currently running MONGO service is able to use command Db.ismaster () for the master node.
MongoDB replica set is different from our common master-slave, master and slave after the host outage all services will stop, and replica set after the host outage, the replica will take over the master node becomes the primary node, there will be no downtime.

Resources:

Http://www.cnblogs.com/skyrim/p/5098167.html

MongoDB Replica set schema building

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.