elasticsearch半數(shù)以上master節(jié)點(diǎn)丟失, 如何恢復(fù)

起因: 本地搭建了集群, 想著擴(kuò)充節(jié)點(diǎn)數(shù)目, 就復(fù)制了安裝目錄, 改了nodename, 以及port等, 刪除data目錄. 但是操作失誤, 最終還是導(dǎo)致腦裂了, 三個(gè)master節(jié)點(diǎn), 其中有一個(gè)data被刪除了, 另外兩個(gè)竟然分別屬于不同的集群, 無(wú)法選主...

這種情況下, 雖然 data都在, 都存活, 但是集群已經(jīng)不能提供管理服務(wù)了. 而就是刪除了所有的master節(jié)點(diǎn), 重建一個(gè)master集群, 也不能和原先的data節(jié)點(diǎn)們組成集群. 這樣元數(shù)據(jù)就丟失了...

參考:
類(lèi)似場(chǎng)景:
https://discuss.elastic.co/t/how-to-recover-cluster-when-2-master-nodes-have-been-lost/269472/2
https://discuss.elastic.co/t/recover-data-after-the-lost-of-master-7-1-1/187775/5
工具說(shuō)明鏈接:
tool-1 https://www.elastic.co/guide/en/elasticsearch/reference/current/node-tool.html#node-tool-detach-cluster

半數(shù)以上master節(jié)點(diǎn)丟失(確定無(wú)法恢復(fù))

from tool-1

If there is at least one remaining master-eligible node, but it is not possible to restart a majority of them, then the elasticsearch-node unsafe-bootstrap command will unsafely override the cluster’s voting configuration as if performing another cluster bootstrapping process. The target node can then form a new cluster on its own by using the cluster metadata held locally on the target node.

如果集群中還剩半數(shù)以下 的master-eligible, 無(wú)論它的元數(shù)據(jù)是否完整, 是否最新. 我們都可以基于它來(lái)恢復(fù)之前的集群(可能有元數(shù)據(jù)丟失, 落后等, 所以是unsafe), 不過(guò)在執(zhí)行的時(shí)候, 還是可以看下, 哪個(gè)剩余節(jié)點(diǎn)的元數(shù)據(jù)更新, 通過(guò)term和version判斷. 這兩個(gè)值在執(zhí)行工具命令的時(shí)候, 會(huì)看到(見(jiàn)下圖unsafe-bootstrap)

步驟

  1. Make sure you have really lost access to at least half of the master-eligible nodes in the cluster, and they cannot be repaired or recovered by moving their data paths to healthy hardware.
  2. Stop all remaining nodes.
  3. Choose one of the remaining master-eligible nodes to become the new elected master as described above.
  4. On this node, run the elasticsearch-node unsafe-bootstrap command as shown below. Verify that the tool reported Master node was successfully bootstrapped.
  5. Start this node and verify that it is elected as the master node.
  6. Run the elasticsearch-node detach-cluster tool, described below, on every other node in the cluster.
  7. Start all other nodes and verify that each one joins the cluster.
  8. Investigate the data in the cluster to discover if any was lost during this process.

注意事項(xiàng) :

  1. 關(guān)閉 security 功能. (如果開(kāi)啟了, 最好先關(guān)閉security插件功能
    1. 因?yàn)樾聠?dòng)的master節(jié)點(diǎn), 沒(méi)有數(shù)據(jù)節(jié)點(diǎn)(如果只配置了一個(gè)master的角色), 那security插件的初始化無(wú)法完成, 各類(lèi)接口不好調(diào)用
    2. 如果給新啟動(dòng)的mster節(jié)點(diǎn), 配置了master and data, 則security插件會(huì)初始化成功. 會(huì)插入index, 但是這個(gè)index會(huì)和原來(lái)的data節(jié)點(diǎn)上保存的沖突. 不知道怎么解.
  2. 能成功, 不代表沒(méi)有數(shù)據(jù)丟失.
  3. 在unsafe-bootstrap的節(jié)點(diǎn), 必須是關(guān)閉的
  4. 所有其他或者的master-eligible節(jié)點(diǎn)(如果有) 必須是關(guān)閉的. all other master-eligible nodes are also stopped while this tool is running, but the tool does not check this.
unsafe-bootstrap.png
detach.png

所有master節(jié)點(diǎn)丟失(確定無(wú)法恢復(fù))

而, 如果所有的master節(jié)點(diǎn)都丟了, 且確定恢復(fù)不了了. 那只能把原來(lái)的data節(jié)點(diǎn)們分離出來(lái), 加入到一個(gè)新的空集群, 并且fix dangling index.

步驟 和之前類(lèi)似, 不過(guò)是啟動(dòng)一個(gè)新集群.

  1. Make sure you have really lost access to every one of the master-eligible nodes in the cluster, and they cannot be repaired or recovered by moving their data paths to healthy hardware.
  2. Start a new cluster and verify that it is healthy. This cluster may comprise one or more brand-new master-eligible nodes, or may be an unsafely-bootstrapped cluster formed as described above.
  3. Stop all remaining data nodes.
  4. On each data node, run the elasticsearch-node detach-cluster tool as shown below. Verify that the tool reported Node was successfully detached from the cluster.
  5. If necessary, configure each data node to discover the new cluster.
  6. Start each data node and verify that it has joined the new cluster.
  7. Wait for all recoveries to have completed, and investigate the data in the cluster to discover if any was lost during this process. Use the Dangling indices API to list, import or delete any dangling indices.

注意事項(xiàng)
與前面略同.

新集群無(wú)法啟動(dòng)排查

無(wú)法啟動(dòng), 可能是因?yàn)樾录翰粔蛐? (雖然它可能是從舊的master-eligible節(jié)點(diǎn)的元數(shù)據(jù)而來(lái))

  1. 關(guān)閉 security 安全插件 , 最好, 方便排查
  2. 有些來(lái)自舊集群的persistence設(shè)置, 導(dǎo)致無(wú)法啟動(dòng)
    1. 使用elasticsearch-node remove-settings
    2. 使用 elasticsearch-node remove-custom
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末宵蕉,一起剝皮案震驚了整個(gè)濱河市皱炉,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌耿芹,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,607評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異入蛆,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)硕勿,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,239評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門(mén)哨毁,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人源武,你說(shuō)我怎么就攤上這事扼褪∠牖茫” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 164,960評(píng)論 0 355
  • 文/不壞的土叔 我叫張陵话浇,是天一觀的道長(zhǎng)脏毯。 經(jīng)常有香客問(wèn)我,道長(zhǎng)幔崖,這世上最難降的妖魔是什么食店? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,750評(píng)論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮赏寇,結(jié)果婚禮上吉嫩,老公的妹妹穿的比我還像新娘。我一直安慰自己嗅定,他們只是感情好自娩,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,764評(píng)論 6 392
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著露戒,像睡著了一般椒功。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上智什,一...
    開(kāi)封第一講書(shū)人閱讀 51,604評(píng)論 1 305
  • 那天动漾,我揣著相機(jī)與錄音,去河邊找鬼荠锭。 笑死旱眯,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的证九。 我是一名探鬼主播删豺,決...
    沈念sama閱讀 40,347評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼愧怜!你這毒婦竟也來(lái)了呀页?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,253評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤拥坛,失蹤者是張志新(化名)和其女友劉穎蓬蝶,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體猜惋,經(jīng)...
    沈念sama閱讀 45,702評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡丸氛,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,893評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了著摔。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片缓窜。...
    茶點(diǎn)故事閱讀 40,015評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出禾锤,到底是詐尸還是另有隱情私股,我是刑警寧澤,帶...
    沈念sama閱讀 35,734評(píng)論 5 346
  • 正文 年R本政府宣布时肿,位于F島的核電站庇茫,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏螃成。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,352評(píng)論 3 330
  • 文/蒙蒙 一查坪、第九天 我趴在偏房一處隱蔽的房頂上張望寸宏。 院中可真熱鬧,春花似錦偿曙、人聲如沸氮凝。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,934評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)罩阵。三九已至,卻和暖如春启摄,著一層夾襖步出監(jiān)牢的瞬間稿壁,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,052評(píng)論 1 270
  • 我被黑心中介騙來(lái)泰國(guó)打工歉备, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留傅是,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,216評(píng)論 3 371
  • 正文 我出身青樓蕾羊,卻偏偏與公主長(zhǎng)得像喧笔,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子龟再,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,969評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容