MongoDB Replica set Environment construction

Source: Internet
Author: User



Environment Introduction:

192.168.1.250 Main port=27408

192.168.1.250 arbitration port=27409

192.168.1.251 Preparation port=27408



[Email protected] ~]# tar xvf mongodb-linux-x86_64-2.6.10.tgz

[Email protected] ~]# mkdir-p/export/mongodb

[Email protected] ~]# mkdir-p/export/mongodb/bin

[Email protected] ~]# mkdir-p/export/mongodb/conf

[Email protected] ~]# mkdir-p/export/mongodb/log

[Email protected] ~]# mkdir-p/export/mongodb/data

[Email protected] bin]# Cd/root/mongodb-linux-x86_64-2.6.10/bin

[Email protected] bin]# cp/root/mongodb-linux-x86_64-2.6.10/bin/*/export/mongodb/bin/

[Email protected] bin]# vi/export/mongodb/conf/mongod.conf

port=27408dbpath=/export/mongodb/datalogpath=/export/mongodb/log/mongod.logfork=truelogappend=truekeyfile=/ Export/mongodb/key/mongodnohttpinterface=truereplset=shard1[[email protected] bin]# vi/export/mongodb/conf/ Arbiter.confport=27409dbpath=/export/mongodb/arbiterlogpath=/export/mongodb/log/arbiter.logfork=truelogappend= Truekeyfile=/export/mongodb/key/arbiternohttpinterface=truereplset=shard1


keyfile files include:

Mongod,arbiter


Create a script that generates keyfile

VI create_key.sh

Cat/dev/urandom | Lc_all=c TR-DC "[: Alnum:]" | Fold-w |head-1 >/tmp/key.txtkeystring= ' Cat/tmp/key.txt ' echo $keystring >/export/mongodb/key/mongodecho $ KeyString >/export/mongodb/key/arbiterchmod 600/export/mongodb/key/*


Start the server in the main

[Email protected] ~]#/export/mongodb/bin/mongod-f/export/mongodb/conf/mongod.conf

[Email protected] ~]#/export/mongodb/bin/mongod-f/export/mongodb/conf/arbiter.conf

In from

[Email protected] ~]#/export/mongodb/bin/mongod-f/export/mongodb/conf/mongod.conf



>config={_id: ' Shard1 ', members:[{_id:0,host: ' 192.168.1.248:27408 '},{_id:1,host: ' 192.168.1.249:27408 '},{_id:2 , host: ' 192.168.1.248:27409 ', Arbiteronly:true}]}




>rs.initiate (config)

Initialize Rs.initiate (config), config is the name defined previously


When the master and standby library is configured, the standby library is queried.

Shard1:secondary> use testswitched to DB testshard1:secondary> db.t1.find () Error: {"$err": "Not Master and Slaveok =false "," code ": 13435}shard1:secondary> Rs.slaveok () shard1:secondary> db.t1.find () {" _id ": ObjectId (" 5704c11d3e0651733bfdea23 ")," X ": 1}


Rs.stauts () can look at the state, Health:1 stands for health, statestr who is our arbitration

Want to downgrade the main library to from the Library, Rs.stepdown ()


This article is from the "Age volt" blog, please make sure to keep this source http://suifu.blog.51cto.com/9167728/1853478

MongoDB Replica set Environment construction

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.