ETCD數據空間壓縮清理

場景:作etcd數據鏡像的時候出現以下錯誤  Error: etcdserver: mvcc: database space exceededhtml

經過查找官方文檔https://coreos.com/etcd/docs/latest/op-guide/maintenance.html 肯定解決方案,經過執行命令壓縮etcd空間而且整理空間碎片便可數據庫

命令以下:json

#使用API3
export ETCDCTL_API=3
# 查看告警信息,告警信息通常 memberID:8630161756594109333 alarm:NOSPACE
etcdctl --endpoints=http://127.0.0.1:2379 alarm list

# 獲取當前版本
rev=$(etcdctl --endpoints=http://127.0.0.1:2379 endpoint status --write-out="json" | egrep -o '"revision":[0-9]*' | egrep -o '[0-9].*')
# 壓縮掉全部舊版本
etcdctl --endpoints=http://127.0.0.1:2379 compact $rev
# 整理多餘的空間
etcdctl --endpoints=http://127.0.0.1:2379 defrag
# 取消告警信息
etcdctl --endpoints=http://127.0.0.1:2379 alarm disarm

 

數據壓縮完成以後數據大小和內存佔用信息以下:mvc

 

 經過上圖能夠看出,壓縮操做執行完以後數據庫大小和內存佔用率降低了不少,總體的性能也會有所提高ide

 

說明:性能

壓縮ETCD空間也能夠減小etcd程序的內存佔用量,提升etcd性能,在沒有問題的時候提早進行壓縮也是明智的選擇ui

 

經過線上實踐發現仍是設置自動壓縮更靠譜,官方一樣提供數據自動壓縮方式,歷史數據只保留一個小時的spa

詳細信息能夠參考官方文檔: https://coreos.com/etcd/docs/latest/op-guide/maintenance.html#history-compactioncode

etcd can be set to automatically compact the keyspace with the --auto-compaction option with a period of hours:

# keep one hour of history
$ etcd --auto-compaction-retention=1
相關文章
相關標籤/搜索