IP錯誤引起MongoDB複本集初始化失敗

來源:互聯網
上載者:User

標籤:uri   MLOG   fork   cat   2.0   配置命令   bpa   mongodb   tor   

問題描述:

在給客戶搭建環境的時候,在初始化一個MongoDB複本集的過程中,出現了初始化失敗,報"No host described in new configuration 1 for replica set mongotest maps to this node"。具體報錯資訊如下(為保護客戶隱私,IP均經過處理):

2018-06-20T11:51:45.695+0800 I CONTROL  [initandlisten]> config = { _id:"mongotest", members:[  {_id:0,host:"10.0.0.217:27017"}]  };{        "_id" : "mongotest",        "members" : [                {                        "_id" : 0,                        "host" : "10.0.0.217:27017"                }        ]}> rs.initiate(config);{        "ok" : 0,        "errmsg" : "No host described in new configuration 1 for replica set mongotest maps to this node",        "code" : 93,        "codeName" : "InvalidReplicaSetConfig"}> 

在執行 config = { _id:"mongotest", members:[ {_id:0,host:"10.0.0.217:27017"}] };的時候成功了,但是執行 rs.initiate(config);的時候一直在報這個錯誤。

原因分析:

看到"No host described in new configuration 1 for replica set mongotest maps to this node"的提示,懷疑是命令列和mongo.conf檔案裡面的配置不一致,但是查看設定檔,確實配置的是mongotest:

[[email protected] ~]# cat /etc/mongodb/mongo.confsystemLog:   destination: file   path: "/opt/mongodb/mongod.log"   logAppend: truestorage:   journal:      enabled: true   dbPath: /opt/mongodbsetParameter:   enableLocalhostAuthBypass: truereplication:   replSetName: mongotest     #和執行的命令列是一致的,沒有問題processManagement:   fork: true   pidFilePath: "/opt/mongodb/mongod.pid"security:   authorization: enabled   keyFile: "/etc/mongodb/mongodb-keyfile"[[email protected] ~]#

於是想到會不會是IP的問題。
因為進入這台機器是用的Bastion Host進去,機器的hostname和命令列視窗顯示的機器IP都是10.0.0.217。但是實際上原生IP並不是這個,ifconfig查看真實的IP地址實際為172.0.2.12,而不是hostname顯示的10.0.0.217.在配置命令列的時候,直接用了hostname的IP,因此出現了這個報錯。

解決方案:

將命令中的IP替換為正確的IP,然後再在MongoDB命令列裡面重新執行命令,就OK了:

2018-06-20T11:51:45.695+0800 I CONTROL  [initandlisten]> config = { _id:"mongotest", members:[  {_id:0,host:"172.0.2.12:27017"}]  };{        "_id" : "mongotest",        "members" : [                {                        "_id" : 0,                        "host" : "172.0.2.12:27017"                }        ]}> rs.initiate(config);     #這次就不再報錯了{ "ok" : 1 }mongotest:OTHER>mongotest:SECONDARY>mongotest:PRIMARY>mongotest:PRIMARY>mongotest:PRIMARY>mongotest:PRIMARY>

單點的複本集就好了。

IP錯誤引起MongoDB複本集初始化失敗

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.