{"id":583,"date":"2011-03-16T01:12:05","date_gmt":"2011-03-15T17:12:05","guid":{"rendered":"http:\/\/www.strongd.net\/?p=583"},"modified":"2011-03-16T01:12:05","modified_gmt":"2011-03-15T17:12:05","slug":"%e9%85%8d%e7%bd%aemongodb%e5%88%86%e7%89%87%e7%be%a4%e9%9b%86sharding-cluster","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=583","title":{"rendered":"\u914d\u7f6emongodb\u5206\u7247\u7fa4\u96c6(sharding cluster)"},"content":{"rendered":"<h1><\/h1>\n<p>&nbsp;<\/p>\n<h3>Sharding cluster\u4ecb\u7ecd<\/h3>\n<p>\u8fd9\u662f\u4e00\u79cd\u53ef\u4ee5\u6c34\u5e73\u6269\u5c55\u7684\u6a21\u5f0f\uff0c\u5728\u6570\u636e\u91cf\u5f88\u5927\u65f6\u7279\u7ed9\u529b\uff0c\u5b9e\u9645\u5927\u89c4\u6a21\u5e94\u7528\u4e00\u822c\u4f1a\u91c7\u7528\u8fd9\u79cd\u67b6\u6784\u53bb\u6784\u5efamonodb\u7cfb\u7edf\u3002<\/p>\n<p>\u8981\u6784\u5efa\u4e00\u4e2a MongoDB Sharding Cluster\uff0c\u9700\u8981\u4e09\u79cd\u89d2\u8272\uff1a<\/p>\n<p>Shard Server: mongod \u5b9e\u4f8b\uff0c\u7528\u4e8e\u5b58\u50a8\u5b9e\u9645\u7684\u6570\u636e\u5757\uff0c\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u4e2d\u4e00\u4e2ashard server\u89d2\u8272\u53ef\u7531\u51e0\u53f0\u673a\u5668\u7ec4\u4e2a\u4e00\u4e2arelica set\u627f\u62c5\uff0c\u9632\u6b62\u4e3b\u673a\u5355\u70b9\u6545\u969c<\/p>\n<p>Config Server: mongod \u5b9e\u4f8b\uff0c\u5b58\u50a8\u4e86\u6574\u4e2a Cluster Metadata\uff0c\u5176\u4e2d\u5305\u62ec chunk \u4fe1\u606f\u3002<\/p>\n<p>Route Server: mongos \u5b9e\u4f8b\uff0c\u524d\u7aef\u8def\u7531\uff0c\u5ba2\u6237\u7aef\u7531\u6b64\u63a5\u5165\uff0c\u4e14\u8ba9\u6574\u4e2a\u96c6\u7fa4\u770b\u4e0a\u53bb\u50cf\u5355\u4e00\u6570\u636e\u5e93\uff0c\u524d\u7aef\u5e94\u7528\u53ef\u4ee5\u900f\u660e\u4f7f\u7528\u3002<\/p>\n<p>Sharding\u67b6\u6784\u56fe:<\/p>\n<p><a href=\"http:\/\/b55.photo.store.qq.com\/http_imgload.cgi?\/rurl4_b=5ec8ad90eb08584afbddc3be2e657eea1382a0a99d49fe5c28a96e3576fd46a7f5c39a137a9a9c828fc97e1d4a52e2507f955d6df5f330bd379a282e52ccc6fdd1b094b0e8016f21d050d3cf4e867a5587acdd93&amp;a=18&amp;b=55\" target=\"_blank\"><\/a><\/p>\n<p><a href=\"http:\/\/b55.photo.store.qq.com\/http_imgload.cgi?\/rurl4_b=5ec8ad90eb08584afbddc3be2e657eea1382a0a99d49fe5c28a96e3576fd46a7f5c39a137a9a9c828fc97e1d4a52e2507f955d6df5f330bd379a282e52ccc6fdd1b094b0e8016f21d050d3cf4e867a5587acdd93&amp;a=18&amp;b=55\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"1\" src=\"http:\/\/b55.photo.store.qq.com\/http_imgload.cgi?\/rurl4_b=5ec8ad90eb08584afbddc3be2e657eea1382a0a99d49fe5c28a96e3576fd46a7f5c39a137a9a9c828fc97e1d4a52e2507f955d6df5f330bd379a282e52ccc6fdd1b094b0e8016f21d050d3cf4e867a5587acdd93&amp;a=18&amp;b=55\" alt=\"\" width=\"668\" height=\"418\" \/><\/a><\/p>\n<h3>\u672c\u4f8b\u5b9e\u9645\u73af\u5883\u67b6\u6784<\/h3>\n<p>\u672c\u4f8b\u67b6\u6784\u793a\u4f8b\u56fe\uff1a<\/p>\n<p><a href=\"http:\/\/b59.photo.store.qq.com\/http_imgload.cgi?\/rurl4_b=5ec8ad90eb08584afbddc3be2e657eeae72a582867912f27866233ee13eac52d857a2d0923a6cd44bd3d6960d9ff56d6638fefeb6950eb64336e8b7803d81664560905337fa4b2b5f0575e1532e59fdf1bd1a130&amp;a=54&amp;b=59\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" title=\"mongodb-2\" src=\"http:\/\/b59.photo.store.qq.com\/http_imgload.cgi?\/rurl4_b=5ec8ad90eb08584afbddc3be2e657eeae72a582867912f27866233ee13eac52d857a2d0923a6cd44bd3d6960d9ff56d6638fefeb6950eb64336e8b7803d81664560905337fa4b2b5f0575e1532e59fdf1bd1a130&amp;a=54&amp;b=59\" alt=\"\" width=\"662\" height=\"377\" \/><\/a><\/p>\n<ol>\n<li>\u5206\u522b\u57283\u53f0\u673a\u5668\u8fd0\u884c\u4e00\u4e2amongod\u5b9e\u4f8b\uff08\u79f0\u4e3amongod shard11\uff0cmongod shard12\uff0cmongod shard13\uff09\u7ec4\u7ec7replica set1\uff0c\u4f5c\u4e3acluster\u7684shard1<\/li>\n<li>\u5206\u522b\u57283\u53f0\u673a\u5668\u8fd0\u884c\u4e00\u4e2amongod\u5b9e\u4f8b\uff08\u79f0\u4e3amongod shard21\uff0cmongod shard22\uff0cmongod shard23\uff09\u7ec4\u7ec7replica set2\uff0c\u4f5c\u4e3acluster\u7684shard2<\/li>\n<li>\u6bcf\u53f0\u673a\u5668\u8fd0\u884c\u4e00\u4e2amongod\u5b9e\u4f8b\uff0c\u4f5c\u4e3a3\u4e2aconfig server<\/li>\n<li>\u6bcf\u53f0\u673a\u5668\u8fd0\u884c\u4e00\u4e2amongs\u8fdb\u7a0b\uff0c\u7528\u4e8e\u5ba2\u6237\u7aef\u8fde\u63a5<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"601\">\n<tbody>\n<tr>\n<td width=\"123\"><strong>\u4e3b\u673a<\/strong><strong> <\/strong><\/td>\n<td width=\"165\"><strong>IP<\/strong><\/td>\n<td width=\"313\"><strong>\u7aef\u53e3\u4fe1\u606f<\/strong><\/td>\n<\/tr>\n<tr>\n<td width=\"123\">Server1<\/td>\n<td width=\"165\">10.1.1.1<\/td>\n<td width=\"313\">mongod shard11:27017<br \/>\nmongod shard12:27018<br \/>\nmongod config1:20000<br \/>\nmongs1:30000<\/td>\n<\/tr>\n<tr>\n<td width=\"123\">Server2<\/td>\n<td width=\"165\">10.1.1.2<\/td>\n<td width=\"313\">mongod shard12:27017<br \/>\nmongod shard22:27018<br \/>\nmongod config2:20000<br \/>\nmongs2:30000<\/td>\n<\/tr>\n<tr>\n<td width=\"123\">Server3<\/td>\n<td width=\"165\">10.1.1.3<\/td>\n<td width=\"313\">mongod shard13:27017<br \/>\nmongod shard23:27018<br \/>\nmongod config3:20000<br \/>\nmongs3:30000<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h3>\u8f6f\u4ef6\u51c6\u5907<\/h3>\n<p>\u8f6f\u4ef6\u51c6\u5907<br \/>\n1.\u00a0\u521b\u5efa\u7528\u6237<br \/>\ngroupadd -g 20001 mongodb<br \/>\nuseradd -u 20001 -g mongodb mongodb<br \/>\npasswd mongodb<\/p>\n<p>2.\u00a0\u5b89\u88c5monodb\u8f6f\u4ef6<br \/>\nsu \u2013 mongodb<br \/>\ntar zxvf mongodb-linux-x86_64-1.7.2.tar<br \/>\n\u5b89\u88c5\u597d\u540e\uff0c\u76ee\u5f55\u7ed3\u6784\u5982\u4e0b\uff1a<br \/>\n$ tree mongodb-linux-x86_64-1.7.2<br \/>\nmongodb-linux-x86_64-1.7.2<br \/>\n|\u2013 GNU-AGPL-3.0<br \/>\n|\u2013 README<br \/>\n|\u2013 THIRD-PARTY-NOTICES<br \/>\n`\u2013 bin<br \/>\n|\u2013 bsondump<br \/>\n|\u2013 mongo<br \/>\n|\u2013 mongod<br \/>\n|\u2013 mongodump<br \/>\n|\u2013 mongoexport<br \/>\n|\u2013 mongofiles<br \/>\n|\u2013 mongoimport<br \/>\n|\u2013 mongorestore<br \/>\n|\u2013 mongos<br \/>\n|\u2013 mongosniff<br \/>\n`\u2013 mongostat<br \/>\n1 directory, 14 files<\/p>\n<p>3.\u00a0\u521b\u5efa\u6570\u636e\u76ee\u5f55<br \/>\n\u6839\u636e\u672c\u4f8bsharding\u67b6\u6784\u56fe\u6240\u793a\uff0c\u5728\u5404\u53f0sever\u4e0a\u521b\u5efashard\u6570\u636e\u6587\u4ef6\u76ee\u5f55<br \/>\nServer1:<br \/>\nsu \u2013 monodb<br \/>\ncd \/home\/monodb<br \/>\nmkdir -p data\/shard11<br \/>\nmkdir -p data\/shard21<br \/>\nServer2:<br \/>\nsu \u2013 monodb<br \/>\ncd \/home\/monodb<br \/>\nmkdir -p data\/shard11<br \/>\nmkdir -p data\/shard22<br \/>\nServer3:<br \/>\nsu \u2013 monodb<br \/>\ncd \/home\/monodb<br \/>\nmkdir -p data\/shard13<br \/>\nmkdir -p data\/shard23<\/p>\n<h3>\u914d\u7f6erelica sets<\/h3>\n<p>1.\u00a0\u914d\u7f6eshard1\u6240\u7528\u5230\u7684replica sets:<br \/>\nServer1:<br \/>\ncd \/home\/mongodb\/mongodb-linux-x86_64-1.7.2\/bin<br \/>\n.\/mongod \u2013shardsvr \u2013replSet shard1 \u2013port 27017 \u2013dbpath \/home\/mongodb\/data\/shard11 \u2013oplogSize 100 \u2013logpath \/home\/mongodb\/data\/shard11.log \u2013logappend \u2013fork<\/p>\n<p>Server2:<br \/>\ncd \/home\/mongodb\/mongodb-linux-x86_64-1.7.2\/bin<br \/>\n.\/mongod \u2013shardsvr \u2013replSet shard1 \u2013port 27017 \u2013dbpath \/home\/mongodb\/data\/shard12 \u2013oplogSize 100 \u2013logpath \/home\/mongodb\/data\/shard12.log \u2013logappend \u2013fork<\/p>\n<p>Server3:<br \/>\ncd \/home\/mongodb\/mongodb-linux-x86_64-1.7.2\/bin<br \/>\n.\/mongod \u2013shardsvr \u2013replSet shard1 \u2013port 27017 \u2013dbpath \/home\/mongodb\/data\/shard13 \u2013oplogSize 100 \u2013logpath \/home\/mongodb\/data\/shard13.log \u2013logappend \u2013fork<\/p>\n<p>\u521d\u59cb\u5316replica set<br \/>\n\u7528mongo\u8fde\u63a5\u5176\u4e2d\u4e00\u4e2amongod\uff0c\u6267\u884c:<br \/>\n&gt; config = {_id: \u2019shard1\u2032, members: [<br \/>\n{_id: 0, host: &#8216;10.1.1.1:27017&#8217;},<br \/>\n{_id: 1, host: &#8216;10.1.1.2:27017&#8217;},<br \/>\n{_id: 2, host: &#8216;10.1.1.3:27017&#8217;}]<br \/>\n}<\/p>\n<p>&gt; rs.initiate(config);<\/p>\n<p>\u540c\u6837\u65b9\u6cd5\uff0c\u914d\u7f6eshard2\u7528\u5230\u7684replica sets:<br \/>\nserver1:<br \/>\ncd \/home\/mongodb\/mongodb-linux-x86_64-1.7.2\/bin<br \/>\n.\/mongod \u2013shardsvr \u2013replSet shard2 \u2013port 27018 \u2013dbpath \/home\/mongodb\/data\/shard21 \u2013oplogSize 100 \u2013logpath \/home\/mongodb\/data\/shard21.log \u2013logappend \u2013fork<\/p>\n<p>server2:<br \/>\ncd \/home\/mongodb\/mongodb-linux-x86_64-1.7.2\/bin<br \/>\n.\/mongod \u2013shardsvr \u2013replSet shard2 \u2013port 27018 \u2013dbpath \/home\/mongodb\/data\/shard22 \u2013oplogSize 100 \u2013logpath \/home\/mongodb\/data\/shard22.log \u2013logappend \u2013fork<\/p>\n<p>server3:<br \/>\ncd \/home\/mongodb\/mongodb-linux-x86_64-1.7.2\/bin<br \/>\n.\/mongod \u2013shardsvr \u2013replSet shard2 \u2013port 27018 \u2013dbpath \/home\/mongodb\/data\/shard23 \u2013oplogSize 100 \u2013logpath \/home\/mongodb\/data\/shard23.log \u2013logappend \u2013fork<\/p>\n<p>\u521d\u59cb\u5316replica set<br \/>\n\u7528mongo\u8fde\u63a5\u5176\u4e2d\u4e00\u4e2amongod\uff0c\u6267\u884c:<br \/>\n&gt; config = {_id: \u2019shard2\u2032, members: [<br \/>\n{_id: 0, host: &#8216;10.1.1.1:27018&#8217;},<br \/>\n{_id: 1, host: &#8216;10.1.1.2:27018&#8217;},<br \/>\n{_id: 2, host: &#8216;10.1.1.3:27018&#8217;}]<br \/>\n}<\/p>\n<p>&gt; rs.initiate(config);<\/p>\n<p>\u5230\u6b64\u5c31\u914d\u7f6e\u597d\u4e86\u4e8c\u4e2areplica sets\uff0c\u4e5f\u5c31\u662f\u51c6\u5907\u597d\u4e86\u4e8c\u4e2ashards<\/p>\n<h3>\u914d\u7f6e\u4e09\u53f0config server<\/h3>\n<p>Server1:<br \/>\nmkdir -p \/home\/mongodb\/data\/config<br \/>\n.\/mongod \u2013configsvr \u2013dbpath \/home\/mongodb\/data\/config \u2013port 20000 \u2013logpath \/home\/mongodb\/data\/config.log \u2013logappend \u2013fork\u00a0\u00a0 #config server\u4e5f\u9700\u8981dbpath<\/p>\n<p>Server2:<br \/>\nmkdir -p \/home\/mongodb\/data\/config<br \/>\n.\/mongod \u2013configsvr \u2013dbpath \/home\/mongodb\/data\/config \u2013port 20000 \u2013logpath \/home\/mongodb\/data\/config.log \u2013logappend \u2013fork<\/p>\n<p>Server3:<br \/>\nmkdir -p \/home\/mongodb\/data\/config<br \/>\n.\/mongod \u2013configsvr \u2013dbpath \/home\/mongodb\/data\/config \u2013port 20000 \u2013logpath \/home\/mongodb\/data\/config.log \u2013logappend \u2013fork<\/p>\n<h3>\u914d\u7f6emongs<\/h3>\n<p>\u5728server1,server2,server3\u4e0a\u5206\u522b\u6267\u884c\uff1a<br \/>\n.\/mongos \u2013configdb 10.1.1.1:20000,10.1.1.2:20000,10.1.1.3:20000 \u2013port 30000 \u2013chunkSize 5 \u2013logpath \/home\/mongodb\/data\/mongos.log \u2013logappend \u2013fork<br \/>\n#mongs\u4e0d\u9700\u8981dbpath<\/p>\n<h3>Configuring the Shard Cluster<\/h3>\n<p>\u8fde\u63a5\u5230\u5176\u4e2d\u4e00\u4e2amongos\u8fdb\u7a0b\uff0c\u5e76\u5207\u6362\u5230admin\u6570\u636e\u5e93\u505a\u4ee5\u4e0b\u914d\u7f6e<br \/>\n1.\u00a0\u8fde\u63a5\u5230mongs\uff0c\u5e76\u5207\u6362\u5230admin<br \/>\n.\/mongo 10.1.1.1:30000\/admin<br \/>\n&gt;db<br \/>\nAdmin<br \/>\n2.\u00a0\u52a0\u5165shards<br \/>\n\u5982\u91ccshard\u662f\u5355\u53f0\u670d\u52a1\u5668\uff0c\u7528&gt;db.runCommand( { addshard : \u201c&lt;serverhostname&gt;[:&lt;port&gt;]\u201d } )\u8fd9\u6837\u7684\u547d\u4ee4\u52a0\u5165\uff0c\u5982\u679cshard\u662freplica sets\uff0c\u7528replicaSetName\/&lt;serverhostname&gt;[:port][,serverhostname2[:port],\u2026]\u8fd9\u6837\u7684\u683c\u5f0f\u8868\u793a\uff0c\u4f8b\u5982\u672c\u4f8b\u6267\u884c\uff1a<br \/>\n&gt;db.runCommand( { addshard : \u201cshard1\/10.1.1.1:27017,10.1.1.2:27017,10.1.1.3:27017\u2033,name:\u201ds1\u2033,maxsize:20480} );<br \/>\n&gt;db.runCommand( { addshard : \u201cshard2\/10.1.1.1:27018,10.1.1.2:27018,10.1.1.3:27018\u2033,name:\u201ds2\u2033,maxsize:20480} );<br \/>\n\u6ce8\u610f\uff1a\u5728\u6dfb\u52a0\u7b2c\u4e8c\u4e2ashard\u65f6\uff0c\u51fa\u73b0error:test database \u5df2\u7ecf\u5b58\u5728\u7684\u9519\u8bef\uff0c\u8fd9\u91cc\u7528mongo\u547d\u4ee4\u8fde\u63a5\u5230\u7b2c\u4e8c\u4e2areplica set\uff0c\u7528db.dropDatabase()\u547d\u4ee4\u628atest\u6570\u636e\u5e93\u7ed9\u5220\u9664\u7136\u540e\u5c31\u53ef\u52a0\u5165<\/p>\n<p>3.\u00a0\u53ef\u9009\u53c2\u6570<br \/>\nName:\u7528\u4e8e\u6307\u5b9a\u6bcf\u4e2ashard\u7684\u540d\u5b57\uff0c\u4e0d\u6307\u5b9a\u7684\u8bdd\u7cfb\u7edf\u5c06\u81ea\u52a8\u5206\u914d<br \/>\nmaxSize:\u6307\u5b9a\u5404\u4e2ashard\u53ef\u4f7f\u7528\u7684\u6700\u5927\u78c1\u76d8\u7a7a\u95f4\uff0c\u5355\u4f4dmegabytes<\/p>\n<p>4.\u00a0Listing shards<br \/>\n&gt;db.runCommand( { listshards : 1 } )<br \/>\n\u5982\u679c\u5217\u51fa\u4e86\u4ee5\u4e0a\u4e8c\u4e2a\u4f60\u52a0\u7684shards\uff0c\u8868\u793ashards\u5df2\u7ecf\u914d\u7f6e\u6210\u529f<\/p>\n<p>5.\u00a0\u6fc0\u6d3b\u6570\u636e\u5e93\u5206\u7247<br \/>\n\u547d\u4ee4\uff1a<br \/>\n&gt; db.runCommand( { enablesharding : \u201c&lt;dbname&gt;\u201d } );<br \/>\n\u901a\u8fc7\u6267\u884c\u4ee5\u4e0a\u547d\u4ee4\uff0c\u53ef\u4ee5\u8ba9\u6570\u636e\u5e93\u8de8shard\uff0c\u5982\u679c\u4e0d\u6267\u884c\u8fd9\u6b65\uff0c\u6570\u636e\u5e93\u53ea\u4f1a\u5b58\u653e\u5728\u4e00\u4e2ashard\uff0c\u4e00\u65e6\u6fc0\u6d3b\u6570\u636e\u5e93\u5206\u7247\uff0c\u6570\u636e\u5e93\u4e2d\u4e0d\u540c\u7684collection\u5c06\u88ab\u5b58\u653e\u5728\u4e0d\u540c\u7684shard\u4e0a\uff0c\u4f46\u4e00\u4e2acollection\u4ecd\u65e7\u5b58\u653e\u5728\u540c\u4e00\u4e2ashard\u4e0a\uff0c\u8981\u4f7f\u5355\u4e2acollection\u4e5f\u5206\u7247\uff0c\u8fd8\u9700\u5355\u72ec\u5bf9collection\u4f5c\u4e9b\u64cd\u4f5c<\/p>\n<h3>Collecton\u5206\u7247<\/h3>\n<p>\u8981\u4f7f\u5355\u4e2acollection\u4e5f\u5206\u7247\u5b58\u50a8\uff0c\u9700\u8981\u7ed9collection\u6307\u5b9a\u4e00\u4e2a\u5206\u7247key\uff0c\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u64cd\u4f5c\uff1a<br \/>\n&gt; db.runCommand( { shardcollection : \u201c&lt;namespace&gt;\u201d,key : &lt;shardkeypatternobject&gt; });<br \/>\n\u6ce8\uff1a<br \/>\na.\u00a0\u5206\u7247\u7684collection\u7cfb\u7edf\u4f1a\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\u7d22\u5f15\uff08\u4e5f\u53ef\u7528\u6237\u63d0\u524d\u521b\u5efa\u597d\uff09<br \/>\nb. \u5206\u7247\u7684collection\u53ea\u80fd\u6709\u4e00\u4e2a\u5728\u5206\u7247key\u4e0a\u7684\u552f\u4e00\u7d22\u5f15\uff0c\u5176\u5b83\u552f\u4e00\u7d22\u5f15\u4e0d\u88ab\u5141\u8bb8<br \/>\nOne note: a sharded collection can have only one unique index, which must exist on the shard key. No other unique indexes can exist on the collection.<\/p>\n<h3>\u5206\u7247collection\u4f8b\u5b50<\/h3>\n<p>&gt;db.runCommand( { shardcollection : \u201ctest.c1\u2033,key : {id: 1} } )<br \/>\n&gt;for (var i = 1; i &lt;= 200003; i++) db.c1.save({id:i,value1:\u201d1234567890\u2033,value2:\u201d1234567890\u2033,value3:\u201d1234567890\u2033,value4:\u201d1234567890\u2033});<br \/>\n&gt; db.c1.stats()<br \/>\n{<br \/>\n\u201csharded\u201d : true,<br \/>\n\u201cns\u201d : \u201ctest.c1\u2033,<br \/>\n\u201ccount\u201d : 200003,<br \/>\n\u201csize\u201d : 25600384,<br \/>\n\u201cavgObjSize\u201d : 128,<br \/>\n\u201cstorageSize\u201d : 44509696,<br \/>\n\u201cnindexes\u201d : 2,<br \/>\n\u201cnchunks\u201d : 15,<br \/>\n\u201cshards\u201d : {<br \/>\n\u201cs1\u2033 : {<br \/>\n\u201cns\u201d : \u201ctest.c1\u2033,<br \/>\n\u201ccount\u201d : 141941,<br \/>\n\u201csize\u201d : 18168448,<br \/>\n\u201cavgObjSize\u201d : 128,<br \/>\n\u201cstorageSize\u201d : 33327616,<br \/>\n\u201cnumExtents\u201d : 8,<br \/>\n\u201cnindexes\u201d : 2,<br \/>\n\u201clastExtentSize\u201d : 12079360,<br \/>\n\u201cpaddingFactor\u201d : 1,<br \/>\n\u201cflags\u201d : 1,<br \/>\n\u201ctotalIndexSize\u201d : 11157504,<br \/>\n\u201cindexSizes\u201d : {<br \/>\n\u201c_id_\u201d : 5898240,<br \/>\n\u201cid_1\u2033 : 5259264<br \/>\n},<br \/>\n\u201cok\u201d : 1<br \/>\n},<br \/>\n\u201cs2\u2033 : {<br \/>\n\u201cns\u201d : \u201ctest.c1\u2033,<br \/>\n\u201ccount\u201d : 58062,<br \/>\n\u201csize\u201d : 7431936,<br \/>\n\u201cavgObjSize\u201d : 128,<br \/>\n\u201cstorageSize\u201d : 11182080,<br \/>\n\u201cnumExtents\u201d : 6,<br \/>\n\u201cnindexes\u201d : 2,<br \/>\n\u201clastExtentSize\u201d : 8388608,<br \/>\n\u201cpaddingFactor\u201d : 1,<br \/>\n\u201cflags\u201d : 1,<br \/>\n\u201ctotalIndexSize\u201d : 4579328,<br \/>\n\u201cindexSizes\u201d : {<br \/>\n\u201c_id_\u201d : 2416640,<br \/>\n\u201cid_1\u2033 : 2162688<br \/>\n},<br \/>\n\u201cok\u201d : 1<br \/>\n}<br \/>\n},<br \/>\n\u201cok\u201d : 1<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Sharding cluster\u4ecb\u7ecd \u8fd9\u662f\u4e00\u79cd\u53ef\u4ee5\u6c34\u5e73\u6269\u5c55\u7684\u6a21\u5f0f\uff0c\u5728\u6570\u636e\u91cf\u5f88\u5927\u65f6\u7279\u7ed9\u529b\uff0c\u5b9e\u9645\u5927\u89c4\u6a21\u5e94\u7528\u4e00\u822c\u4f1a\u91c7\u7528\u8fd9\u79cd\u67b6\u6784\u53bb\u6784\u5efamonodb\u7cfb\u7edf\u3002 \u8981\u6784\u5efa\u4e00\u4e2a MongoDB Sharding Cluster\uff0c\u9700\u8981\u4e09\u79cd\u89d2\u8272\uff1a Shard Server: mongod \u5b9e\u4f8b\uff0c\u7528\u4e8e\u5b58\u50a8\u5b9e\u9645\u7684\u6570\u636e\u5757\uff0c\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u4e2d\u4e00\u4e2ashard server\u89d2\u8272\u53ef\u7531\u51e0\u53f0\u673a\u5668\u7ec4\u4e2a\u4e00\u4e2arelica set\u627f\u62c5\uff0c\u9632\u6b62\u4e3b\u673a\u5355\u70b9\u6545\u969c Config Server: mongod \u5b9e\u4f8b\uff0c\u5b58\u50a8\u4e86\u6574\u4e2a Cluster Metadata\uff0c\u5176\u4e2d\u5305\u62ec chunk \u4fe1\u606f\u3002 Route Server: mongos \u5b9e\u4f8b\uff0c\u524d\u7aef\u8def\u7531\uff0c\u5ba2\u6237\u7aef\u7531\u6b64\u63a5\u5165\uff0c\u4e14\u8ba9\u6574\u4e2a\u96c6\u7fa4\u770b\u4e0a\u53bb\u50cf\u5355\u4e00\u6570\u636e\u5e93\uff0c\u524d\u7aef\u5e94\u7528\u53ef\u4ee5\u900f\u660e\u4f7f\u7528\u3002 Sharding\u67b6\u6784\u56fe: \u672c\u4f8b\u5b9e\u9645\u73af\u5883\u67b6\u6784 \u672c\u4f8b\u67b6\u6784\u793a\u4f8b\u56fe\uff1a \u5206\u522b\u57283\u53f0\u673a\u5668\u8fd0\u884c\u4e00\u4e2amongod\u5b9e\u4f8b\uff08\u79f0\u4e3amongod shard11\uff0cmongod shard12\uff0cmongod shard13\uff09\u7ec4\u7ec7replica set1\uff0c\u4f5c\u4e3acluster\u7684shard1 \u5206\u522b\u57283\u53f0\u673a\u5668\u8fd0\u884c\u4e00\u4e2amongod\u5b9e\u4f8b\uff08\u79f0\u4e3amongod shard21\uff0cmongod shard22\uff0cmongod shard23\uff09\u7ec4\u7ec7replica set2\uff0c\u4f5c\u4e3acluster\u7684shard2 \u6bcf\u53f0\u673a\u5668\u8fd0\u884c\u4e00\u4e2amongod\u5b9e\u4f8b\uff0c\u4f5c\u4e3a3\u4e2aconfig server \u6bcf\u53f0\u673a\u5668\u8fd0\u884c\u4e00\u4e2amongs\u8fdb\u7a0b\uff0c\u7528\u4e8e\u5ba2\u6237\u7aef\u8fde\u63a5 &nbsp; \u4e3b\u673a IP \u7aef\u53e3\u4fe1\u606f Server1 10.1.1.1 mongod shard11:27017 mongod shard12:27018 mongod config1:20000 mongs1:30000 &hellip; <a href=\"https:\/\/www.strongd.net\/?p=583\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">\u914d\u7f6emongodb\u5206\u7247\u7fa4\u96c6(sharding cluster)<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,6,7],"tags":[],"class_list":["post-583","post","type-post","status-publish","format-standard","hentry","category-java","category-linux","category-nosql"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=583"}],"version-history":[{"count":1,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/583\/revisions"}],"predecessor-version":[{"id":584,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/583\/revisions\/584"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}