{"id":21698,"date":"2024-01-02T13:49:28","date_gmt":"2024-01-02T13:49:28","guid":{"rendered":"https:\/\/server.hk\/blog\/21698\/"},"modified":"2024-11-14T10:28:28","modified_gmt":"2024-11-14T02:28:28","slug":"how-to-fix-mongodb-error-code-108-inconsistentreplicasetnames","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21698\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 108 &#8211; InconsistentReplicaSetNames"},"content":{"rendered":"<h1 id=\"how-to-fix-mongodb-error-code-108-inconsistentreplicasetnames-wOuvlVRMGa\">\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 108 &#8211; InconsistentReplicaSetNames<\/h1>\n<p>MongoDB \u662f\u4e00\u500b\u53d7\u6b61\u8fce\u7684\u958b\u6e90 NoSQL \u8cc7\u6599\u5eab\uff0c\u63d0\u4f9b\u9ad8\u6548\u80fd\u3001\u64f4\u5c55\u6027\u548c\u9748\u6d3b\u6027\u3002\u5b83\u88ab\u958b\u767c\u4eba\u54e1\u548c\u4f01\u696d\u5ee3\u6cdb\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u7a0b\u5e8f\u3002\u7136\u800c\uff0c\u8207\u5176\u4ed6\u8edf\u4ef6\u4e00\u6a23\uff0cMongoDB \u53ef\u80fd\u6703\u9047\u5230\u9700\u8981\u89e3\u6c7a\u7684\u932f\u8aa4\u548c\u554f\u984c\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u662f MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 108 &#8211; InconsistentReplicaSetNames\u3002<\/p>\n<h2 id=\"understanding-mongodb-error-code-108-inconsistentreplicasetnames-wOuvlVRMGa\">\u7406\u89e3 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 108 &#8211; InconsistentReplicaSetNames<\/h2>\n<p>MongoDB \u4f7f\u7528\u4e00\u500b\u7a31\u70ba\u8907\u88fd\u96c6\uff08Replica Set\uff09\u7684\u6982\u5ff5\uff0c\u9019\u662f\u4e00\u7d44\u6258\u7ba1\u76f8\u540c\u6578\u64da\u96c6\u7684 MongoDB \u7bc0\u9ede\u3002\u8907\u88fd\u96c6\u63d0\u4f9b\u9ad8\u53ef\u7528\u6027\uff0c\u4e26\u5728\u4e3b\u8981\u7bc0\u9ede\u6545\u969c\u6642\u81ea\u52d5\u6545\u969c\u8f49\u79fb\u3002\u6bcf\u500b\u8907\u88fd\u96c6\u90fd\u6709\u4e00\u500b\u552f\u4e00\u7684\u540d\u7a31\uff0c\u7528\u4f86\u5728 MongoDB \u90e8\u7f72\u4e2d\u8b58\u5225\u5b83\u3002<\/p>\n<p>\u932f\u8aa4\u4ee3\u78bc &#8211; 108 &#8211; InconsistentReplicaSetNames \u767c\u751f\u65bc MongoDB \u6aa2\u6e2c\u5230\u90e8\u7f72\u4e2d\u7684\u7bc0\u9ede\u4e4b\u9593\u8907\u88fd\u96c6\u540d\u7a31\u4e0d\u4e00\u81f4\u6642\u3002\u5728\u5065\u5eb7\u7684\u8907\u88fd\u96c6\u4e2d\uff0c\u6240\u6709\u7bc0\u9ede\u61c9\u8a72\u64c1\u6709\u76f8\u540c\u7684\u540d\u7a31\u3002\u5982\u679c\u540d\u7a31\u4e0d\u4e00\u81f4\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u5404\u7a2e\u554f\u984c\uff0c\u5305\u62ec\u6545\u969c\u8f49\u79fb\u548c\u6578\u64da\u540c\u6b65\u7684\u554f\u984c\u3002<\/p>\n<h2 id=\"causes-of-mongodb-error-code-108-inconsistentreplicasetnames-wOuvlVRMGa\">MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 108 &#8211; InconsistentReplicaSetNames \u7684\u539f\u56e0<\/h2>\n<p>\u5c0e\u81f4\u6b64\u932f\u8aa4\u7684\u539f\u56e0\u6709\u5e7e\u500b\uff1a<\/p>\n<ul>\n<li><strong>\u624b\u52d5\u914d\u7f6e\uff1a<\/strong> \u5982\u679c\u624b\u52d5\u914d\u7f6e\u4e0d\u540c\u7bc0\u9ede\u7684\u8907\u88fd\u96c6\u540d\u7a31\uff0c\u5247\u53ef\u80fd\u51fa\u73fe\u4e0d\u4e00\u81f4\u7684\u60c5\u6cc1\u3002<\/li>\n<li><strong>\u7db2\u7d61\u554f\u984c\uff1a<\/strong> \u7bc0\u9ede\u4e4b\u9593\u7684\u7db2\u7d61\u9023\u63a5\u554f\u984c\u53ef\u80fd\u5c0e\u81f4\u8907\u88fd\u96c6\u540d\u7a31\u4e0d\u4e00\u81f4\u3002<\/li>\n<li><strong>\u932f\u8aa4\u914d\u7f6e\uff1a<\/strong> \u932f\u8aa4\u7684\u914d\u7f6e\u6587\u4ef6\u6216\u8a2d\u7f6e\u4e5f\u53ef\u80fd\u5c0e\u81f4\u8907\u88fd\u96c6\u540d\u7a31\u4e0d\u4e00\u81f4\u3002<\/li>\n<\/ul>\n<h2 id=\"fixing-mongodb-error-code-108-inconsistentreplicasetnames-wOuvlVRMGa\">\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 108 &#8211; InconsistentReplicaSetNames<\/h2>\n<p>\u8981\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u6240\u6709\u7bc0\u9ede\u7684\u8907\u88fd\u96c6\u540d\u7a31\u5728 MongoDB \u90e8\u7f72\u4e2d\u4fdd\u6301\u4e00\u81f4\u3002\u4ee5\u4e0b\u662f\u89e3\u6c7a\u8a72\u554f\u984c\u7684\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"step-1-check-replica-set-configuration-wOuvlVRMGa\">\u6b65\u9a5f 1\uff1a\u6aa2\u67e5\u8907\u88fd\u96c6\u914d\u7f6e<\/h3>\n<p>\u9996\u5148\uff0c\u6aa2\u67e5\u8907\u88fd\u96c6\u4e2d\u6bcf\u500b\u7bc0\u9ede\u7684\u914d\u7f6e\u3002\u4f7f\u7528 MongoDB shell \u6216 MongoDB \u5ba2\u6236\u7aef\u9023\u63a5\u5230\u6bcf\u500b\u7bc0\u9ede\uff0c\u4e26\u904b\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>rs.conf()<\/code><\/pre>\n<p>\u6b64\u547d\u4ee4\u5c07\u986f\u793a\u8907\u88fd\u96c6\u914d\u7f6e\uff0c\u5305\u62ec\u540d\u7a31\u3002\u78ba\u4fdd\u6240\u6709\u7bc0\u9ede\u4e0a\u7684\u540d\u7a31\u4e00\u81f4\u3002\u5982\u679c\u767c\u73fe\u4efb\u4f55\u4e0d\u4e00\u81f4\uff0c\u8acb\u7e7c\u7e8c\u9032\u884c\u4e0b\u4e00\u6b65\u3002<\/p>\n<h3 id=\"step-2-update-replica-set-names-wOuvlVRMGa\">\u6b65\u9a5f 2\uff1a\u66f4\u65b0\u8907\u88fd\u96c6\u540d\u7a31<\/h3>\n<p>\u8981\u66f4\u65b0\u8907\u88fd\u96c6\u540d\u7a31\uff0c\u60a8\u9700\u8981\u9023\u63a5\u5230\u6bcf\u500b\u7bc0\u9ede\u4e26\u904b\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>rs.reconfig({ \"_id\": \"your_replica_set_name\", \"version\": 1, \"members\": [ { \"_id\": 0, \"host\": \"node1:27017\" }, { \"_id\": 1, \"host\": \"node2:27017\" }, { \"_id\": 2, \"host\": \"node3:27017\" } ] })<\/code><\/pre>\n<p>\u5c07 &#8220;your_replica_set_name&#8221; \u66ff\u63db\u70ba\u60a8\u5e0c\u671b\u7684\u8907\u88fd\u96c6\u540d\u7a31\u3002\u4e26\u66f4\u65b0 &#8220;host&#8221; \u503c\uff0c\u5c07\u5176\u66ff\u63db\u70ba\u6bcf\u500b\u7bc0\u9ede\u7684\u6b63\u78ba\u4e3b\u6a5f\u540d\u7a31\u548c\u7aef\u53e3\u3002\u5728\u6bcf\u500b\u7bc0\u9ede\u4e0a\u904b\u884c\u6b64\u547d\u4ee4\uff0c\u78ba\u4fdd\u6240\u6709\u7bc0\u9ede\u7684\u914d\u7f6e\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<h3 id=\"step-3-restart-mongodb-wOuvlVRMGa\">\u6b65\u9a5f 3\uff1a\u91cd\u555f MongoDB<\/h3>\n<p>\u66f4\u65b0\u8907\u88fd\u96c6\u540d\u7a31\u5f8c\uff0c\u8acb\u91cd\u555f\u6bcf\u500b\u7bc0\u9ede\u4e0a\u7684 MongoDB \u4ee5\u61c9\u7528\u66f4\u6539\u3002\u60a8\u53ef\u4ee5\u904b\u884c\u4ee5\u4e0b\u547d\u4ee4\u4f86\u57f7\u884c\u6b64\u64cd\u4f5c\uff1a<\/p>\n<pre><code>sudo systemctl restart mongod<\/code><\/pre>\n<p>\u78ba\u4fdd\u5728\u90e8\u7f72\u4e2d\u7684\u6240\u6709\u7bc0\u9ede\u4e0a\u91cd\u555f MongoDB\u3002<\/p>\n<h3 id=\"step-4-verify-replica-set-configuration-wOuvlVRMGa\">\u6b65\u9a5f 4\uff1a\u9a57\u8b49\u8907\u88fd\u96c6\u914d\u7f6e<\/h3>\n<p>\u6700\u5f8c\uff0c\u9a57\u8b49\u8907\u88fd\u96c6\u914d\u7f6e\u4ee5\u78ba\u4fdd\u540d\u7a31\u4e00\u81f4\u3002\u9023\u63a5\u5230\u8907\u88fd\u96c6\u4e2d\u7684\u4efb\u4f55\u7bc0\u9ede\uff0c\u4e26\u904b\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>rs.conf()<\/code><\/pre>\n<p>\u8a72\u547d\u4ee4\u61c9\u986f\u793a\u66f4\u65b0\u7684\u914d\u7f6e\uff0c\u4e26\u78ba\u4fdd\u6240\u6709\u7bc0\u9ede\u7684\u8907\u88fd\u96c6\u540d\u7a31\u4e00\u81f4\u3002<\/p>\n<h2 id=\"summary-wOuvlVRMGa\">\u7e3d\u7d50<\/h2>\n<p>\u4e0d\u4e00\u81f4\u7684\u8907\u88fd\u96c6\u540d\u7a31\u6703\u5c0e\u81f4 MongoDB \u90e8\u7f72\u4e2d\u7684\u554f\u984c\uff0c\u9032\u800c\u5c0e\u81f4\u932f\u8aa4\u4ee3\u78bc &#8211; 108\u3002\u8981\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u90e8\u7f72\u4e2d\u6240\u6709\u7bc0\u9ede\u7684\u8907\u88fd\u96c6\u540d\u7a31\u4e00\u81f4\u3002\u901a\u904e\u672c\u6587\u4e2d\u6982\u8ff0\u7684\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u89e3\u6c7a MongoDB \u932f\u8aa4\u4ee3\u78bc &#8211; 108 &#8211; InconsistentReplicaSetNames\uff0c\u4e26\u78ba\u4fdd MongoDB \u8cc7\u6599\u5eab\u7684\u6b63\u5e38\u904b\u884c\u3002<\/p>\n<p>\u5982\u9700\u53ef\u9760\u4e14\u9ad8\u6548\u80fd\u7684 VPS \u8a17\u7ba1\u89e3\u6c7a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4fee\u5fa9 MongoDB \u932f\u8aa4\u4ee3&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-21698","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=21698"}],"version-history":[{"count":2,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21698\/revisions"}],"predecessor-version":[{"id":23705,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21698\/revisions\/23705"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}