"MongoDB Learning Note 31" MongoDB Configuration Replica set

Source: Internet
Author: User
Tags centos server

First, configure the environment

1. Two CentOS server with MongoDB installed; (Installation reference http://281816327.blog.51cto.com/907015/1598270)

2. The IP of two servers is 192.168.1.112, 192.168.1.113 respectively;

3. Two server firewalls let go of the default 27017 port of MongoDB;

Second, configure the server

Both servers do the following configuration

Create a/data/db folder

Mkdir/date && mkdir/data/db

Modifying a configuration file

Vim/etc/mongodb.conf

Some of the important parameters are modified as follows:

#where to log logpath=/var/log/mongodb/mongod.loglogappend=true# fork and run in background fork=truedbpath=/data/db# Location of Pidfile pidfilepath=/var/run/mongodb/mongod.pid# Listen to local interface only.   Comment out to listen on all interfaces.   #bind_ip =127.0.0.1# Enable The HTTP interface (Defaults to Port 28017). httpinterface=true# in replicated MONGO databases, specify the replica set name here Replset=spock

Start MongoDB:

Mongod–f/etc/mongodb.conf–-rest

Third, configure the replica set

Enter MongoDB's shell on 192.168.1.122, test the connection 192.168.1.113 and create a config document:

[[email protected] ~]# mongo   mongodb shell version: 2.6.6     connecting to: test    > db= (New Mongo (" 192.168.1.113:27017 ")). Getdb (" test ")     test    > config={" _id ":" Spock ",    ... " members ": [    ... {" _id ": 0," host ":" 192.168.1.112:27017 "},    ... {" _id ": 1," host ":" 192.168.1.113:27017 "}]}     {             "_id"  :  "Spock" ,             "Members"  : [                     {                               "_id"  : 0,                              " Host " : " 192.168.1.112:27017 "                     },                     {                               "_id"  : 1,                              "Host"  :   "192.168.1.113:27017"                      }            ]     }

Initialize replica set:

> rs.initiate (config) {"info": "Config now saved locally. Should come online in about a minute. "," OK ": 1}

Iv. Verification Results

Enter the MongoDB shell on the 192.168.1.112:

[[email protected] ~]# MONGO MongoDB shell version:2.6.6 connecting To:test spock:secondary>

Enter the MongoDB shell on the 192.168.1.112:

[[email protected] ~]# MONGO MongoDB shell version:2.6.7 connecting To:test spock:primary>

You can see the spock:secondary and Spock:primary keywords, indicating that the replica set configuration is complete;


This article is from the "Margin with Wish" blog, please be sure to keep this source http://281816327.blog.51cto.com/907015/1610153

"MongoDB Learning Note 31" MongoDB Configuration Replica set

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.