To MongoDB a stand-alone computer to a replica set

Source: Internet
Author: User
Tags mongodb
single-machine switch to replica set method step

1: Back up the database, turn off the current database

/u03/mongodb/bin/mongodump-d Configuration-o/u02/dump/

Use admin db.shutdownserver ();

2: Start two data nodes on both machines as follows:

/u01/mongo/bin/mongod--dbpath=/u01/mongodb/data/--logpath=/u01/mongodb/logs/node1.log--replSet replcopy/ 192.168.191.141:27017--fork

/u01/mongo/bin/mongod--dbpath=/u01/mongodb/data/--logpath=/u01/mongodb/logs/node2.log--replSetreplcopy/ 192.168.191.151:27017--fork

The data file for the first node is the data file directory of the previous single point, guaranteeing that the data has been

3: Start the quorum node on another machine

u01/mongo/bin/mongod--dbpath=/u01/mongodb/arbiter/--port 20000--logpath=/u01/mongodb/logs/arbiter.log--replSet Replcopy/192.168.191.141:27017,192.168.191.151:27017--fork

/admin

4: Add Configuration

CFG = {_id: "Replcopy", Members: [{_id:0, Host: "192.168.191.141:27017"}, {_id:1,host: "192.168.191 .151:27,017 "}]}

Rs.initiate (CFG)

5: Add quorum node

Rs.addarb ("192.168.191.150:20000");

6: Enter the database to view the status of a few laps

The Rs.status () rs.stepdown () command can force the primary and standard node roles to be interchanged to verify that the failover function is implemented.

7: Make the repository readable (optional)

Db.getmongo (). Setslaveok ()

8: Modify the Application connection string

mongodb://192.168.191.141:27017,192.168.191.151:27017


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.