{"id":1119,"date":"2018-09-20T05:51:01","date_gmt":"2018-09-20T05:51:01","guid":{"rendered":"http:\/\/www.ipcpu.com\/?p=1119"},"modified":"2018-11-27T07:20:55","modified_gmt":"2018-11-27T07:20:55","slug":"mongodb-shard","status":"publish","type":"post","link":"https:\/\/c.ipcpu.com\/2018\/09\/mongodb-shard\/","title":{"rendered":"MongoDB\u7684\u5206\u7247shard"},"content":{"rendered":"

MongoDB\u7684\u5206\u7247shard.md<\/p>\n

\u4e00\u3001\u5206\u7247\u6982\u8ff0<\/h2>\n

\u5728MongoDB\u4e2d\uff0c\u5206\u7247\u96c6\u7fa4\uff08sharded cluster\uff09\u662f\u4e00\u79cd\u6c34\u5e73\u6269\u5c55\u6570\u636e\u5e93\u7cfb\u7edf\u6027\u80fd\u7684\u65b9\u6cd5\uff0c\u80fd\u591f\u5c06\u6570\u636e\u96c6\u5206\u5e03\u5f0f\u5b58\u50a8\u5728\u4e0d\u540c\u7684\u5206\u7247\uff08shard\uff09\u4e0a\uff0c\u6bcf\u4e2a\u5206\u7247\u53ea\u4fdd\u5b58\u6570\u636e\u96c6\u7684\u4e00\u90e8\u5206\uff0cMongoDB\u4fdd\u8bc1\u5404\u4e2a\u5206\u7247\u4e4b\u95f4\u4e0d\u4f1a\u6709\u91cd\u590d\u7684\u6570\u636e\uff0c\u6240\u6709\u5206\u7247\u4fdd\u5b58\u7684\u6570\u636e\u4e4b\u548c\u5c31\u662f\u5b8c\u6574\u7684\u6570\u636e\u96c6\u3002\u5206\u7247\u96c6\u7fa4\u5c06\u6570\u636e\u96c6\u5206\u5e03\u5f0f\u5b58\u50a8\uff0c\u80fd\u591f\u5c06\u8d1f\u8f7d\u5206\u644a\u5230\u591a\u4e2a\u5206\u7247\u4e0a\uff0c\u6bcf\u4e2a\u5206\u7247\u53ea\u8d1f\u8d23\u8bfb\u5199\u4e00\u90e8\u5206\u6570\u636e\uff0c\u5145\u5206\u5229\u7528\u4e86\u5404\u4e2ashard\u7684\u7cfb\u7edf\u8d44\u6e90\uff0c\u63d0\u9ad8\u6570\u636e\u5e93\u7cfb\u7edf\u7684\u541e\u5410\u91cf\u3002<\/p>\n

<\/p>\n

\u4ece\u56fe\u4e2d\u53ef\u4ee5\u770b\u5230\u6709\u56db\u4e2a\u7ec4\u4ef6\uff1amongos\u3001config server\u3001shard\u3001replica set\u3002<\/p>\n

\n

mongos\uff0c\u6570\u636e\u5e93\u96c6\u7fa4\u8bf7\u6c42\u7684\u5165\u53e3\uff0c\u6240\u6709\u7684\u8bf7\u6c42\u90fd\u901a\u8fc7mongos\u8fdb\u884c\u534f\u8c03\uff0c\u4e0d\u9700\u8981\u5728\u5e94\u7528\u7a0b\u5e8f\u6dfb\u52a0\u4e00\u4e2a\u8def\u7531\u9009\u62e9\u5668\uff0cmongos\u81ea\u5df1\u5c31\u662f\u4e00\u4e2a\u8bf7\u6c42\u5206\u53d1\u4e2d\u5fc3\uff0c\u5b83\u8d1f\u8d23\u628a\u5bf9\u5e94\u7684\u6570\u636e\u8bf7\u6c42\u8bf7\u6c42\u8f6c\u53d1\u5230\u5bf9\u5e94\u7684shard\u670d\u52a1\u5668\u4e0a\u3002\u5728\u751f\u4ea7\u73af\u5883\u901a\u5e38\u6709\u591amongos\u4f5c\u4e3a\u8bf7\u6c42\u7684\u5165\u53e3\uff0c\u9632\u6b62\u5176\u4e2d\u4e00\u4e2a\u6302\u6389\u6240\u6709\u7684mongodb\u8bf7\u6c42\u90fd\u6ca1\u6709\u529e\u6cd5\u64cd\u4f5c\u3002<\/p>\n

config server\uff0c\u987e\u540d\u601d\u4e49\u4e3a\u914d\u7f6e\u670d\u52a1\u5668\uff0c\u5b58\u50a8\u6240\u6709\u6570\u636e\u5e93\u5143\u4fe1\u606f\uff08\u8def\u7531\u3001\u5206\u7247\uff09\u7684\u914d\u7f6e\u3002mongos\u672c\u8eab\u6ca1\u6709\u7269\u7406\u5b58\u50a8\u5206\u7247\u670d\u52a1\u5668\u548c\u6570\u636e\u8def\u7531\u4fe1\u606f\uff0c\u53ea\u662f\u7f13\u5b58\u5728\u5185\u5b58\u91cc\uff0c\u914d\u7f6e\u670d\u52a1\u5668\u5219\u5b9e\u9645\u5b58\u50a8\u8fd9\u4e9b\u6570\u636e\u3002mongos\u7b2c\u4e00\u6b21\u542f\u52a8\u6216\u8005\u5173\u6389\u91cd\u542f\u5c31\u4f1a\u4ece config server \u52a0\u8f7d\u914d\u7f6e\u4fe1\u606f\uff0c\u4ee5\u540e\u5982\u679c\u914d\u7f6e\u670d\u52a1\u5668\u4fe1\u606f\u53d8\u5316\u4f1a\u901a\u77e5\u5230\u6240\u6709\u7684 mongos \u66f4\u65b0\u81ea\u5df1\u7684\u72b6\u6001\uff0c\u8fd9\u6837 mongos \u5c31\u80fd\u7ee7\u7eed\u51c6\u786e\u8def\u7531\u3002\u5728\u751f\u4ea7\u73af\u5883\u901a\u5e38\u6709\u591a\u4e2aconfig server \u914d\u7f6e\u914d\u7f6e\u6210\u526f\u672c\u96c6\uff0c\u9632\u6b62\u6570\u636e\u4e22\u5931\uff01<\/p>\n

shard\uff0c\u5206\u7247\uff08sharding\uff09\u662f\u6307\u5c06\u6570\u636e\u5e93\u62c6\u5206\uff0c\u5c06\u5176\u5206\u6563\u5728\u4e0d\u540c\u7684\u673a\u5668\u4e0a\u7684\u8fc7\u7a0b\u3002\u5c06\u6570\u636e\u5206\u6563\u5230\u4e0d\u540c\u7684\u673a\u5668\u4e0a\uff0c\u4e0d\u9700\u8981\u529f\u80fd\u5f3a\u5927\u7684\u670d\u52a1\u5668\u5c31\u53ef\u4ee5\u5b58\u50a8\u66f4\u591a\u7684\u6570\u636e\u548c\u5904\u7406\u66f4\u5927\u7684\u8d1f\u8f7d\u3002\u57fa\u672c\u601d\u60f3\u5c31\u662f\u5c06\u96c6\u5408\u5207\u6210\u5c0f\u5757\uff0c\u8fd9\u4e9b\u5757\u5206\u6563\u5230\u82e5\u5e72\u7247\u91cc\uff0c\u6bcf\u4e2a\u7247\u53ea\u8d1f\u8d23\u603b\u6570\u636e\u7684\u4e00\u90e8\u5206\uff0c\u6700\u540e\u901a\u8fc7\u4e00\u4e2a\u5747\u8861\u5668\u6765\u5bf9\u5404\u4e2a\u5206\u7247\u8fdb\u884c\u5747\u8861\uff08\u6570\u636e\u8fc1\u79fb\uff09\u3002<\/p>\n

replica set\uff0c\u4e2d\u6587\u7ffb\u8bd1\u526f\u672c\u96c6\uff0c\u5176\u5b9e\u5c31\u662fshard\u7684\u5907\u4efd\uff0c\u9632\u6b62shard\u6302\u6389\u4e4b\u540e\u6570\u636e\u4e22\u5931\u3002\u590d\u5236\u63d0\u4f9b\u4e86\u6570\u636e\u7684\u5197\u4f59\u5907\u4efd\uff0c\u5e76\u5728\u591a\u4e2a\u670d\u52a1\u5668\u4e0a\u5b58\u50a8\u6570\u636e\u526f\u672c\uff0c\u63d0\u9ad8\u4e86\u6570\u636e\u7684\u53ef\u7528\u6027\uff0c \u5e76\u53ef\u4ee5\u4fdd\u8bc1\u6570\u636e\u7684\u5b89\u5168\u6027\u3002<\/p>\n<\/blockquote>\n

\u4e8c\u3001\u5206\u7247\u73af\u5883\u7684\u90e8\u7f72<\/h2>\n

\u51c6\u5907\u4e09\u53f0\u670d\u52a1\u5668\uff1a192.168.1.101\u3001192.168.1.102\u3001192.168.1.103\uff0c\u89c4\u5212\u5982\u4e0b\uff0c<\/p>\n

\n
\n\n\n\n\n\n\n\n\n\n
192.168.1.101<\/th>\n192.168.1.102<\/th>\n192.168.1.103<\/th>\n<\/tr>\n<\/thead>\n
mongos<\/td>\nmongos<\/td>\nmongos<\/td>\n<\/tr>\n
config server<\/td>\nconfig server<\/td>\nconfig server<\/td>\n<\/tr>\n
shard1 \u4e3b\u8282\u70b9<\/td>\nshard1 \u526f\u8282\u70b9<\/td>\nshard1 \u526f\u8282\u70b9<\/td>\n<\/tr>\n
shard2 \u526f\u8282\u70b9<\/td>\nshard2 \u4e3b\u8282\u70b9<\/td>\nshard2 \u526f\u8282\u70b9<\/td>\n<\/tr>\n
shard3 \u526f\u8282\u70b9<\/td>\nshard3 \u526f\u8282\u70b9<\/td>\nshard3 \u4e3b\u8282\u70b9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n

\u7aef\u53e3\u5206\u914d<\/p>\n

\n

mongos\uff1a27021
\n config\uff1a21020
\n shard1\uff1a27017
\n shard2\uff1a27018
\n shard3\uff1a27019<\/p>\n<\/blockquote>\n

\u526f\u672c\u96c6\u7684\u90e8\u7f72\uff0c\u6211\u4eec\u4e0a\u7bc7\u6587\u7ae0\u5df2\u7ecf\u4ecb\u7ecd\u8fc7\uff0c\u8fd9\u91cc\u4e0d\u518d\u8be6\u7ec6\u8ba8\u8bba\uff0c\u6211\u4eec\u9700\u8981\u5728\u673a\u5668\u4e0a\u90e8\u7f72shard1\u3001shard2\u3001shard3 \u4e09\u4e2a\u526f\u672c\u96c6\uff0c\u5e76\u4e14\u5c06PRIMARY\u8282\u70b9\u5206\u6563\u52303\u53f0\u673a\u5668\u4e0a\u3002<\/p>\n

\u914d\u7f6e\u6587\u4ef6\u5982\u4e0b\uff1a<\/p>\n

\n
#start shell: numactl --interleave=all \/usr\/bin\/mongod -f \/etc\/mongodb\/shard1.conf --journal\r\nsystemLog:\r\n destination: file\r\n path: \"\/data\/logs\/mongodb\/sahrd1.log\"\r\n quiet: true\r\n logAppend: true\r\n timeStampFormat: iso8601-utc\r\nstorage:\r\n wiredTiger:\r\n  engineConfig:\r\n   cacheSizeGB: 6\r\n dbPath: \"\/data\/mongodb\/shard1\"\r\n directoryPerDB: true\r\n indexBuildRetry: false\r\n# quota:\r\n# enforced: false\r\n# maxFilesPerDB: 8\r\n syncPeriodSecs: 60\r\n# repairPath: \"\/var\/lib\/mongo\/_tmp\"\r\n journal:\r\n  enabled:true\r\n# debugFlags: 1\r\n# commitIntervalMs: 100\r\nprocessManagement:\r\n fork: true\r\n pidFilePath: \"\/data\/run\/mongodb\/shard1.pid\"\r\nnet:\r\n# bindIp: 127.0.0.1\r\n port: 27017\r\n# http:\r\n# enabled: true\r\n# RESTInterfaceEnabled: false\r\n# ssl:\r\n# mode: \"requireSSL\"\r\n# PEMKeyFile: \"\/etc\/ssl\/mongodb.pem\"\r\noperationProfiling:\r\n slowOpThresholdMs: 100\r\n mode: \"slowOp\"\r\n#security:\r\n# keyFile: \"\/var\/lib\/mongo\/mongodb-keyfile\"\r\n# clusterAuthMode: \"keyFile\"\r\n# authorization: \"disabled\"\r\nreplication:\r\n oplogSizeMB: 1024\r\n replSetName: \"shard1\"\r\n secondaryIndexPrefetch: \"all\"\r\nsharding:\r\n clusterRole: shardsvr<\/code><\/pre>\n<\/div>\n

\u7136\u540e\u6309\u7167\u4e0a\u9762\u7684\u4f8b\u5b50\u521b\u5efaconfigserver\u7684\u526f\u672c\u96c6\uff0c\u914d\u7f6e\u6587\u4ef6\u57fa\u672c\u7c7b\u4f3c\uff0c\u6ce8\u610f\u4fee\u6539\u5b58\u50a8\u8def\u5f84\u3001\u7aef\u53e3\u4fe1\u606f\u3002
\n\u6700\u540e\u7684clusterRole\u914d\u7f6e\u4e3aclusterRole: configsvr \u3002<\/p>\n

\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u6765\u521b\u5efamongos\uff0c\u914d\u7f6e\u6587\u4ef6\u5982\u4e0b<\/p>\n

\n
systemLog:\r\n destination: file\r\n path: \"\/data\/logs\/mongodb\/mongos\/mongos.log\"\r\n logAppend: true\r\nprocessManagement:\r\n  fork: true\r\n  pidFilePath: \"\/data\/run\/mongodb\/mongos.pid\"\r\nnet:\r\n port: 27021\r\n# bindIp: 127.0.0.1\r\nsharding:\r\n configDB: configsvr\/192.168.1.101:27020,192.168.1.102:27020,192.168.1.103:27020<\/code><\/pre>\n<\/div>\n

\u56e0\u4e3amongos\u5206\u7247\u914d\u7f6e\u4fe1\u606f\u662f\u5b58\u50a8\u5728configserver\u4e2d\u7684\uff0c\u6240\u4ee5\u767b\u9646\u4efb\u610f\u4e00\u53f0mongos\u5373\u53ef\uff0cmongo --port 27021\uff0c\u8fdb\u884c\u64cd\u4f5c\uff1a<\/p>\n

\n
#\u4f7f\u7528admin\u6570\u636e\u5e93\r\nuse admin\r\n#\u4e32\u8054\u8def\u7531\u670d\u52a1\u5668\u4e0e\u5206\u914d\u526f\u672c\u96c6\r\nsh.addShard(\"shard1\/192.168.1.101:27017,192.168.1.102:27017,192.168.1.103:27017\")\r\nsh.addShard(\"shard2\/192.168.1.101:27018,192.168.1.102:27018,192.168.1.103:27018\")\r\nsh.addShard(\"shard3\/192.168.1.101:27019,192.168.1.102:27019,192.168.1.103:27019\")\r\n#\u67e5\u770b\u96c6\u7fa4\u72b6\u6001\r\nsh.status()<\/code><\/pre>\n<\/div>\n

\u4e09\u3001\u6d4b\u8bd5\u5206\u7247\u6548\u679c<\/h2>\n

\u767b\u9646mongos\uff0cmongo --port 27021\uff0c\u6d4b\u8bd5\u5206\u7247\u6548\u679c<\/p>\n

\n
#\u6307\u5b9a\u8981\u5f00\u542f\u5206\u7247\u7684\u6570\u636e\u5e93\r\ndb.runCommand( { enablesharding :\"testdb\"});\r\n\u6216\u8005\r\nsh.enableSharding(\"testdb\")\r\n\r\n#\u4f7f\u7528\u54c8\u5e0c\u7247\u952e\u5bf9\u96c6\u5408\u5206\u7247\r\nsh.shardCollection( \"testdb.billing\", { id: \"hashed\" } )\r\n\r\n#\u63d2\u5165\u6d4b\u8bd5\u6570\u636e\r\nuse testdb\r\nfor(var i=0; i<1000; i++) db.billing.insert({id:i*1597,uid:i}); \r\ndb.billing.find()\r\ndb.billing.find().count();\r\n\r\n#\u67e5\u770b\u6570\u636e\u5206\u7247\u60c5\u51b5\r\ndb.billing.stats()<\/code><\/pre>\n<\/div>\n

\u6ce8\u610f\uff1a\u597d\u591a\u6559\u7a0b\u4f7f\u7528\u7684\u5206\u7247\u89c4\u5219\u4e0d\u662f\u54c8\u5e0c\u5206\u7247\uff0c\u6700\u7ec8\u53ef\u80fd\u6570\u636e\u5206\u5e03\u4e0d\u662f\u5f88\u660e\u663e\u3002<\/p>\n

\u56db\u3001\u5206\u7247\u89c4\u5219<\/h2>\n

MongoDB\u4e2d\u6570\u636e\u7684\u5206\u7247\u662f\u4ee5\u96c6\u5408\u4e3a\u57fa\u672c\u5355\u4f4d\u7684\uff0c\u96c6\u5408\u4e2d\u7684\u6570\u636e\u901a\u8fc7\u7247\u952e\uff08Shard key\uff09\u88ab\u5206\u6210\u591a\u90e8\u5206\u3002\u5176\u5b9e\u7247\u952e\u5c31\u662f\u5728\u96c6\u5408\u4e2d\u9009\u4e00\u4e2a\u952e\uff0c\u7528\u8be5\u952e\u7684\u503c\u4f5c\u4e3a\u6570\u636e\u62c6\u5206\u7684\u4f9d\u636e\u3002\u6240\u4ee5\u4e00\u4e2a\u597d\u7684\u7247\u952e\u5bf9\u5206\u7247\u81f3\u5173\u91cd\u8981\u3002\u7247\u952e\u5fc5\u987b\u662f\u4e00\u4e2a\u7d22\u5f15\uff0c\u901a\u8fc7sh.shardCollection\u52a0\u4f1a\u81ea\u52a8\u521b\u5efa\u7d22\u5f15\uff08\u524d\u63d0\u662f\u6b64\u96c6\u5408\u4e0d\u5b58\u5728\u7684\u60c5\u51b5\u4e0b\uff09\u3002\u4e00\u4e2a\u81ea\u589e\u7684\u7247\u952e\u5bf9\u5199\u5165\u548c\u6570\u636e\u5747\u5300\u5206\u5e03\u5c31\u4e0d\u662f\u5f88\u597d\uff0c\u56e0\u4e3a\u81ea\u589e\u7684\u7247\u952e\u603b\u4f1a\u5728\u4e00\u4e2a\u5206\u7247\u4e0a\u5199\u5165\uff0c\u540e\u7eed\u8fbe\u5230\u67d0\u4e2a\u9600\u503c\u53ef\u80fd\u4f1a\u5199\u5230\u522b\u7684\u5206\u7247\u3002\u4f46\u662f\u6309\u7167\u7247\u952e\u67e5\u8be2\u4f1a\u975e\u5e38\u9ad8\u6548\u3002\u968f\u673a\u7247\u952e\u5bf9\u6570\u636e\u7684\u5747\u5300\u5206\u5e03\u6548\u679c\u5f88\u597d\u3002\u6ce8\u610f\u5c3d\u91cf\u907f\u514d\u5728\u591a\u4e2a\u5206\u7247\u4e0a\u8fdb\u884c\u67e5\u8be2\u3002\u5728\u6240\u6709\u5206\u7247\u4e0a\u67e5\u8be2\uff0cmongos\u4f1a\u5bf9\u7ed3\u679c\u8fdb\u884c\u5f52\u5e76\u6392\u5e8f\u3002<\/p>\n

mongos\u90e8\u7f72\u65f6\uff0c\u9700\u8981\u6839\u636e\u4e1a\u52a1\u573a\u666f\u9009\u62e9\u5408\u9002\u7684\u5206\u7247\u952e\uff08shard key\uff09\u4ee5\u51b3\u5b9amongos\u5982\u4f55\u8fdb\u884c\u6570\u636e\u5207\u5206\u540e\u5b58\u50a8\u5728\u5bf9\u5e94chunk\uff08chunk\u662fmongos\u6570\u636e\u5b58\u50a8\u7684\u6700\u5c0f\u5355\u5143\uff0c\u9ed8\u8ba4\u662f64M\uff09\u3002\u5e38\u89c1\u7684\u5206\u7247\u89c4\u5219\u6709\u4e09\u79cd\uff1aHASH\u5206\u7247\u3001RANGE\u5206\u7247\u53caZONE\u5206\u7247\u3002<\/p>\n

4.1. \u54c8\u5e0c\u5206\u7247(Hashed Sharding)<\/h4>\n

hash\u5206\u7247\u4f7f\u7528\u5355\u5b57\u6bb5\u7684hash\u51fd\u6570\u4f5c\u4e3a\u5206\u7247\u952e\u8de8\u5206\u7247\u96c6\u7fa4\u62c6\u5206\u6570\u636e\u3002
\n<\/p>\n

4.2. RANGEED\u5206\u7247(Ranged Sharding)<\/h4>\n

range\u5206\u7247\u4f9d\u636e\u5206\u7247\u89c4\u5219\u5c06\u6d89\u53ca\u5230\u7684\u6570\u636e\u5212\u5206\u6210\u8fde\u7eed\u8303\u56f4\u7684chunk\u3002<\/p>\n

<\/p>\n

4.3. ZONES\u5206\u7247(Zones in Sharded Clusters)<\/h4>\n

\u81ea\u5b9a\u4e49\u533a\u57df\u5207\u7247\u3002\u901a\u8fc7\u5bf9\u5206\u7247\u952e\u7684\u7279\u5b9a\u8303\u56f4\u8fdb\u884c\u6807\u8bb0\uff0c\u5e76\u5c06\u8fd9\u4e9b\u6807\u8bb0\u4e0eshard\u5173\u8054\uff0c\u5b9e\u73b0\u6570\u636e\u7684\u5b9a\u5411\u5b58\u50a8\u3002
\n\u6570\u636e\u62c6\u5206\u5982\u56fe\uff1a<\/p>\n

<\/p>\n

\u53c2\u8003\u8d44\u6599<\/h2>\n

https:\/\/zhuanlan.zhihu.com\/p\/29530029<\/a>
\n
https:\/\/www.cnblogs.com\/ljhdo\/p\/4886087.html<\/a>
\n
http:\/\/blog.fens.me\/mongodb-shard\/<\/a>
\n
http:\/\/www.ityouknow.com\/mongodb\/2017\/08\/05\/mongodb-cluster-setup.html<\/a><\/p>\n

<\/p>\n

<\/div>\n
<\/div>\n
\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n<\/div>\n
\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n
<\/div>\n<\/div>\n

<\/wiz_tmp_tag><\/p>\n

\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1aIPCPU-\u7f51\u7edc\u4e4b\u8def<\/a> » MongoDB\u7684\u5206\u7247shard<\/a><\/p>","protected":false},"excerpt":{"rendered":"

MongoDB\u7684\u5206\u7247shard.md \u4e00\u3001\u5206\u7247\u6982\u8ff0 \u5728MongoDB\u4e2d\uff0c\u5206\u7247\u96c6\u7fa4\uff08sharded cluster\uff09\u662f\u4e00\u79cd\u6c34\u5e73\u6269\u5c55\u6570\u636e\u5e93\u7cfb\u7edf\u6027\u80fd\u7684\u65b9\u6cd5\uff0c\u80fd\u591f\u5c06\u6570\u636e\u96c6\u5206\u5e03\u5f0f\u5b58\u50a8\u5728\u4e0d\u540c\u7684\u5206\u7247\uff08shard\uff09\u4e0a\uff0c\u6bcf\u4e2a\u5206\u7247\u53ea\u4fdd\u5b58\u6570\u636e\u96c6\u7684\u4e00\u90e8\u5206\uff0cMongoDB\u4fdd\u8bc1\u5404\u4e2a\u5206\u7247\u4e4b\u95f4\u4e0d\u4f1a\u6709\u91cd\u590d\u7684\u6570\u636e\uff0c\u6240\u6709\u5206\u7247\u4fdd\u5b58\u7684\u6570\u636e\u4e4b\u548c\u5c31\u662f\u5b8c\u6574\u7684\u6570\u636e\u96c6\u3002\u5206\u7247\u96c6\u7fa4\u5c06\u6570\u636e\u96c6\u5206\u5e03\u5f0f\u5b58\u50a8\uff0c\u80fd\u591f\u5c06\u8d1f\u8f7d\u5206\u644a\u5230\u591a\u4e2a\u5206\u7247\u4e0a\uff0c\u6bcf\u4e2a\u5206\u7247\u53ea\u8d1f\u8d23\u8bfb\u5199\u4e00\u90e8\u5206\u6570\u636e\uff0c\u5145\u5206\u5229\u7528\u4e86\u5404\u4e2ashard\u7684\u7cfb\u7edf\u8d44\u6e90\uff0c\u63d0\u9ad8\u6570\u636e\u5e93\u7cfb\u7edf\u7684\u541e\u5410\u91cf\u3002 \u4ece\u56fe\u4e2d\u53ef\u4ee5\u770b\u5230\u6709\u56db\u4e2a\u7ec4\u4ef6\uff1amongos\u3001config server\u3001shard\u3001replica set\u3002 mongos\uff0c\u6570\u636e\u5e93\u96c6\u7fa4\u8bf7\u6c42\u7684\u5165\u53e3\uff0c\u6240\u6709\u7684\u8bf7\u6c42\u90fd\u901a\u8fc7mongos\u8fdb\u884c\u534f\u8c03\uff0c\u4e0d\u9700\u8981\u5728\u5e94\u7528\u7a0b\u5e8f\u6dfb\u52a0\u4e00\u4e2a\u8def\u7531\u9009\u62e9\u5668\uff0cmongos\u81ea\u5df1\u5c31\u662f\u4e00\u4e2a\u8bf7\u6c42\u5206\u53d1\u4e2d\u5fc3\uff0c\u5b83\u8d1f\u8d23\u628a\u5bf9\u5e94\u7684\u6570\u636e\u8bf7\u6c42\u8bf7\u6c42\u8f6c\u53d1\u5230\u5bf9\u5e94\u7684shard\u670d\u52a1\u5668\u4e0a\u3002\u5728\u751f\u4ea7\u73af\u5883\u901a\u5e38\u6709\u591amongos\u4f5c\u4e3a\u8bf7\u6c42\u7684\u5165\u53e3\uff0c\u9632\u6b62\u5176\u4e2d\u4e00\u4e2a\u6302\u6389\u6240\u6709\u7684mongodb\u8bf7\u6c42\u90fd\u6ca1\u6709\u529e\u6cd5\u64cd\u4f5c\u3002 config server\uff0c\u987e\u540d\u601d\u4e49\u4e3a\u914d\u7f6e\u670d\u52a1\u5668\uff0c\u5b58\u50a8\u6240\u6709\u6570\u636e\u5e93\u5143\u4fe1\u606f\uff08\u8def\u7531\u3001\u5206\u7247\uff09\u7684\u914d\u7f6e\u3002mongos\u672c\u8eab\u6ca1\u6709\u7269\u7406\u5b58\u50a8\u5206\u7247\u670d\u52a1\u5668\u548c\u6570\u636e\u8def\u7531\u4fe1\u606f\uff0c\u53ea\u662f\u7f13\u5b58\u5728\u5185\u5b58\u91cc\uff0c\u914d\u7f6e\u670d\u52a1\u5668\u5219\u5b9e\u9645\u5b58\u50a8\u8fd9\u4e9b\u6570\u636e\u3002mongos\u7b2c\u4e00\u6b21\u542f\u52a8\u6216\u8005\u5173\u6389\u91cd\u542f\u5c31\u4f1a\u4ece config server \u52a0\u8f7d\u914d\u7f6e\u4fe1\u606f\uff0c\u4ee5\u540e\u5982\u679c\u914d\u7f6e\u670d\u52a1\u5668\u4fe1\u606f\u53d8\u5316\u4f1a\u901a\u77e5\u5230\u6240\u6709\u7684 mongos \u66f4\u65b0\u81ea\u5df1\u7684\u72b6\u6001\uff0c\u8fd9\u6837 mongos \u5c31\u80fd\u7ee7\u7eed\u51c6\u786e\u8def\u7531\u3002\u5728\u751f\u4ea7\u73af\u5883\u901a\u5e38\u6709\u591a\u4e2aconfig server \u914d\u7f6e\u914d\u7f6e\u6210\u526f\u672c\u96c6\uff0c\u9632\u6b62\u6570\u636e\u4e22\u5931\uff01 shard\uff0c\u5206\u7247\uff08sharding\uff09\u662f\u6307\u5c06\u6570\u636e\u5e93\u62c6\u5206\uff0c\u5c06\u5176\u5206\u6563\u5728\u4e0d\u540c\u7684\u673a\u5668\u4e0a\u7684\u8fc7\u7a0b\u3002\u5c06\u6570\u636e\u5206\u6563\u5230\u4e0d\u540c\u7684\u673a\u5668\u4e0a\uff0c\u4e0d\u9700\u8981\u529f\u80fd\u5f3a\u5927\u7684\u670d\u52a1\u5668\u5c31\u53ef\u4ee5\u5b58\u50a8\u66f4\u591a\u7684\u6570\u636e\u548c\u5904\u7406\u66f4\u5927\u7684\u8d1f\u8f7d\u3002\u57fa\u672c\u601d\u60f3\u5c31\u662f\u5c06\u96c6\u5408\u5207\u6210\u5c0f\u5757\uff0c\u8fd9\u4e9b\u5757\u5206\u6563\u5230\u82e5\u5e72\u7247\u91cc\uff0c\u6bcf\u4e2a\u7247\u53ea\u8d1f\u8d23\u603b\u6570\u636e\u7684\u4e00\u90e8\u5206\uff0c\u6700\u540e\u901a\u8fc7\u4e00\u4e2a\u5747\u8861\u5668\u6765\u5bf9\u5404\u4e2a\u5206\u7247\u8fdb\u884c\u5747\u8861\uff08\u6570\u636e\u8fc1\u79fb\uff09\u3002 replica set\uff0c\u4e2d\u6587\u7ffb\u8bd1\u526f\u672c\u96c6\uff0c\u5176\u5b9e\u5c31\u662fshard\u7684\u5907\u4efd\uff0c\u9632\u6b62shard\u6302\u6389\u4e4b\u540e\u6570\u636e\u4e22\u5931\u3002\u590d\u5236\u63d0\u4f9b\u4e86\u6570\u636e\u7684\u5197\u4f59\u5907\u4efd\uff0c\u5e76\u5728\u591a\u4e2a\u670d\u52a1\u5668\u4e0a\u5b58\u50a8\u6570\u636e\u526f\u672c\uff0c\u63d0\u9ad8\u4e86\u6570\u636e\u7684\u53ef\u7528\u6027\uff0c \u5e76\u53ef\u4ee5\u4fdd\u8bc1\u6570\u636e\u7684\u5b89\u5168\u6027\u3002 \u4e8c\u3001\u5206\u7247\u73af\u5883\u7684\u90e8\u7f72 \u51c6\u5907\u4e09\u53f0\u670d\u52a1\u5668\uff1a192.168.1.101\u3001192.168.1.102\u3001192.168.1.103\uff0c\u89c4\u5212\u5982\u4e0b\uff0c 192.168.1.101 192.168.1.102 192.168.1.103 mongos mongos mongos config server config server config server shard1 \u4e3b\u8282\u70b9 shard1 \u526f\u8282\u70b9 shard1 \u526f\u8282\u70b9 shard2 \u526f\u8282\u70b9 shard2 \u4e3b\u8282\u70b9 shard2 \u526f\u8282\u70b9 shard3 \u526f\u8282\u70b9 shard3 \u526f\u8282\u70b9 shard3 \u4e3b\u8282\u70b9 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,13],"tags":[130],"_links":{"self":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1119"}],"collection":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/comments?post=1119"}],"version-history":[{"count":2,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1119\/revisions"}],"predecessor-version":[{"id":1121,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1119\/revisions\/1121"}],"wp:attachment":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/media?parent=1119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/categories?post=1119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/tags?post=1119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}