MongoDB replica sets practice (applicable to version 1.8, not applicable after version 2.0)

Source: Internet
Author: User

Db1 startup Item:

./Mongod -- dbpath/data/dbdata -- logpath/data/dblog/mongodb1.log -- fork

Then set the user name and password:

Use Admin
DB. adduser ("admin", "admin ");
Use local
DB. adduser ("repl", "repl ");

Then start again as verified

./Mongod -- replset ABC -- dbpath/data/dbdata -- logpath/data/dblog/mongodb1.log -- auth -- fork

DB2 is also started in the preceding method.

----------------------------------------------------

Go to db1:

Use Admin

DB. Auth ("XXXX ");

Rs. Initiate ();

It takes 10 minutes to create a file.

Then execute Rs. Add ("db2serfer: 27017 ");

If db1 contains data, DB2 synchronizes the data.

----------------------------------------------------------

Add an arbiter

Start a server like db1.

Execute Rs. addarb ("xxxxxx: 27017") on the primary database (XXXX: Primary> ");

In this way, the arbiter is successfully added.

Execute Rs. Status (); To View, "health": 1, OK.

------------------------------------------------------------------------

Note that when adding arbiter, it must start like others, including authentication, user name and password.

When adding configuration, you need to enter the local database for verification.

-------------------------------------------------------------------------

If the new server cannot synchronize data, you can only copy the file to the new server by importing the file, and add -- fastsync.

./Mongod -- replset ABC -- dbpath/data/dbdata -- logpath/data/dblog/mongodb1.log -- auth -- fork -- fastsync

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.