Apache > ZooKeeper
 

ZooKeeper 快照和還原指南

Zookeeper 旨在承受機器故障。Zookeeper 集群可以自動從臨時故障中復原,例如機器重新開機。對於 N 個成員的集群,它還可以容忍多達 (N-1)/2 的永久故障,原因是硬體故障或磁碟損毀等。當成員永久故障時,它會失去對集群的存取權。如果集群永久失去超過 (N-1)/2 的成員,它將慘遭失敗並失去法定人數。一旦失去法定人數,集群就無法達成共識,因此無法繼續接受更新。

為了從這些慘烈的故障中復原,Zookeeper 提供快照和還原功能,以從快照中還原集群。

  1. 快照和還原透過管理員伺服器 API 在已連線的伺服器上執行
  2. 快照和還原受到速率限制,以保護伺服器不會過載
  3. 快照和還原需要在具有所有權限的根路徑上進行驗證和授權。支援的驗證架構為摘要、x509 和 IP。

快照

還原集群需要來自 ZooKeeper 集群的快照。使用者可以定期從具有最高 zxid 的執行中伺服器擷取快照,並將資料串流到本機或外部儲存/檔案系統(例如 S3)。

# The snapshot command takes snapshot from the server it connects to and rate limited to once every 5 mins by default
curl -H 'Authorization: digest root:root_passwd' http://hostname:adminPort/commands/snapshot?streaming=true --output snapshotFileName

還原

還原集群需要單一快照作為輸入串流。還原可用於還原失去法定人數的集群,或使用種子資料建立全新的集群。

所有成員都應使用相同的快照進行還原。以下是建議的步驟

# The restore command takes a snapshot as input stream and restore the db of the server it connects. It is rate limited to once every 5 mins by default
curl -H 'Content-Type:application/octet-stream' -H 'Authorization: digest root:root_passwd' -POST http://hostname:adminPort/commands/restore --data-binary "@snapshotFileName"