Linux system MongoDB Master-Slave mode configuration

Source: Internet
Author: User

First, the environment

Operating system:

# uname-r2.6.32-358.el6.x86_64# Cat/etc/issuecentos Release 6.4 (Final) Kernel \ r on an \m

Master: 192.168.137.148

From: 192.168.137.154

Second, master-slave synchronization system time

#ntpdate ntp.api.bz && hwclock-w--SYSTOHC

Third, installation

#wget #tar XF MONGODB-LINUX-X86_64-ENTERPRISE-RHEL62-2.6.4.TGZ#MV mongodb-linux-x86_64-enterprise-rhel62-2.6.4/usr /local/mongodb#[-e/data/mongodb/data] && mkdir-p/data/mongodb/data | | Echo '/data/mongodb/data is exist! ' #[-e/data/mongodb/mongodb.log] && Touch/data/mongodb/mongodb.log | | Echo '/data/mongodb/mongodb.log is exist! '

Iv. Start-up service

MongoDB Master:

#/usr/local/mongodb/bin/mongod--master--bind_ip=192.168.137.148--dbpath=/data/mongodb/data--logpath=/data/ Mongodb/mongodb.log--logappend--port=27017--fork

MongoDB Slave:

#/usr/local/mongodb/bin/mongod--slave--bind_ip=192.168.137.154--source 192.168.137.148:27017--dbpath=/data/ Mongodb/data--logpath=/data/mongodb/mongodb.log--logappend--port=27017--fork

V. Testing

Master

# /usr/local/mongodb/bin/mongo --host 192.168.137.148mongodb shell version:  2.6.4connecting to: 192.168.0.23:27017/testwelcome to the mongodb shell. for interactive help, type  "Help". for more comprehensive documentation, seehttp://docs.mongodb.org/questions? try  the support grouphttp://groups.google.com/group/mongodb-userserver has startup  warnings: 2014-09-24t14:16:58.169+0800 [initandlisten] 2014-09-24t14:16:58.169+0800 [ initandlisten] ** warning: you are running on a numa  machine.2014-09-24t14:16:58.169+0800 [initandlisten] **           We suggest launching mongod like this to avoid  Performance problems:2014-09-24t14:16:58.169+0800 [initandlisten] **              numactl --interleave=all mongod [ other options]2014-09-24t14:16:58.169+0800 [initandlisten] > show dbs;                               #查看数据库local1 .203125gbtest0.203125gb> use test1;                               #新建库switched  to db test1>  Db.foo.save ({"id": 123456, "name": ' Zhangsan '})         #插入数据 >  Db.foo.find ({"id": 123456})              #查询数据 {  "_id"  : objectid ("542277078091089E1CBFECBC"),  "id"  : 123456,  "name"  :  "Zhangsan"  }> shoW dbs;local1.203125gbtest0.203125gbtest10.203125gb 

Slave:

# /usr/local/mongodb/bin/mongo --host 192.168.137.148mongodb shell version:  2.6.4connecting to: 192.168.0.23:27017/testwelcome to the mongodb shell. for interactive help, type  "Help". for more comprehensive documentation, seehttp://docs.mongodb.org/questions? try  the support grouphttp://groups.google.com/group/mongodb-userserver has startup  warnings: 2014-09-24t14:16:58.169+0800 [initandlisten] 2014-09-24t14:16:58.169+0800 [ initandlisten] ** warning: you are running on a numa  machine.2014-09-24t14:16:58.169+0800 [initandlisten] **           We suggest launching mongod like this to avoid  Performance problems:2014-09-24t14:16:58.169+0800 [initandlisten] **              numactl --interleave=all mongod [ other options]2014-09-24t14:16:58.169+0800 [initandlisten] > show dbs; Local0.203125gbtest0.203125gbtest10.203125gb> use test1;switched to db test1>  db.foo.find ({"id": 123456}) {  "_id"  : objectid ("542277078091089E1CBFECBC"),  "id"   : 123456,  "name"  :  "Zhangsan"  }

Data synchronization Success

Vi. Common operations

1) Querying the primary server for information from the server

> Use local;switched to DB local> show collections;mesourcessystem.indexes> db.sources.find () {"_id": ObjectId ( "541d8f661037aa7d865374d0"), "host": "192.168.137.148:27017", "source": "Main", "Syncedto": {"T": 1411545377000, "I" : 1}}

2) Querying the synchronization status on the primary server

> Db.printreplicationinfo (); configured Oplog Size:944.1375732421875mblog length start to End:420339secs (116.76hrs)  Oplog First Event Time:fri Sep 19:15:28 gmt+0800 (CST) Oplog last event time:wed Sep 16:01:07 gmt+0800 (CST) now:wed Sep 16:01:11 gmt+0800 (CST)

3) Querying the collection status on the master server

> db.printcollectionstats (); foo{"ns": "Test1.foo", "Count": 1, "size": Up, "avgobjsize": +, "storagesize": 4096, "num  Extents ": 1," nindexes ": 1," lastextentsize ": 4096," Paddingfactor ": 1," Flags ": 1," totalindexsize ": 8176," indexsizes ": {"_id_": 8176}, "OK": 1}---system.indexes{"ns": "Test1.system.indexes", "Count": 1, "size": +, "avgobjsize": "Stora" Gesize ": 4096," numextents ": 1," nindexes ": 0," lastextentsize ": 4096," Paddingfactor ": 1," Flags ": 0," totalindexsize ": 0, "indexsizes": {}, "OK": 1}---

VII. master/Slave switching

1) Stop slave Service

#killall Mongod

2) Delete local data

#rm-rf/data/mongodb/data/local.*

3) boot from server as Master

#/usr/local/mongodb/bin/mongod--master--bind_ip=192.168.137.154--dbpath=/data/mongodb/data--logpath=/data/ Mongodb/mongodb.log--logappend--port=27017--fork

4) View status 650 as Web) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M00/4A/1A/wKioL1QifmrQbd4rAAQNq6bo4Ag351.jpg " Title= "11.jpg" alt= "Wkiol1qifmrqbd4raaqnq6bo4ag351.jpg"/>

This article is from the "technical Side dish" blog, please make sure to keep this source http://390892467.blog.51cto.com/2006821/1557761

Linux system MongoDB Master-Slave mode configuration

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.