MongoDB Replica set Environment construction

Source: Internet
Author: User

Original works, allow reprint, please be sure to use hyperlinks in the form of the original source of the article, author information and this statement. Otherwise, the legal liability will be investigated. http://suifu.blog.51cto.com/9167728/1853478

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

1234567891011121314151617 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

12345 cat/dev/urandom| LC_ALL=C tr-dc"[:alnum:]" fold-w 10 |head-1 >/tmp/key.txtkeystring=`cat/tmp/key.txt`echo$keystring >/export/mongodb/key/mongodecho$keystring >/export/mongodb/key/arbiterchmod600 /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.

1234567 shard1:SECONDARY> use testswitched todb 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.