"Mongodb" sharding Replica sets Shard cluster production environment installation and introduction!

Source: Internet
Author: User

System Environment: Centos 6.5

Official manual:http://docs.mongodb.org/manual/

See the information: MongoDB authoritative guide"MongoDB Combat" "deep learning mongodb"

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/47/BD/wKioL1P_H0fj-HlSAAEqqyVR3Fo773.jpg "title=" 1.png " alt= "Wkiol1p_h0fj-hlsaaeqqyvr3fo773.jpg"/>

As can be seen from the official topology above, sharding cluster members are composed of Shard,configserver,Router

Shard: Can be an instance, the official recommended production environment uses replica set Replica set

Config Server: For three hosts, when there are 1 or 2 server servers, for the user, the cluster is still readable, but the cluster will not be Chunk split and migration, Until normal recovery.

Router:Mongos Process, the number is not limited, it is recommended for one application server for only one Mongos process.

below I will build a simulation environment, note that in the actual production environment, each instance is a separate host, each config Server will be a separate host, do not fall into the logic of thinking.


Host Planning:

Host A (Shard1, consisting of three instances of replica sets): 10.1.2.11:2710110.1.2.11:2710210.1.2.11:27103 Host B (Shard2, consisting of three instances replica Sets): 10.1.2.12:2720110.1.2.12:2720210.1.2.12:27203 Host C: (three config server instances, one MONGOs instance) 10.1.2.10 : 2730110.1.2.10:2730210.1.2.10:2730310.1.2.10:27400 (MONGOs)


A,B host operation is basically consistent, here I write over the operation on a .

1.

Download and unzip Mongodb binary Source package!

Latest Mongodb Stable installation package Download:http://www.mongodb.org/downloads

Tar xzf mongodb-linux-x86_64-2.6.4.tgzmv Mongodb-linux-x86_64-2.6.4/usr/local/mongodb

2. Create a data directory for each instance:

Mkdir-p/data/shard1_1mkdir-p/data/shard1_1mkdir-p/data/shard1_1

3. Create Mongodb log and PID file directory

Mkdir/var/log/mongodbmkdir/var/run/mongodb

4. Create the Mongodb profile directory and configure the appropriate configuration file contents. (Production environment I recommend the configuration file to control the startup parameters!) This step, because I experiment each host opened a number of instances, there is no configuration files, if you are production environment, you can refer to the next! )

Cd/usr/local/mongodb/mkdir Etcvim etc/mongod.conf#filename:mongodb.conf#now Use options:fork = Trueport = 27101quiet = t Ruereplset = Sharding1dbpath =/data/mongodb Pidfilepath =/var/run/mongodb/mongod.pidlogpath =/var/log/mongodb/mongod . Loglogappend = Truejournal = True

5. Configure Global environment variables:

echo "path= $PATH:/usr/local/mongodb/bin" >>/etc/profile

execution . /etc/profile immediately enables the current user to take effect. This is intended to facilitate the implementation of MONGODB- related commands!

6. launch the instance:

Mongod--shardsvr--replset sharding1--port 27101--dbpath/data/shard1_1/--pidfilepath/var/run/mongodb/sharding1_1. Pid--logpath/var/log/mongodb/sharding1_1.log--logappend–fork mongod--shardsvr--replset sharding1--port 27102-- dbpath/data/shard1_2/--pidfilepath/var/run/mongodb/sharding1_2.pid--logpath/var/log/mongodb/sharding1_2.log-- Logappend–forkmongod--shardsvr--replset sharding1--port 27103--dbpath/data/shard1_3/--pidfilepath/var/run/ Mongodb/sharding1_3.pid--logpath/var/log/mongodb/sharding1_3.log--logappend–fork

7. Initialize the Shard1 Replica set(replica set):

# MONGO--port 27101MongoDB Shell version:2.6.4connecting to:127.0.0.1:27101/test> use adminswitched to DB admin>d B.runcommand ({"replsetinitiate": {... "_id": "Sharding1",... "Members": [... {"_id": 1, "host": "10.1.2.11:27101"},... {"_id": 2, "host": "10.1.2.11:27102"},... {"_id": 3, "host": "10.1.2.11:27103"},...]})  #执行后返回: {"info": "Config now saved locally. Shouldcome online in about a minute. "," OK ": 1}

8. Verify The Replica sets status:

Sharding1:primary> rs.status () {          "set":  " Sharding1 ",         " date ":  isodate (" 2014-08-28t08:29:45z "),           "MyState": 1,           "Members": [                    {                              "_id":  1,                              "name":  "10.1.2.11:27101",                               "Health": 1,                              "state":  1,                              "Statestr":  "PRIMARY",                               "Uptime": 577,                               "Optime":  timestamp (1409214151, 1),                               "Optimedate": isodate ("2014-08-28t08:22:31z"),                              "Electiontime" :  timestamp (1409214162, 1),                              "Electiondate" :  isodate ("2014-08-28t08:22:42z"),                              "Self":  true                    },                    {                              "_id": 2,                               "name":  "10.1.2.11:27102",                               "Health": 1,                              "state":  2,                               "Statestr":  "secondary",                               "Uptime": 431,                              "Optime":  Timestamp (1409214151, 1),                              "Optimedate":  Isodate ("2014-08-28t08:22:31z"),                              "Lastheartbeat":  isodate ("2014-08-28t08:29:45z"),                              " Lastheartbeatrecv ":  isodate (" 2014-08-28t08:29:43z "),                              "PingMs": 0,                               "Syncingto":  "10.1.2.11:27101"                     },                    {                               "_id": 3,                               "name":  "10.1.2.11:27103",                              "Health": 1,                               "State": 2,                               "Statestr":  "secondary",                              " Uptime ": 431,                              "Optime":  timestamp ( 1409214151, 1),                              "Optimedate":  isodate ("2014-08-28t08:22:31z"),                               "Lastheartbeat":  isodate ("2014-08-28t08:29:45z"),                               "Lastheartbeatrecv":  isodate ("2014-08-28t08:29:45z" ),                              "Pingms": 12,                               "Syncingto":  "10.1.2.11:27101"                     }         ],           "OK":  1}


B Host operation is basically consistent with a host, after configuring the Host B, then continue the following operation!


Host configuration on C:

1. Unzip the source package

Tar xzf mongodb-linux-x86_64-2.6.4.tgzmv Mongodb-linux-x86_64-2.6.4/usr/local/mongodb

2. Configure config and log directory:

Mkdir-p/data/config_1mkdir-p/data/config_2mkdir-p/data/config_3mkdir-p/var/log/mongodb

3. Configure Global environment variables:

echo "path= $PATH:/usr/local/mongodb/bin" >>/etc/profile

4. start the config Server instance:

Mongod--configsvr--dbpath/data/config_1/--port 27301--logpath/var/log/mongodb/dbconfig_1.log--logappend–fork Mongod--configsvr--dbpath/data/config_2/--port 27302--logpath/var/log/mongodb/dbconfig_2.log--logappend–fork Mongod--configsvr--dbpath/data/config_3/--port 27303--logpath/var/log/mongodb/dbconfig_3.log--logappend–fork

5. launch The MONGOs instance:

MONGOs--configdb10.1.2.10:27301,10.1.2.10:27302,10.1.2.10:27303--port 27400--logpath/var/log/mongodb/mongos.log --logappend–fork

Note: The production environment MONGOs is recommended to be controlled by a configuration file, for example:

#mongos. Conf#options:port =27400fork =truelogappend= truelogpath=/var/log/mongodb/mongos.logpidfilepath=/var/run/ mongos.pidconfigdb= 10.1.2.10:27301,10.1.2.10:27302,10.1.2.10:27303

6. Log in to the MONGOs process and configure Shard Cluster:

# MONGO--port 27400 adminmongodb Shell version:2.6.4connecting to:127.0.0.1:27400/adminmongos>mongos> Db.runcommand ({addshard: "sharding1/10.1.2.11:27101,10.1.2.11:27102,10.1.2.11:27103"}); {"shardadded": "Sharding1", "OK": 1}mongos>db.runcommand ({addshard: "sharding2/ 10.1.2.12:27201,10.1.2.12:27202,10.1.2.12:27203 "}); {"shardadded": "Sharding2", "OK": 1}

7. Verify the sharding cluster status:

Mongos> sh.status ()--- Sharding Status --- sharding version: {           "_id": 1,           "Version": 4,          "Mincompatibleversion":  4,           "CurrentVersion": 5,           "Clusterid":  objectid ("53fee749becfed3ca6de7051")} shards:          {   "_id"  :  "Sharding1",   "host"  : " sharding1/10.1.2.11:27101,10.1.2.11:27102,10.1.2.11:27103 " }          {   "_id"  :  "Sharding2",   "host"  : "sharding2/ 10.1.2.12:27201,10.1.2.12:27202,10.1.2.12:27203 " } databases:          {   "_id"  :&nbSP; " Admin ",  " partitioned " : false,  " primary " : " config " }          {   "_id"  :  "test",   "partitioned " : false,  " PRIMARY " : " Sharding2 " } mongos>

At this point, all the environmental establishment completed!


Attached: Here is a little bit about the operation of the Shard:

Activate database shard: Db.runcommand ({enablesharding: "dbname"})//Here to operate under the Admin database or sh.enablesharding ("dbname")//This can be global operation Collection Enable Sharding (select a Shard key here, refer to the official website for details): Db.runcommand ({shardcollection: "Dbname.collectionname", key{_id:1})/ Ibid. or Sh.shardcollection ("Records.active", {a: "hashed"})


This article is from the "you insist on _it blog" blog, please be sure to keep this source http://fdgui.blog.51cto.com/3484207/1546290

"Mongodb" sharding Replica sets Shard cluster production environment installation and introduction!

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.