Build MongoDB replica set under Linux

Source: Internet
Author: User
Tags mongodb

1. Build three MongoDB servers

Cd/usr/local

mkdir MongoDB
TAR-ZXVF mongodb-linux-x86_64-2.6.7.tgz
CD MONGODB-LINUX-X86_64-2.6.7MV */usr/local/mongodb
Cd/usr/local/mongodbmkdir Datatouch Logs
CD Bin./mongod-dbpath=/usr/local/mongodb/data-logpath=/usr/local/mongodb/logs booting and testing

2. Setting up the boot configuration file

cd/usr/local/mongodb/

Mkdir-p mongodb_data/mongodb_db

mkdir Mongodb_data/mongodb_logs

Vi/etc/mongodb.conf

Fork = True

Quiet = True

BIND_IP = 192.168.30.112

Port = 27017

DBPath =/usr/local/mongodb/mongodb_data/mongodb_db

LogPath =/usr/local/mongodb/mongodb_data/mongodb_logs/server1.log

Logappend = True

Journal = True

Rest = True

Replset = Test

Above 3 servers, the same installation steps

3. Start MongoDB

Cd/usr/local/mongodb/bin

./mongod-f/etc/mongodb.conf

We connect to one of the nodes and initialize with the Replsetinitiate command. This command requires a configuration object that specifies the name of each member set

./mongo 192.168.30.112: 3306/admin

Use admin

Rs.initiate ()

Confirm Settings
Rs.conf ()

添加第一个从库rs0:PRIMARY> rs.add(‘IP:27017‘)
添加第二个从库
以通过priority来调整主库,选举的时候,priority大的优先被选举为主库
rs.add({host: 
"IP:27017", priority: 5})

确认设定
rs0:PRIMARY> rs.conf()

查看状态rs0:SECONDARY> rs.status()


Remove from library

First close the MongoDB from the library, and then remove the library from the main library

rs0:PRIMARY> rs.remove(‘IP:27017‘)

 

Build MongoDB replica set under Linux

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.