[MongoDB] Installing MONGODB configuration replica Set

Source: Internet
Author: User
Tags install mongodb

url:http://blog.csdn.net/hf81970/article/details/19643639

MongoDB's environment mainly includes standalone,replication and sharding.

    • StandAlone: Single-machine environment, general development and testing when used.
    • Replication: Master-slave structure, a primary, multiple secondary, may have arbitry.
      • After the primary is hung, a secondary will be elected as primary, similar to zookeeper.
      • Arbitry does not save data, just to dine. The election algorithm requires the number of nodes must be an odd number, if primary+secondary is not an odd number, it is necessary to use Arbitry dine.
      • Write data only in primary, read data by default also in primary, can be configured to read from secondary, you can choose the nearest node.
      • After the data is written successfully on primary, the operation will be recorded in Oplog, secondary will oplog copy the past, and then follow the operation again, there is data.
      • The data above primary and secondary guarantees eventual consistency and can be configured with write concern for writing, with several levels: write success on Primary, write to Oplog, write success, write to one/more/A/ After a few secondary think of writing success, and so on.
    • Sharding:share the structure of nothing, only a fraction of the data is stored on each machine. Mongod Server storage data, MONGOs server is responsible for routing read-write requests, metadata exists in the config database.

Because of the amount of data and the amount of machine, the project ended up with a primary, a secondary, a arbitry. My own development environment is Ubuntu, the test environment is CentOS. The 64-bit MongoDB is installed.

Installation on Ubuntu
Install Mongodb-10gen
installation on CentOS

Configure the Yum source to create the file:/etc/yum.repos.d/mongodb.repo

[Mongodb]name=MongoDB repositorybaseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/ gpgcheck=0enabled=1     

installation command:

Install Mongo-10gen Mongo-10gen-server
Configuration

Each machine above the configuration file/etc/mongod.conf modified to the following:

#数据库文件所在位置 (default) dbpath=/var/lib/mongo# log location (default) logpath=/var/log/mongo/mongod.log#pid location (default) Pidfilepath =/var/run/mongodb/mongod.pid#keyfile location, generated in the back (add) keyfile=/var/lib/mongo/key# port (default) port=27017 #每次启动后日志追加在后面, no new log file (default) logappend=true#用deamon方式启动 (add) fork=true#打开操作日志, For fault recovery and persistence (default) journal=true#replica set name (add) replset=test-set       

Run on each machine:

sudo mongod-f/etc/mongod.conf

Inside my environment, Primary ip:192.168.1.1,secondary ip:192.168.1.2,arbitary ip:192.168.1.3. Multiple MongoDB can be set to a different port on a single machine, I test it is also possible.

Run "MONGO" on primary, open the command line, set the replica setting:

Rs.initiate ({"_id" :"Test-set","Members": [ {"_id" :1,"Host" :"192.168.1.1"}, {"_id" :2,"Host" :"192.168.1.2"}, {"_id" :3, "host":  "192.168.1.3", arbiteronlytrue" }); { "info "config now saved locally. Should come online in about a minute.  " " ok1"   

After a successful history, he will elect primary and then view the status of replica set:

Test-set:primary>Rs.status () {"Set" :"Test-set","Date": Isodate ("2014-02-21t10:28:55z"),"MyState" :7,"Members": [ {"_id" :1,"Name" :"192.168.1.1:27017","Health" :1,"State" :1,"Statestr" :"PRIMARY","Uptime" :4086,"Optime": Timestamp (1392972480,1),"Optimedate": Isodate ("2014-02-21t08:48:00z"),"Lastheartbeat": Isodate ("2014-02-21t10:28:54z"),"Lastheartbeatrecv": Isodate ("2014-02-21t10:28:53z"),"Pingms" :0}, {"_id" :2,"Name" :"192.168.1.2:27017","Health" :1,"State" :2,"Statestr" :"Secondary","Uptime" :3997,"Optime": Timestamp (1392972480,1),"Optimedate": Isodate ("2014-02-21t08:48:00z"),"Lastheartbeat": Isodate ("2014-02-21t10:28:54z"),"Lastheartbeatrecv": Isodate ("2014-02-21t10:28:55z"),"Pingms" :0,"Syncingto" :"192.168.131.15:27017"}, {"_id" :3,"Name" :"192.168.1.3:27017", "health": 1state ": 7  statestr arbiter< Span style= "color: #800000;" > ", " uptime ": 5781 " self ": true}", "OK": 1}             

This allows the entire replica set to be configured successfully, or relatively simple.

Settings for KeyFile

KeyFile is used between the machine for authorization authentication, if not set KeyFile, in the Rs.initiate (), will be prompted to have other machines do not have ready, probably this meaning is not clear, anyway, there is an error ...

Online search for this error, a lot of explanation is that the server abnormal shutdown or MongoDB abnormal exit, will leave a lock file "/var/lib/mongo/mongo.lock", need to delete this lock file after the restart MongoDB. I tried this method to be ineffective for me.

Viewed the log file on a machine and found that there were other machines sending him messages, but that a key file would need to be configured on each machine. That's probably what it means, forget it.

Create a key file with the following statement:

741

The resulting string is stored in a text file, then the permissions of the file are chmod to 600 (if the permissions are too high, log will tell you that the permissions are too high), and then add "Keyfile=keyfile path" in the configuration, restart MongoDB on the line.

Issues with NUMA

The CPU of the test machine is NUMA, so the command line and log will have the following hint when running Mongod:

Warning:you is running on a NUMA machine. We suggest launching mongod like this-avoid performance problems:numactl–-interleave=all Mongod [other options]

The start command is then changed to:

 sudo numactl--interleave=all mongod-f/etc/mongod.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.