The "Replica" database server for MongoDB

Source: Internet
Author: User

1. Assume that 1 database server is Active server (master server), 2 and 3 is the backup server, when 1 fails, then will be in 2 and 3 to elect one (according to the weight of the rules) as an active server, and when 1 is back to normal, it will be the identity of the backup server to appear;

2. Set the value of the database server (in the configuration file to be set to a closed loop):

For example, set up a replica cluster of three databases:

Database 1:dbpath= D:/AA/AA/1

port= 1111 #端口号

bind_ip= 127.0.0.1 #服务器的IP地址

replset= child/127.0.0.1:2222 #备份的服务器同伴

Located in the 1.conf configuration file;

Database 2:dbpath= D:/AA/AA/2

port= 2222 #端口号

bind_ip= 127.0.0.1 #服务器的IP地址

replset= child/127.0.0.1:3333 #备份的服务器同伴

Located in the 2.conf configuration file;

Database 3:dbpath= D:/AA/AA/3

port= 333 #端口号

bind_ip= 127.0.0.1 #服务器的IP地址

replset= child/127.0.0.1:1111 #备份的服务器同伴

Located in the 3.conf configuration file;

And then in the corresponding server-initiated batch file in the 1.conf corresponding to the same as 1 database boot server Mongod--config the same as the same can be * * *;

In the shell, such as 1 database server Direct input: MONGO 127.0.0.1:1111 other similar;

3. If you want a replica cluster that is configured above to work, you must execute the command:

3.1 Use database name input: Db.runcommand ({"Replsetinitiate"):

{

"_id": "Child",

"Menbers": [{"_id": 1, "host": "127.0.0.1:1111"},{"_id": 1, "host": "127.0.0.1:2222"},{"_id": 1, "host": "127.0.0.1 : 3333 "}]

}

});

4. Use Rs.status () to view the status of the replica cluster database server;

The replica database server for MongoDB

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.