How to install Replica Sets for MongoDB learning and sorting

Source: Internet
Author: User

Preparation:
Server Port Data Directory log replica set key file
Server1 28010/app/mongo/mongodb/data/sets/r0/app/mongo/mongodb/data/sets/log/r0.log/app/mongo/mongodb/data/sets/key /r0
Server2 28011/app/mongo/mongodb/data/sets/r1/app/mongo/mongodb/data/sets/log/r2.log/app/mongo/mongodb/data/sets/key /r1
Server3 28012/app/mongo/mongodb/data/sets/r2/app/mongo/mongodb/data/sets/log/r3.log/app/mongo/mongodb/data/sets/key /r2

1. Create data files, Log Path directories, and replica set key files
Mkdir-p/app/mongo/mongodb/data/sets/r0
Mkdir-p/app/mongo/mongodb/data/sets/r1
Mkdir-p/app/mongo/mongodb/data/sets/r2
Mkdir-p/app/mongo/mongodb/data/sets/key/
Mkdir-p/app/mongo/mongodb/data/sets/log/

Echo "test sets">/app/mongo/mongodb/data/sets/key/r0
Echo "test sets">/app/mongo/mongodb/data/sets/key/r1
Echo "test sets">/app/mongo/mongodb/data/sets/key/r2

Chmod 600/app/mongo/mongodb/data/sets/key/r *

2. Start three mongodb instances to simulate three node servers:

/App/mongo/mongodb/bin/mongod -- replSet rs1 -- keyFile/app/mongo/mongodb/data/sets/key/r0 -- port 28010 -- dbpath =/app/mongo/ mongodb/data/sets/r0 -- logpath =/app/mongo/mongodb/data/sets/log/r0.log -- logappend -- fork

/App/mongo/mongodb/bin/mongod -- replSet rs1 -- keyFile/app/mongo/mongodb/data/sets/key/r1 -- port 28011 -- dbpath =/app/mongo/ mongodb/data/sets/r1 -- logpath =/app/mongo/mongodb/data/sets/log/r2.log -- logappend -- fork

/App/mongo/mongodb/bin/mongod -- replSet rs1 -- keyFile/app/mongo/mongodb/data/sets/key/r2 -- port 28012 -- dbpath =/app/mongo/ mongodb/data/sets/r2 -- logpath =/app/mongo/mongodb/data/sets/log/r3.log -- logappend -- fork

3. initialize the Replica Sets Environment
[Mongodb @ www.bkjia.com mongo] $/app/mongo/mongodb/bin/mongo-port 28010 // connection

> Config_rs = {_ id: 'rs1', members: [{_ id: 0, host: 'localhost: 100'}, {_ id: 1, host: 'localhost: 28011 '}, {_ id: 2, host: 'localhost: 28012'}]}
> Rs. initiate (config_rs );

4. view the status of the replica set and analyze the running indicators of the replica set ,:

OK.

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.