ETCD数据空间压缩清理

场景:做etcd数据镜像的时候出现如下错误  Error: etcdserver: mvcc: database space exceeded

通过查找官方文档https://coreos.com/etcd/docs/latest/op-guide/maintenance.html 确定解决方案,通过执行命令压缩etcd空间并且整理空间碎片即可

命令如下:

#使用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

 

数据压缩完成之后数据大小和内存占用信息如下:

 

 通过上图可以看出,压缩操作执行完之后数据库大小和内存占用率下降了很多,整体的性能也会有所提升

 

说明:

压缩ETCD空间也可以减少etcd程序的内存占用量,提高etcd性能,在没有问题的时候提前进行压缩也是明智的选择

 

通过线上实践发现还是设置自动压缩更靠谱,官方同样提供数据自动压缩方式,历史数据只保留一个小时的

详细信息可以参考官方文档: https://coreos.com/etcd/docs/latest/op-guide/maintenance.html#history-compaction

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

 

根据实践发现只配置auto-compaction-retention只会做碎片整理,不会实际减少空间大小; 如果需要减少大小还是需要使用etcdctl compact 和 etcdctl defrag清理空间

 

posted @ 2018-03-07 18:11  davygeek  阅读(15485)  评论(3编辑  收藏  举报