MongoDB builds a Replica Set

Source: Internet
Author: User
Tags install mongodb

1. Create a data directory under the same-level installation directory of MongoDB. The directory structure is as follows:

/Data/rs0

/Data/rs1

/Data/rs2

2. Use the command line to start the three instances of mongod, open the three command line windows, and enter the following commands respectively:

Mongod -- port 10000 -- dbpath E:/field/replset/data/rs0 -- replSet rscx -- smallfiles -- oplogSize 128

Mongod -- port 10001 -- dbpath E:/field/replset/data/rs1 -- replSet rscx -- smallfiles -- oplogSize 128

Mongod -- port 10002 -- dbpath E:/field/replset/data/rs2 -- replSet rscx -- smallfiles -- oplogSize 128

After executing the preceding command, the MongoDB instance service has been started. We can see some data configuration files automatically generated by MongoDB under the data directory just created. But at the same time, we will also find that the command line will not stop typing "replSet can't get local. system. replset config from self or any seed ", this is because of the loccal set. system. replset does not have any configuration information. We also need to execute rs on the command line. initialize.

Open a command line window and connect to the first instance.

Mongo -- port 10000

Enter the configuration information of mongodb replicate sets in the command line, and then execute rs. initiate (rsconf) to initialize the configuration information.

Rsconf = {

_ Id: "rs0 ",

Members :[

{

_ Id: 0,

Host: "

}

]

}

Rs. initiate (rsconf)

In this step, if you forget to add parameters when executing the rs. initialte method, you can re-initialize the configuration file through rs. reconfig (rsconf.

Next, run the rs. conf () command. The following information is displayed.

Rscx: PRIMARY> rs. conf ()

{

"_ Id": "rscx ",

"Version": 2,

"Members ":[

{

"_ Id": 0,

"Host": "favpc: 10000"

}

]

}

Next, run the following command to add the other two configuration sets to the replica set.

Rs. add ("favpc": 10001)

Rs. add ("favpc": 10002)

Now, the Replica Sets Replica set is successfully set up. We can also see that the command line window of the mongodb replica set no longer prints replSet can't get local. system. replset config from self or any seed "is replaced by the printed connection information of the replica set. When we update data on the master node, the slave Node also automatically updates the data.

MongoDB details: click here
MongoDB: click here

MongoDB backup and recovery

CentOS compilation and installation of MongoDB

CentOS compilation and installation of php extensions for MongoDB and mongoDB

CentOS 6 install MongoDB and server configuration using yum

Install MongoDB2.4.3 in Ubuntu 13.04

How to create a new database and set in MongoDB

MongoDB beginners must read (both concepts and practices)

MongoDB authoritative Guide (The Definitive Guide) in English [PDF]

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.