MongoDB Shard Cluster

Source: Internet
Author: User

MongoDB clusters   Components: MONGOs: Request distribution config server Shard Shard data server   Three machine 192.168.174.128192.168.174.129192.168.174.130 Server Planning    port assignment:  mongos:20000config:21000shard1:27001shard2:27002shard3:27003  server needs synchronization time, otherwise the test does not pass  128 machine operation  1, download official website: HTTPS://WWW.MONGODB.COM/DOWNLOAD-CENTER#COMMUNITY&NBSP;2, decompression     tar-xf mongodb-linux-x86_64- Rhel70-3.6.5.tgz && MV mongodb-linux-x86_64-rhel70-3.6.5/usr/local/mongodb 3, plus environment variable, easy to operate (3 machines)      vim/etc/profile        export PATH= $PATH:/usr/local/ Mongodb/bin    source/etc/profile 4, create the desired directory      mkdir-p/usr/ Local/mongodb/{conf,config/{data,log},shard1/{data,log},shard2/{data,log},shard3/{data,log},mongos/log} 5 , writing configuration Files config.conf, shard1.conf, shard2.conf, shard3.conf, mongos.conf ====================================== ==============================================vim/usr/local/mongodb/conf/confiG.confsystemlog:  destination:file  logappend:true  path:/usr/local/mongodb/ Config/log/configsvr.logstorage:  dbpath:/usr/local/mongodb/config/data  journal:     enabled:trueprocessmanagement:  fork:true  pidfilepath:/usr/local/ Mongodb/config/log/configsvr.pid  timezoneinfo:/usr/share/zoneinfonet:  port:21000   bindip:192.168.174.128  maxincomingconnections:20000replication:  replsetname: configssharding:  clusterrole:configsvr    ===================================== =================================================    vim/usr/local/mongodb/conf/ Shard1.confsystemlog:  destination:file  logappend:true  path:/usr/local/mongodb /shard1/log/shard1.logstorage:  dbpath:/usr/local/mongodb/shard1/data  journal:     enabled:tRueprocessmanagement:  fork:true  pidfilepath:/usr/local/mongodb/shard1/log/shard1.pid   timezoneinfo:/usr/share/zoneinfonet:  port:27001  bindip:192.168.174.128   maxincomingconnections:20000replication:  replsetname:shard1sharding:  clusterrole: shardsvr=======================================================================================vim/usr/local/ Mongodb/conf/shard2.confsystemlog:  destination:file  logappend:true  path:   /usr/local/mongodb/shard2/log/shard2.logstorage:  dbpath:  /usr/local/mongodb/ Shard2/data  journal:    enabled:trueprocessmanagement:  fork:true   pidfilepath:  /usr/local/mongodb/shard2/log/shard2.pid  timezoneinfo:/usr/ Share/zoneinfonet:  port:27002  bindip:192.168.174.128  maxincomingconnections: 20000replication:  replsetname:shard2sharding:  clusterrole:shardsvr=================================== ======================================================vim/usr/local/mongodb/conf/shard3.confsystemlog:   destination:file  logappend:true  path:  /usr/local/mongodb/shard3/log/ shard3.logstorage:  dbpath:  /usr/local/mongodb/shard3/data  journal:     enabled:trueprocessmanagement:  fork:true  pidfilepath:  /usr/ Local/mongodb/shard3/log/shard3.pid  timezoneinfo:/usr/share/zoneinfonet:  port:27003   bindip:192.168.174.128  maxincomingconnections:20000replication:  replsetname: shard3sharding:  clusterrole:shardsvr=============================================================== ============================vim/usr/local/mongodb/conf/mongos.confsystemlog:  destination:file   logaPpend:true  path:/usr/local/mongodb/mongos/log/mongos.logprocessmanagement:  fork:true   pidfilepath:/usr/local/mongodb/mongos/log/mongos.pid  timezoneinfo:/usr/share/ Zoneinfonet:  port:20000  bindip:192.168.174.128  maxincomingconnections: 20000sharding:  configdb:configs/192.168.174.128:21000,192.168.174.130:21000,192.168.174.131:21000== ========================================================================================== 6, The MongoDB directory SCP to its two servers     scp-r/usr/local/mongodb 192.168.174.130:/usr/local/mongodb     scp-r/usr/local/mongodb 192.168.174.131:/usr/local/mongodb     ** Note: 130 and 131 nodes, the Bindip in the configuration file need to be modified to the corresponding ip 7, create the user, authorize (three machines)     useradd mongod     chown-r mongod:mongod/usr/local/mongodb/ ===================================================== =======================8, boot Configuration server (3 units))     mongod-f/usr/local/mongodb/conf/config.conf 9, initialize the replica set (login to any instance)       #连接         mongo 192.168.174.128:21000      #初始化副本集         rs.initiate (  {     _id: "Configs",     configsvr:true,    members: [       {_id:0, Host: "192.168.174.128:21000"},      {_id:1, Host: "192.168.174 .130:21000 "},      {_id:2, Host:" 192.168.174.131:21000 "}&NBSP;&NBSP;&NBSP;&NBSP;]   })       #查看状态     rs.status (); ========================= =====================================================10, start Shard1, Shard2, Shard3 (3 units)      Mongod-f/usr/local/mongodb/conf/shard1.conf    mongod-f/usr/local/mongodb/conf/shArd2.conf    mongod-f/usr/local/mongodb/conf/shard3.conf 11, initializing the replica set (on a single execution)        #连接         mongo 192.168.174.130:27001      #初始化副本集         rs.initiate (  {     _id: "Shard1",     members: [      {_id:0, Host: " 192.168.174.128:27001 ", priority:2},      {_id:1, Host:" 192.168.174.130:27001 ", priority:1},      {_id:2, Host: "192.168.174.131:27001",arbiteronly:true}     ]  })      #查看状态     rs.status ();       #连接         mongo 192.168.174.131:27002      #初始化副本集         rs.initiate (  {     _id: "Shard2",     members: [      {_id:0, Host: " 192.168.174.128:27002 ", arbiteronly:true},      {_id:1, Host:" 192.168.174.130:27002 ", priority:2},      {_id:2, Host:" 192.168.174.131:27002 ", PRIORITY:1}&NBSP;&NBSP;&NBSP;&NBSP;]&NBSP;&NBSP,})      #查看状态      Rs.status ();      #连接         mongo 192.168.174.128:27003     #初始化副本集          Rs.initiate (  {    _id: "Shard3",     members: [       {_id:0, Host: "192.168.174.128:27003", priority:1},      {_ Id:1, Host: "192.168.174.130:27003", arbiteronly:true},      {_id:2, Host: "192.168.1 74.131:27003 ", priority:2}    ]  })       #查看状态     rs.status (); ======= ========================================================================12, Start MONGOs (3 sets)      mongos-f/usr/local/mongodb/conf/mongos.conf 13, enable sharding (login to any instance)          mongo 192.168.174.128:20000                 use  admin                 sh.addshard ("shard1/ 192.168.174.128:27001,192.168.174.130:27001,192.168.174.130:27001 ");         sh.addshard ("shard2/192.168.174.128:27002,192.168.174.130:27002,192.168.174.130:27002");         sh.addshard ("shard3/ 192.168.174.128:27003,192.168.174.130:27003,192.168.174.130:27003 ");              #查看集群状态         sh.status ();  ============================= ==================================================&NBSP;14, Test                   Set Chunk size              use config             Db.settings.save ({"_id": "Chunksize", "Value": 1})               #为方便测试设为1M, otherwise you need to insert large amounts of data to shard storage           Login              mongo 192.168.127.128:20000          Specify TestDB Shard effective              Use Admin;            db.runcommand ({enablesharding : "TestDB"});          Specifies the collection and slice keys that require sharding              db.runcommand ({shardcollection: "Testdb.table1", key: {id:1}});                 use testdb;          inserting Data             for (var i = 1; i < = 10000; i++) Db.table1.save ({id:i, "test1": "Testval1"});         view is a shard case                 db.table1.stats ();             can see that the data is divided into 3 shards with the respective number of shards: Shard1 "Count": 42183,shard2 " Count ": 38937,shard3" Count ": 18880. It's done!   Start shutdown      mongodb boot sequence is to start the configuration server first, start the Shard, and finally start the mongos.          mongod-f/usr/local/mongodb/conf/conFig.conf        mongod-f/usr/local/mongodb/conf/shard1.conf         mongod-f/usr/local/mongodb/conf/shard2.conf         mongod-f/usr/local/mongodb/conf/shard3.conf         mongos-f/usr/local/mongodb/conf/mongos.conf  off, directly killall kill all processes (test use)       Pkill MONGO

MongoDB Shard Cluster

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.