{"id":5368,"date":"2024-11-14T13:22:18","date_gmt":"2024-11-14T05:22:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5368\/"},"modified":"2024-11-14T13:22:18","modified_gmt":"2024-11-14T05:22:18","slug":"%e6%80%8e%e4%b9%88%e9%83%a8%e7%bd%b2mongodb%e9%9b%86%e7%be%a4","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5368\/","title":{"rendered":"\u600e\u4e48\u90e8\u7f72mongodb\u96c6\u7fa4"},"content":{"rendered":"<blockquote><p>\n  \u90e8\u7f72 mongodb \u96c6\u7fa4\u5206\u4e94\u6b65\uff1a\u90e8\u7f72\u4e3b\u8282\u70b9\uff0c\u90e8\u7f72\u8f85\u52a9\u8282\u70b9\uff0c\u6dfb\u52a0\u8f85\u52a9\u8282\u70b9\uff0c\u914d\u7f6e\u590d\u5236\uff0c\u9a8c\u8bc1\u96c6\u7fa4\u3002\u5305\u62ec\u5b89\u88c5 mongodb \u8f6f\u4ef6\u3001\u521b\u5efa\u6570\u636e\u76ee\u5f55\u3001\u542f\u52a8 mongodb \u5b9e\u4f8b\u3001\u521d\u59cb\u5316\u590d\u5236\u96c6\u3001\u6dfb\u52a0\u8f85\u52a9\u8282\u70b9\u3001\u542f\u7528\u526f\u672c\u96c6\u529f\u80fd\u3001\u914d\u7f6e\u6295\u7968\u6743\uff0c\u5e76\u9a8c\u8bc1\u96c6\u7fa4\u72b6\u6001\u548c\u6570\u636e\u590d\u5236\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052802121983006.jpg\" class=\"aligncenter\" title=\"\u600e\u4e48\u90e8\u7f72mongodb\u96c6\u7fa4\u63d2\u56fe\" alt=\"\u600e\u4e48\u90e8\u7f72mongodb\u96c6\u7fa4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u90e8\u7f72 MongoDB \u96c6\u7fa4<\/strong><\/p>\n<p>MongoDB \u96c6\u7fa4\u662f\u4e00\u79cd\u5c06\u591a\u4e2a MongoDB \u5b9e\u4f8b\u8fde\u63a5\u5728\u4e00\u8d77\uff0c\u4ee5\u63d0\u4f9b\u66f4\u9ad8\u53ef\u7528\u6027\u3001\u53ef\u6269\u5c55\u6027\u548c\u6027\u80fd\u7684\u89e3\u51b3\u65b9\u6848\u3002\u4ee5\u4e0b\u662f\u6784\u5efa MongoDB \u96c6\u7fa4\u7684\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u90e8\u7f72\u4e3b\u8282\u70b9<\/strong><\/p>\n<ul>\n<li>\u5b89\u88c5 MongoDB \u8f6f\u4ef6\u3002<\/li>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u76ee\u5f55\u3002<\/li>\n<li>\u542f\u52a8 MongoDB \u5b9e\u4f8b\uff0c\u6307\u5b9a\u6570\u636e\u76ee\u5f55\u548c\u7aef\u53e3\u3002<\/li>\n<\/ul>\n<p><strong>2. \u90e8\u7f72\u8f85\u52a9\u8282\u70b9<\/strong><\/p>\n<ul>\n<li>\u5728\u5176\u4ed6\u670d\u52a1\u5668\u4e0a\u5b89\u88c5 MongoDB \u8f6f\u4ef6\u3002<\/li>\n<li>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u76ee\u5f55\u3002<\/li>\n<li>\u4f7f\u7528 &#8211;replSet \u9009\u9879\u542f\u52a8 MongoDB \u5b9e\u4f8b\uff0c\u6307\u5b9a\u96c6\u7fa4\u7684\u590d\u5236\u96c6\u540d\u79f0\u3002 <\/li>\n<li>\u4f7f\u7528 rs.initiate() \u547d\u4ee4\u521d\u59cb\u5316\u590d\u5236\u96c6\uff0c\u6307\u5b9a\u4e3b\u8282\u70b9\u7684\u5730\u5740\u548c\u7aef\u53e3\u3002<\/li>\n<\/ul>\n<p><strong>3. \u6dfb\u52a0\u8f85\u52a9\u8282\u70b9<\/strong><\/p>\n<ul>\n<li>\u505c\u6b62\u6240\u6709\u8f85\u52a9\u8282\u70b9\u3002<\/li>\n<li>\u5728\u4e3b\u8282\u70b9\u4e0a\u4f7f\u7528 rs.add( : ) \u547d\u4ee4\u6dfb\u52a0\u6bcf\u4e2a\u8f85\u52a9\u8282\u70b9\u3002 <\/li>\n<li>\u542f\u52a8\u8f85\u52a9\u8282\u70b9\u3002<\/li>\n<\/ul>\n<p><strong>4. \u914d\u7f6e\u590d\u5236<\/strong><\/p>\n<ul>\n<li>\n<p>\u5728\u6240\u6709\u8282\u70b9\u4e0a\u542f\u7528\u526f\u672c\u96c6\u529f\u80fd\uff1a<\/p>\n<ul>\n<li>\u4e3b\u8282\u70b9\uff1ars.conf({}).replSetConfig.majorityOplogSize \u8bbe\u7f6e\u4e3a 8MB<\/li>\n<li>\u8f85\u52a9\u8282\u70b9\uff1ars.conf({}).replSetConfig.oplogSize \u8bbe\u7f6e\u4e3a 8MB<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u914d\u7f6e\u526f\u672c\u96c6\u6295\u7968\u6743\uff1a<\/p>\n<ul>\n<li>rs.conf({}).settings.electionTimeoutMillis \u8bbe\u7f6e\u4e3a 60000<\/li>\n<li>rs.conf({}).settings.heartbeatIntervalMillis \u8bbe\u7f6e\u4e3a 2000<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>5. \u9a8c\u8bc1\u96c6\u7fa4<\/strong><\/p>\n<ul>\n<li>\u68c0\u67e5\u6240\u6709\u8282\u70b9\u7684\u72b6\u6001\uff1ars.status()<\/li>\n<li>\u68c0\u67e5\u6570\u636e\u590d\u5236\u662f\u5426\u6b63\u5e38\uff1adb.collection.find().count() \u5e94\u5728\u6240\u6709\u8282\u70b9\u4e0a\u76f8\u7b49<\/li>\n<\/ul>\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n<ul>\n<li>\u5728\u9ad8\u53ef\u7528\u6027\u548c\u6027\u80fd\u4e4b\u95f4\u8fdb\u884c\u6743\u8861\u3002\u5bf9\u4e8e\u9ad8\u53ef\u7528\u6027\uff0c\u4f7f\u7528\u5947\u6570\u4e2a\u8f85\u52a9\u8282\u70b9\u3002\u5bf9\u4e8e\u6027\u80fd\uff0c\u4f7f\u7528\u5076\u6570\u4e2a\u8f85\u52a9\u8282\u70b9\u3002<\/li>\n<li>\u4f7f\u7528\u9632\u706b\u5899\u9650\u5236\u5bf9 MongoDB \u7aef\u53e3\u7684\u8bbf\u95ee\u3002<\/li>\n<li>\u5b9a\u671f\u5907\u4efd MongoDB \u6570\u636e\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u90e8\u7f72\u96c6\u7fa4\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u90e8\u7f72 mongodb \u96c6\u7fa4\u5206\u4e94\u6b65\uff1a\u90e8\u7f72\u4e3b\u8282\u70b9\uff0c\u90e8\u7f72\u8f85\u52a9\u8282\u70b9\uff0c\u6dfb\u52a0\u8f85\u52a9\u8282\u70b9\uff0c\u914d\u7f6e\u590d\u5236\uff0c\u9a8c\u8bc1\u96c6\u7fa4\u3002\u5305\u62ec\u5b89\u88c5 mongodb \u8f6f\u4ef6\u3001\u521b\u5efa\u6570\u636e\u76ee\u5f55\u3001\u542f\u52a8 mongodb \u5b9e\u4f8b\u3001\u521d\u59cb\u5316\u590d\u5236\u96c6\u3001\u6dfb\u52a0\u8f85\u52a9\u8282\u70b9\u3001\u542f\u7528\u526f\u672c\u96c6\u529f\u80fd\u3001\u914d\u7f6e\u6295\u7968\u6743\uff0c\u5e76\u9a8c\u8bc1\u96c6\u7fa4\u72b6\u6001\u548c\u6570\u636e\u590d\u5236\u3002 \u5982\u4f55\u90e8\u7f72 MongoDB \u96c6\u7fa4 MongoDB \u96c6\u7fa4\u662f\u4e00\u79cd\u5c06\u591a\u4e2a MongoDB \u5b9e\u4f8b\u8fde\u63a5\u5728\u4e00\u8d77\uff0c\u4ee5\u63d0\u4f9b\u66f4\u9ad8\u53ef\u7528\u6027\u3001\u53ef\u6269\u5c55\u6027\u548c\u6027\u80fd\u7684\u89e3\u51b3\u65b9\u6848\u3002\u4ee5\u4e0b\u662f\u6784\u5efa MongoDB \u96c6\u7fa4\u7684\u6b65\u9aa4\uff1a 1. \u90e8\u7f72\u4e3b\u8282\u70b9 \u5b89\u88c5 MongoDB \u8f6f\u4ef6\u3002 \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u76ee\u5f55\u3002 \u542f\u52a8 MongoDB \u5b9e\u4f8b\uff0c\u6307\u5b9a\u6570\u636e\u76ee\u5f55\u548c\u7aef\u53e3\u3002 2. \u90e8\u7f72\u8f85\u52a9\u8282\u70b9 \u5728\u5176\u4ed6\u670d\u52a1\u5668\u4e0a\u5b89\u88c5 MongoDB \u8f6f\u4ef6\u3002 \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u76ee\u5f55\u3002 \u4f7f\u7528 &#8211;replSet \u9009\u9879\u542f\u52a8 MongoDB \u5b9e\u4f8b\uff0c\u6307\u5b9a\u96c6\u7fa4\u7684\u590d\u5236\u96c6\u540d\u79f0\u3002 \u4f7f\u7528 rs.initiate() \u547d\u4ee4\u521d\u59cb\u5316\u590d\u5236\u96c6\uff0c\u6307\u5b9a\u4e3b\u8282\u70b9\u7684\u5730\u5740\u548c\u7aef\u53e3\u3002 3. \u6dfb\u52a0\u8f85\u52a9\u8282\u70b9 \u505c\u6b62\u6240\u6709\u8f85\u52a9\u8282\u70b9\u3002 \u5728\u4e3b\u8282\u70b9\u4e0a\u4f7f\u7528 rs.add( : ) \u547d\u4ee4\u6dfb\u52a0\u6bcf\u4e2a\u8f85\u52a9\u8282\u70b9\u3002 \u542f\u52a8\u8f85\u52a9\u8282\u70b9\u3002 4. \u914d\u7f6e\u590d\u5236 \u5728\u6240\u6709\u8282\u70b9\u4e0a\u542f\u7528\u526f\u672c\u96c6\u529f\u80fd\uff1a \u4e3b\u8282\u70b9\uff1ars.conf({}).replSetConfig.majorityOplogSize \u8bbe\u7f6e\u4e3a 8MB \u8f85\u52a9\u8282\u70b9\uff1ars.conf({}).replSetConfig.oplogSize [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5368","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5368"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5368\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}