MongoDB Standalone Configuration Shard Shard

Source: Internet
Author: User
Tags mongodb version


#####################################################

Operating system:

[Email protected] logs]# Cat/etc/issuecentos release 6.4 (Final) Kernel \ r on a \m[[email protected] logs]# uname-r2.6. 32-358.el6.x86_64

MongoDB version:

[Email protected] logs]# Mongo-versionmongodb Shell version:2.6.11

1: Directory Planning

[Email protected] opt]# mkdir/opt/{shard1,shard2,configsvr,logs,mongos}[[email protected] opt]# tree/opt//opt/├── CONFIGSVR├──LOGS├──MONGOS├──SHARD1└──SHARD25 directories, 0 files

2:shard1-20000 configuration file

[Email protected] opt]# cat/etc/shard1.conf logpath=/opt/logs/shard1.loglogappend=truefork = Trueport = 20000dbpath=/ Opt/shard1pidfilepath =/opt/shard1/20000.pid

Start shard1-20000

[[email protected] opt]# mongod-f/etc/shard1.conf about to fork child process, waiting until server was ready for connect Ions.forked Process:3341child Process started successfully, parent Exiting[[email protected] opt]# Netstat-ntpl|grep 200 0tcp 0 0 0.0.0.0:20000 0.0.0.0:* LISTEN 3341/mongod


3:shard2-20001 configuration file

[Email protected] opt]# cat/etc/shard2.conf logpath=/opt/logs/shard2.loglogappend=truefork = Trueport = 20001dbpath=/ Opt/shard2pidfilepath =/opt/shard2/20001.pid

Start shard2-20001

[[email protected] opt]# mongod -f /etc/ Shard2.conf            about to fork  child process, waiting until server is ready for  connections.forked process: 3360child process started successfully, parent  exiting[[email protected] opt]# netstat -ntpl|grep 20001              tcp        0       0 0.0.0.0:20001                0.0.0.0:*                    listen      3360/mongod 

4:configsvr-20002 configuration file

[Email protected] opt]# cat/etc/configsvr.conf logpath=/opt/logs/configsvr.loglogappend=truefork = Trueport = 20002dbpath=/opt/configsvrpidfilepath =/opt/configsvr/20002.pidconfigsvr = True

Start configsvr-20002

[[email protected] opt]# mongod-f/etc/configsvr.conf about to fork child process, waiting until server was ready for Conn  Ections.forked Process:3377child Process started successfully, parent Exiting[[email protected] opt]# Netstat-ntpl|grep 20002tcp 0 0 0.0.0.0:20002 0.0.0.0:* LISTEN 3377/mongod

5:mongos-20003 configuration file

[Email protected] logs]# cat/etc/mongos.conf logpath=/opt/logs/mongos.loglogappend=truefork = Trueport = 20003pidfilepath =/opt/mongos/20003.pidconfigdb = 192.168.75.130:20002

mongos-20003 start

[[email protected] logs]# mongos -f /etc/mongos.conf 2015-12-15t09:57:42.222+ 0800 warning: running with 1 config server should be done  only for testing purposes and is not recommended for  productionabout to fork child process, waiting until server is  ready for connections.forked process: 3452child process started  successfully, parent exiting[[email protected] logs]# netstat -ntpl|grep  20003tcp        0      0  0.0.0.0:20003               0.0.0.0 :*                     listen      3452/mongos 

6: Login MONGOs

[Email protected] logs]# MONGO--port 20003MongoDB Shell version:2.6.11connecting To:127.0.0.1:20003/testwelcome to the MongoDB Shell. For interactive help, type ' help '. For more comprehensive documentation, see http://docs.mongodb.org/Questions? Try the Support group Http://groups.google.com/group/mongodb-user

View status

mongos> sh.status ()---sharding status---sharding version: {"_id": 1, "Version": 4, "mincom Patibleversion ": 4," CurrentVersion ": 5," Clusterid ": ObjectId (" 566f73969b960c2046e49eba ")} Shards:dat Abases: {"_id": "admin", "partitioned": false, "PRIMARY": "Config"}

7: Add Shard Shard Machine

Mongos> sh.addshard ("192.168.75.130:20000") {  "shardadded"  :  "shard0000",  "OK"  : 1 }mongos> sh.addshard ("192.168.75.130:20001") {  "shardAdded"  :  " shard0001 ", " OK " : 1 }mongos> sh.status ()--- Sharding Status ---    sharding version: {         "_id"  :  1,         "Version"  : 4,          "Mincompatibleversion"  : 4,         " CurrentVersion " : 5,        " Clusterid " : objectid ("566f73969b960c2046e49eba")}   shards:        {   "_id"  :  "shard0000",    "Host"  :  "192.168.75.130:20000"  }        {& NBsp;  "_id"  :  "shard0001",   "host"  :  "192.168.75.130:20001"  }   databases:        {   "_id"  :  "admin",   " Partitioned " : false,  " primary " : " config " }

The library with the Shard shard enabled is named ' Zxl ', which is the library

Mongos> sh.enablesharding ("Zxl") {"OK": 1}

Set the name and field of the collection, automatically indexed by default, ZXL library, haha collection

Mongos> sh.shardcollection ("Zxl.haha", {age:1, name:1}) {"collectionsharded": "Zxl.haha", "OK": 1}

View status

Mongos> sh.status ()--- Sharding Status ---   sharding version:  {         "_id"  : 1,          "Version"  : 4,         " Mincompatibleversion " : 4,        " CurrentVersion " :  5,         "Clusterid"  : objectid (" 566f73969b960c2046e49eba ")}  shards:        {  " _ ID " : " shard0000 ",  " host " : " 192.168.75.130:20000 " }         {   "_id"  :  "shard0001",   "host"  :  " 192.168.75.130:20001 " }  databases:        {    "_id"  :  "admin",   "partitioned"  : false,   "PRIMARY"  :  "config"  }        {   " _id " : " test ",  " partitioned " : false,  " primary " : " shard0000 " }        {  " _id " : " ZXL ",    "Partitioned"  : true,   "primary"  :  "shard0000"  }                 zxl.haha                          shard key: {  "Age"  : 1,  "name"  : 1 }                          chunks:                                 shard0000        1                         {  "Age"  : {  "$minKey"  :  1 },  "name"  : {  "$minKey"  : 1 } } -->> {   "Age"  : {  "$maxKey"  : 1 },  "name"  : {  "$maxKey"  :  1 } } on : shard0000 timestamp (1, 0)  mongos>  dbtestmongos> show dbsadmin    (empty) config  0.016gbzxl      0.078gbmongos> use zxlswitched to db zxlmongos> dbzxl

8: Simulate inserting data into the Haha collection

Mongos> for (i=1;i<=10000;i++) Db.haha.insert ({name: ' User ' +i, Age: (i%150)}) Writeresult ({"ninserted": 1})

Post-insert Data View status

Mongos> sh.status ()--- Sharding Status ---   sharding version:  {         "_id"  : 1,          "Version"  : 4,         " Mincompatibleversion " : 4,        " CurrentVersion "&NBSP;:  5,         "Clusterid"  : objectid (" 566f73969b960c2046e49eba ")}  shards:        {  " _ ID " : " shard0000 ",  " host " : " 192.168.75.130:20000 " }         {   "_id"  :  "shard0001",   "host"  :  " 192.168.75.130:20001 " }  databases:        {    "_id"  :  "admin",   "partitioned"  : false,   "PRIMARY"  :  "config"  }        {   " _id " : " test ",  " partitioned " : false,  " primary " : " shard0000 " }        {  " _id " : " ZXL ",    "Partitioned"  : true,   "primary"  :  "shard0000"  }                 zxl.haha                          shard key: {  "Age"  : 1,  "name"  : 1 }                          chunks:                                 shard0001        2                                  shard0000       1                         {  "Age" &NBSP;:  {  "$minKey"  : 1 },  "name"  : {  "$minKey" &NBSP;:&NBSP;1&NBSP;  } -->> {  "Age"  : 1,  "name"  :  "user1" &NBSP;}&NBSP;ON&NBSP;:  shard0001 timestamp (2, 0)                           {  "Age"  : 1 ,  "Name"  : "User1"  } -->> {  "age"  : 149,  "name"  :  "user899" &NBSP;}  on : shard0000 timestamp (3, 1)                           {  "Age"  : 149,  "name"  :  "user899"  } -->> {  "Age"  : {   "$maxKey"  : 1 },  "name"  : {  "$maxKey" &NBSP;:&NBSP;1&NBSP;}&NBSP;  on : shard0001 timestamp (3, 0)

9: View age greater than

Mongos> db.haha.find ({age: {$gt:  88}}) {  "_id"  : objectid (" 566f7509ebd7512bf6df23f7 "), " name " : " user899 ", " Age " : 149 }{ " _id "  : objectid ("566f750aebd7512bf6df24e7"),  "name"  :  "user1139",  "Age"  :  89 }{  "_id"  : objectid ("566f7511ebd7512bf6df439b"),  "name"  :  "user8999",   "Age"  : 149 }{  "_id"  : objectid ("566f750aebd7512bf6df257d"),  "name"  :  "user1289",  "Age"  : 89 }{  "_id"  : objectid (" 566f7511ebd7512bf6df4431 "), " name " : " user9149 ", " Age " : 149 }{ " _id "  : objectid ("566f750aebd7512bf6df2613"),  "name"  :  "user1439",  "Age"  :  89 }{  "_id"  : objectid ("566f7511ebd7512bf6df44c7"),  "name"  :  "user9299",   "Age"  : 149 }{  "_id"  :  ObjectId ("566f750aebd7512bf6df26a9"),  "name"  :  "user1589",  "Age"  : 89 }{   "_id"  : objectid ("566f7511ebd7512bf6df455d"),  "name"  :  "user9449",  "age"  : 149 }{  "_id"  : objectid ("566f750aebd7512bf6df273f"),  "name"  :  "user1739",  "Age"  : 89 }{  "_id"  : objectid ("566f7511ebd7512bf6df45f3"),   "name"  :  "user9599",  "Age"  : 149 }{  "_id"  : objectid (" 566f750aebd7512bf6df27d5 "), " name " : " user1889 ", " Age " : 89 }{ " _id "  : objectid ("566f7511ebd7512bf6df4689"),  "name"  :  "user9749",  "Age"  :  149 }{  "_id"  : objectid ("566f750aebd7512bf6df286b"),  "name"  :  "user2039",   "Age"  : 89 }{  "_id"  : objectid ("566f7511ebd7512bf6df471f"),  "name"  :  "user9899", "Age"  : 149 }{  "_id"  : objectid ("566f750bebd7512bf6df2901"),  "name" &NBSP;:   "user2189",  "Age"  : 89 }{  "_id"  : objectid ("566f750bebd7512bf6df2997" ),  "name"  :  "user2339",  "Age"  : 89 }{  "_id"  : objectid (" 566f7509ebd7512bf6df2163 "), " name " : " user239 ", " Age " : 89 }{ " _id "  : objectid ("566f750bebd7512bf6df2a2d"),  "name"  :  "user2489",  "Age"  :  89 }{  "_id"  : objectid ("566f750bebd7512bf6df2ac3"),  "name"  :  "user2639",   "Age"  : 89 }Type  "it"  for more

The above is the MongoDB shard


This article is from the "Village Boys" blog, please make sure to keep this source http://noodle.blog.51cto.com/2925423/1748149

MongoDB Standalone Configuration Shard Shard

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.