MongoDB: mongodb master-slave replication (2) replica set

Source: Internet
Author: User
Tags create mongodb
I will talk about the replica set in the previous phase. The primary features of the replica set are embodied in two aspects: 1. the replica set does not have a specific primary database. 2. If there is a fault such as a crash, the cluster selects a database as the primary database, which provides the automatic fault recovery function. Next we will perform the following operations: in the folder, copy mongodb1_db2

I will talk about the replica set in the previous phase. The primary features of the replica set are embodied in two aspects: 1. the replica set does not have a specific primary database. 2. If there is a fault such as a crash, the cluster selects a database as the primary database, which provides the automatic fault recovery function. Next we will perform the following operations: in the folder, We will reproduce mongodb mongodb2

I will talk about replica sets in the previous phase. The primary features of replica sets are reflected in two aspects:
1. The replica set does not have a specific primary database
2. If a fault such as downtime occurs, the cluster selects a database as the primary database, which provides the automatic fault recovery function.

Next we will perform the following operations:
We re-create mongodb mongodb3 in the folder as the master database, slave database, and arbitration database we will operate on.
1. Let's name the cluster we are about to operate. It is called my blog English name: jessonlv. -- replSet indicates to let the server know that there are other databases under jessonlv. Here we will open the mongodb program in drive F with port 2222. The specified port 3333 is another database server in the jessonlv cluster.

mongod --dbpath=F:\mongodb\db --port 2222 --replSet jessonlv/127.0.0.1:3333


2. Start mongodb with port 3333.

mongod --dbpath=F:\mongodb2\db --port 3333 --replSet jessonlv/127.0.0.1:2222
It is the same as above.
3. The third step is to initialize the replica set and view the code in the admin collection:
mongo 127.0.0.1:2222/admindb.runCommand({"replSetInitiate":{"_id":"jessonlv","members":[{"_id":1,"host":"127.0.0.1:2222"},{"_id":2,"host":"127.0.0.1:3333"}]}})
Figure:


As shown in, "OK" is displayed. The replica set has been initialized. Let's check who said the master server and who said the slave server.
Let's look at it again:
Now, the master-slave service is ready. Let's discuss the arbitration server. Note: The arbitration server only participates in voting.
Specify the arbitration server: mongod -- dbpath = F: \ mongodb3 \ db -- port 4444 -- replSet jessonlv/127.0.0.1: 2222


Then I enter the admin set on port 2222 and append it with rs. addArb.
Append mongo 127.0.0.1: 2222/adminrs. addArb ("127.0.0.1: 4444") in the admin collection using rs. addArb ")

After the append, run rs. status ()

View status
For example, it is clear who is the master-slave and arbitration database.

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.