MongoDB Replica set creation

Source: Internet
Author: User



VI install_mongo.sh

TAR-ZXVF mongodb-linux-x86_64-rhel62-3.2.9.tgz

MV Mongodb-linux-x86_64-rhel62-3.2.9/usr/local/mongo

Cat>>/etc/profile<<eof

Export Path=/usr/local/mongo/bin: $PATH

Eof

Source/etc/profile



Mongotest1


VI start27017.sh

Mkdir/opt/mongo1_1

Cat >>/etc/mongo_27017.conf<<eof

port=27017

Fork=true

Storageengine=wiredtiger

Dbpath=/opt/mongo1_1

Logpath=/opt/mongo1_1/mongo.log

Wiredtigerdirectoryforindexes=true

wiredtigercachesizegb=0.3

Logappend=true

Replset=rs1

oplogsize=100

Eof

Mongod-f/etc/mongo_27017.conf


[email protected] etc]# cat mongo_2701

Mongo_27017.conf mongo_27018.conf

[email protected] etc]# cat mongo_27018.conf

port=27018

Fork=true

Storageengine=mmapv1

Dbpath=/opt/mongo1_2

Logpath=/opt/mongo1_2/mongo.log

Replset=rs1

Logappend=true

oplogsize=100







CFG = {_id: "Rs1", members:[

{_id:0, Host: "192.168.0.109:27017"},

{_id:1, Host: "192.168.0.110:27017"},

{_id:2, Host: "192.168.0.111:27017"}]

};

Rs.initiate (CFG);


Use online

Db.test1.insert ({name: ' AAA '})

Db.test1.find ()



Adding nodes

Rs.add (' 192.168.0.111:27018 ')



[Email protected] opt]# MONGO--port 27018

rs1:secondary> Use admin

Switched to DB admin

rs1:secondary> Use online

Switched to DB online

Rs1:secondary> Rs.slaveok ()

Rs1:secondary> Db.test1.find ()

{"_id": ObjectId ("57e943faff931e363a5a0309"), "name": "AAA"}


This article is from the "12104515" blog, please be sure to keep this source http://12114515.blog.51cto.com/12104515/1856809

MongoDB Replica set creation

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.