MONGO 3.2 Replica Set configuration

Source: Internet
Author: User

I. Environmental information

CentOS Release 6.7 (Final)

MONGO version:3.2.6


192.168.1.173 Primary

192.168.1.174 Secondary

192.168.1.172 Secondary or arbiter

Second, installation MONGO


1. Yum Source configuration (which version enable=1 is used)

# Cat/etc/yum.repos.d/mongodb-org-3.2.repo

[mongodb-org-3.2]

Name=mongodb Repository

baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/

Gpgcheck=1

Enabled=1

Gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc

[mongodb-org-2.6]

NAME=MONGODB 2.6 Repository

baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/

Gpgcheck=0

Enabled=0

2. Yum Install-y mongodb-org


Third, Replicat set configuration


1, modify the configuration file (three servers in addition to IP is not the same):

Cat/etc/mongod.conf

# mongod.conf

# for documentation of all options, see:

# http://docs.mongodb.org/manual/reference/configuration-options/

# Where to write logging data.

Systemlog:

Destination:file

Logappend:true

Path:/var/log/mongodb/mongod.log

# Where and how to store data.

Storage

DbPath:/data/mongo

# DbPath:/var/lib/mongo

Journal

Enabled:true

# Engine:

# Mmapv1:

# Wiredtiger:

# How the process runs

Processmanagement:

Fork:true # Fork and run in background

Pidfilepath:/var/run/mongodb/mongod.pid # Location of Pidfile

# Network Interfaces

Net

port:27017

bindip:192.168.1.173 # Listen to local interface only, comment to Listen on all interfaces.

#security:

Security: #副本集配置成功之后才能打开安全认证

Authorization:enabled #开启认证

KeyFile:/data/mongo/mongodb-keyfile #副本集使用keyFile进行相互认证

#operationProfiling:

#replication:

Replication

oplogsizemb:2000 #oplog的大小M

Replsetname:rongyi #副本集的名称

#sharding:

# # Enterprise-only Options

#auditLog:

#snmp:


2. Configuring the Replicat Set procedure

#启动mongod服务

#/usr/bin/mongod-f/etc/mongod.conf

After successful startup, you can login directly from the command line because Auth authentication is not turned on.


#mongo 192.168.1.173

Use admin

admin> config = {_id: "Rongyi", members:[

... {_id:172,host: "192.168.1.172:27017", arbiteronly:true},

... {_id:173,host: "192.168.1.173:27017"},

... {_id:174,host: "192.168.1.174:27017"}]

... }

{

"_id": "Rongyi",

"Members": [

{

"_id": 172,

"Host": "192.168.1.172:27017",

"Arbiteronly": True

},

{

"_id": 173,

"Host": "192.168.1.173:27017"

},

{

"_id": 174,

"Host": "192.168.1.174:27017"

}

]

}

admin> rs.initiate (config)

{"OK": 1}


or use

Config = {_id: "Rongyi", Members:[{_id:172,host: "192.168.1.172:27017"},{_id:173,host: "192.168.1.173:27017"},{_id : 174,host: "192.168.1.174:27017"}]}


Note: The former is a backup node, the latter is two backup nodes, the MONGO election process must conform to most, if the node is even, you can use the Arbiter (quorum node), this node is only to participate in the election


Use Rs.status () to view the status of the Replicat set


3. Create an Administrator account (this account must use root role otherwise will be error):


Admin> Db.createuser ({User: "admin", pwd: "********", roles:[{role: "Root", DB: "Admin"}]})

Successfully added User: {

"User": "admin",

"Roles": [

{

"Role": "Root",

"DB": "admin"

}

]

}


4. Configure KeyFile Certification


Execute on the 192.168.1.173

OpenSSL rand-base64 741 >/data/mongo/mongodb-keyfile

chmod 600/data/mongo/mongodb-keyfile

SCP Mongodb-keyfile 192.168.1.174:/data/mongo/

SCP Mongodb-keyfile 192.168.1.172:/data/mongo/


To turn on authentication in the configuration file:

Security

Authorization:enabled

KeyFile:/data/mongo/mongodb-keyfile


5. Restart Mongod Service

/etc/init.d/mongod Stop &&/usr/bin/mongod-f/etc/mongod.conf


IV. Login Verification

MONGO 192.168.1.173:27017/admin-uadmin-p*******

Admin> Rs.status ()

{

"Set": "Rongyi",

"Date": Isodate ("2016-06-24t08:31:28.549z"),

"MyState": 1,

"Term": Numberlong (7),

"Heartbeatintervalmillis": Numberlong (2000),

"Members": [

{

"_id": 172,

"Name": "192.168.1.172:27017",

"Health": 1,

"State": 7,

"Statestr": "Arbiter", #使用了仲裁

"Uptime": 19572,

"Lastheartbeat": Isodate ("2016-06-24t08:31:26.604z"),

"Lastheartbeatrecv": Isodate ("2016-06-24t08:31:24.145z"),

"Pingms": Numberlong (0),

"ConfigVersion": 3

},

{

"_id": 173,

"Name": "192.168.1.173:27017",

"Health": 1,

"State": 1,

"Statestr": "PRIMARY",

"Uptime": 19573,

"Optime": {

"TS": Timestamp (1466740497, 1),

"T": Numberlong (7)

},

"Optimedate": Isodate ("2016-06-24t03:54:57z"),

"Electiontime": Timestamp (1466737527, 1),

"Electiondate": Isodate ("2016-06-24t03:05:27z"),

"ConfigVersion": 3,

"Self": true

},

{

"_id": 174,

"Name": "192.168.1.174:27017",

"Health": 1,

"State": 2,

"Statestr": "Secondary",

"Uptime": 19567,

"Optime": {

"TS": Timestamp (1466740497, 1),

"T": Numberlong (7)

},

"Optimedate": Isodate ("2016-06-24t03:54:57z"),

"Lastheartbeat": Isodate ("2016-06-24t08:31:26.604z"),

"Lastheartbeatrecv": Isodate ("2016-06-24t08:31:26.604z"),

"Pingms": Numberlong (0),

"Syncingto": "192.168.1.173:27017",

"ConfigVersion": 3

}

],

"OK": 1

}



This article from the "Linux Learning" blog, reproduced please contact the author!

MONGO 3.2 Replica Set configuration

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.