MongoDB replica set Creation

Source: Internet
Author: User

After reading the mongodb authoritative guide, it is more appropriate to use the replica set for read/write splitting, and the general system is enough to use it.

It is easy to find. If you do not describe it, you can only describe the key steps.

The two servers are 201 and 202 nodes, the two are initially configured on 202, and the other is added on 201.

Deploy two nodes first
202:
./Mongod -- dbpath./db1 -- port 10002 -- replSet blort/Server202: 10001
./Mongod -- dbpath./db -- port 10001 -- replSet blort/Server202: 10002

./Mongo Server202: 10001/admin
Db. runCommand ({"replSetInitiate": {"_ id": "blort", "members": [{"_ id": 1, "host": "Server202: 10001 "},{" _ id ": 2," host ":" Server202: 10002 "}]})
Db. _ adminCommand ("replSetGetStatus ");

Add a node
201:
./Mongod -- dbpath./db -- port 10001 -- replSet blort/Server202: 10002
202:
Rs. add ("Server201: 10002 ");

By default, the slave database cannot be queried. Execute the following statement to make the current slave database available for query and share the query load of the master database.
Db. getMongo (). setSlaveOk ()

The random machine automatically starts the script at/etc/rc. local.
Rm-rf/home/aircom/mongodb-linux-i686-2.0.6/bin/db/*. lock
Rm-rf/home/aircom/mongodb-linux-i686-2.0.6/bin/db1/*. lock
/Home/aircom/mongodb-linux-i686-2.0.6/bin/mongod -- dbpath/home/aircom/mongodb-linux-i686-2.0.6/bin/db -- port 10001 -- replSet blort/Server202: 10002 -- fork -- logpath/home/aircom/mongodb-linux-i686-2.0.6/bin/log/1001.log
/Home/aircom/mongodb-linux-i686-2.0.6/bin/mongod -- dbpath/home/aircom/mongodb-linux-i686-2.0.6/bin/db1 -- port 10002 -- replSet blort/Server202: 10001 -- fork -- logpath/home/aircom/mongodb-linux-i686-2.0.6/bin/log/1002.log

Modify the configuration, such as modifying the priority. You can use the priority to control the Tianji
Conf = rs. conf ()
Conf. members [0]. priority = 3
Conf. members [1]. priority = 2
Conf. members [2]. priority = 1
Conf. members [3]. priority = 0.5
Rs. reconfig (conf)

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.