MongoDB Replica Cluster setup

Source: Internet
Author: User
Tags mongodb version

First, build the environment:

MongoDB version: mongodb-linux-x86_64-3.0.6.gz

Linux version: CentOS 7 x64

Server: (Port: 27000)

192.168.1.201 database server, 192.168.1.202 database server, 192.168.1.203 quorum server

(Each server firewall turns on 27000 port iptables-i input-p TCP--dport 27000-j ACCEPT)

Two, 201, and 202 Configure the database and start (Cluster Name: daxiong) Command:

Bin/mongod--port 27000--dbpath db--logpath log/mongod.log--replset Daxiong


third, the connection 201 or 202 Database

Bin/mongo 192.168.1.201:27000

Iv. Enter admin, initialize the cluster

Use Adminconfig = {_id: "Daxiong", Members:[{_id:0,host: "192.168.1.201:27000"},{_id:1,host: "192.168.1.202:27000"}]} Rs.initiate (config)


(need to be executed for a period of time)

Five, add the arbiter server after successful addition

Rs.addarb ("192.168.1.203:27000")


Vi. Viewing Status:

Rs.status ()


201 is currently the primary server: Primary

202 Standby server: Secondary

203 Arbiter Server: Arbiter

Vii. test failover

Back to 201,ko Mongod

Connection 202, view status 202 has become the primary server primary, then 201 has lost the link

Start 201 Now 201 is already an alternative server.

By default, both read and write are on the primary server, and the replica server does not support queries, if the master-slave separation is implemented, the primary server is written, and the replica server reads

Replica server to turn on Read permissions

Db.getmongo (). Setslaveok ();





MongoDB Replica Cluster setup

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.