Linux is the installation configuration MongoDB replica set step

Source: Internet
Author: User
Tags install mongodb mongodb

First step, install MongoDB to each server

Prepare more than 3 MongoDB servers and do the following on each platform

1, download MongoDB, extract and move to/usr/local/mongodb directory
(if wget is not installed, please yum install wget or apt-get install wget)
It is possible to download a Web server from a local area network, and then go on downloading from this server.

such as: Wget-c http://10.0.0.123/mongodb-linux-x86_64-2.6.5.tgz

Wget-c https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.5.tgz
Tar zxvf mongodb-linux-x86_64-2.6.5.tgz
MV Mongodb-linux-x86_64-2.6.5/usr/local/mongodb
2, the establishment of MONGODB database (data), logs (log) folder.

Mkdir-p/home/mongodb/data/home/mongodb/log
3, set the configuration file:

Vi/usr/local/mongodb/mongo.conf
Paste the following to this file: Wq Save and exit.

Systemlog:
Destination: "File"
Path: "/home/mongodb/log/mongo.log"
Logappend:true
Storage
Journal
Enabled:true
DBPath: "/home/mongodb/data"
Directoryperdb:true
Processmanagement:
Fork:true
Pidfilepath: "/usr/local/mongodb/mongo.pid"
Net
port:27017
http
Enabled:true
Restinterfaceenabled:true
Replication
Replsetname: "Replica_name_must_be_the_same"
Specific configuration parameters can refer to the official documentation:
http://docs.mongodb.org/manual/reference/configuration-options/
Note Spaces and indents
Available conf files
wget http://xclient.info/assets/mongodb/mongo.conf

4. Run MongoDB Process

/usr/local/mongodb/bin/mongod--config/usr/local/mongodb/mongo.conf
The first start here may be slower because you want to create a database file

5. Set Boot up

Vi/etc/rc.d/rc.local
Paste the following command in, save exit

/usr/local/mongodb/bin/mongod--config/usr/local/mongodb/mongo.conf
First STEP work Ready!!!

Step two, set the replica set.

1, open the MONGO on the server that you want to set as the primary database

/usr/local/mongodb/bin/mongo
2. Initialization configuration

Rs.initiate ()
Rs.conf ()
You'll see that you've become the master node:P rimary> is the name of the replica set

3. Add members

Rs.add ("10.0.0.101:27017")
Rs.add ("10.0.0.102:27017")
......
To add a quorum node, the command is:

Rs.addarb ("10.0.0.111:27017")
Note: When the number of servers is even, one additional quorum node needs to be added, that is, the total number of servers for the replica set must be odd.
About the quorum node, more can Google

4, set from the database to read
Perform the following on each from the server:

/usr/local/mongodb/bin/mongo
Db.getmongo (). Setslaveok ()
You can also use the/usr/local/mongodb/bin/mongo--host 10.0 0.101来 Connection on the primary server to set from the server (10.0.0.101 from server IP)

At this point, the MongoDB replica set configuration is complete.

Here are some other actions that might be used

Set Priority

Set the server _id to 2 as the primary server.

CFG = rs.conf ()
cfg.members[0].priority = 1
cfg.members[1].priority = 1
Cfg.members[2].priority = 2
Rs.reconfig (CFG)
Set the primary server to be from the server

Rs.stepdown ()
Resetting the database IP address

Run MONGO on the primary server, and then execute

CFG = rs.conf ()
Cfg.members[n].host= ' New_host_name:prot '
Rs.reconfig (CFG)
To reset the primary server IP, first demote the primary server, and then perform the above action on the new primary server.

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.