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
相关文章
相关标签/搜索