MongoDB replication set replica set (Master-slave Replication) (8)

Source: Internet
Author: User

Replicattion set is that multiple servers maintain the same copy of the data, increasing the availability of the server.

Replication Set Setup whole process

0: Create a directory

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

1: Start 3 instances and declare instances to be part of a replication set

./bin/mongod--port 27017--dbpath/data/r0--smallfiles--replset RSA--fork--logpath/var/log/mongo17.log

./bin/mongod--port 27018--dbpath/data/r1--smallfiles--replset RSA--fork--logpath/var/log/mongo18.log

./bin/mongod--port 27019--dbpath/data/r2--smallfiles--replset RSA--fork--logpath/var/log/mongo19.log

2: Start Mongo.exe, feel free to connect to a server, start the configuration

Use admin

var rsconf = {

_id: ' RSA ',

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 '

}

]

}

3: Initialize according to configuration

Rs.initiate (rsconf);

4: View status

Rs.status ();

We got three nodes "Statestr": "Secondary", "statestr": "Secondary", "Statestr": "PRIMARY",

5: Add node

Rs.add (' 192.168.1.201:27018 ');

Rs.add (' 192.168.1.201:27019 ');

6: Delete node

Rs.remove (' 192.168.1.201:27019 ');

7: Primary Node inserts data

>use Test

>db.user.insert ({uid:1,name: ' Lily '});

8: Connection Secondary Query synchronization situation

./bin/mongo--port 27019

>use Test

>show collections;

Rsa:secondary> Show Collections;

2015-11-10t21:56:14.075+0800 E QUERY error:listdatabases failed:{"note": "

From ExecCommand "," OK ": 0," errmsg ":" Not Master "}

At Error (<anonymous>)

At Mongo.getdbs (src/mongo/shell/mongo.js:47:15)

At Shellhelper.show (src/mongo/shell/utils.js:630:33)

At Shellhelper (src/mongo/shell/utils.js:524:36)

At (SHELLHELP2): 1:1 at src/mongo/shell/mongo.js:47

8.1 The above error occurs because slave is not allowed to read and write by default

>rs.slaveok ();

>show collections;

See data that is consistent with primary

MongoDB replication set replica set (Master-slave Replication) (8)

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.