MongoDB 3.0 Replica Set Build

Source: Internet
Author: User
Tags install mongodb mongodb version

Environment Configuration

Architecture: One master two from (three virtual machines)

System version: CentOS Linux release 7.4.1708 (Core)

MongoDB version: 3.0.15

MongoDB Installation


The following operations are performed on three virtual machines


Download Yum Source Configuration

wget Https://repo.mongodb.org/yum/redhat/mongodb-org-3.0.repo MV mongodb-org-3.0.repo/etc/yum.repos.d/

Installing MongoDB

Yum-y Install mongodb-org

Modify the MongoDB configuration file

# Modify the Listener address for 0.0.0.0net:port:27017 bindip:0.0.0.0# Modify the replica set configuration, which is the configuration required to configure the replica set replication:oplogsizemb:20480 replsetname: GoGen

Modify Kernel Configuration

# It's best to join the boot profile echo never >/sys/kernel/mm/transparent_hugepage/enabledecho never >/sys/kernel/mm/transparent_ Hugepage/defrag

Modify the file descriptor /etc/security/limits.conf

# After the configuration file is added later content Mongod soft nofile 64000mongod hard nofile 64000mongod soft nproc 32000mongod hard Nproc 32000

Start the service

Chkconfig Mongod onservice mongod start

Replica set deployment


Execute the following command on any server to log in to Monogdb

Mongo

Switch to Admin library

> Use admin

Define a config variable

> config={_id: "GoGen", Members:[{_id:0,host: "192.168.6.91:27017"},{_id:1,host: "192.168.6.92:27017"},{_id:2, Host: "192.168.6.93:27017"}]}

Initialize configuration, return {"OK": 1} to create success

> rs.initiate (config) {"OK": 1}gogen:other> gogen:primary>

Replica Set weight configuration


Log on to MONOGDB on any server and execute the following command, first define a variable

Gogen:primary> Cfg=rs.config ()

Change the weight of the first host to 100

Gogen:primary> cfg.members[0].priority=100

Change the weight of a second host to 90

Gogen:primary> cfg.members[1].priority=90

Change the weight of a third host to 1

Gogen:primary> Cfg.members[2].priority=1

Refresh Configuration

Gogen:primary> Rs.reconfig (CFG)

Replica set basic commands are used

View Replica set Status

Gogen:primary> Rs.status ()

View Replica Set Configuration

Gogen:primary> Rs.config ()

Test

    1. Write some data on the master to see if it can be synchronized from the master

    2. Test the main outage (direct shutdown, or stop the service), whether the new master can be re-elected in two other

    3. Write the data on the new master and see if the other one can be synchronized

    4. Restore the old primary server of the outage, see if the newly written data can be synced to the old master, and see if the master will be captured back


MongoDB 3.0 Replica Set Build

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.