etcd空间清理

#备份举例

ETCDCTL_API=3 /app/prophet/opt/k8s/bin/etcdctl --cacert=/app/prophet/opt/k8s/etc/kubernetes/ssl/ca.pem --cert=/app/prophet/opt/k8s/etc/kubernetes/ssl/etcd.pem --key=/app/prophet/opt/k8s/etc/kubernetes/ssl/etcd-key.pem --endpoints=xx.xx.xx.ip1:2379,xx.xx.xx.ip2:2379,xx.xx.xx.ip3:2379 snapshot save /mnt/disk0/back/snapshot.db

#如下命令为查看/路径下10条key,如需导出全部需要把--limit 10去掉

ETCDCTL_API=3 /app/prophet/opt/k8s/bin/etcdctl --cacert=/app/prophet/opt/k8s/etc/kubernetes/ssl/ca.pem --cert=/app/prophet/opt/k8s/etc/kubernetes/ssl/etcd.pem --key=/app/prophet/opt/k8s/etc/kubernetes/ssl/etcd-key.pem --endpoints=xx.xx.xx.ip1:2379,xx.xx.xx.ip2:2379,xx.xx.xx.ip3:2379 get / --prefix --keys-only --limit 10 --command-timeout=60s | sed '/^\s*$/d' | tee a.log

###删除key(删除慢不用—)

export ETCDCTL_API=3

grep '/registry/events/' a.log | xargs -I{} /app/prophet/opt/k8s/bin/etcdctl --cacert=/app/prophet/opt/k8s/etc/kubernetes/ssl/ca.pem --cert=/app/prophet/opt/k8s/etc/kubernetes/ssl/etcd.pem --key=/app/prophet/opt/k8s/etc/kubernetes/ssl/etcd-key.pem --endpoints=xx.xx.xx.ip1:2379,xx.xx.xx.ip2:2379,xx.xx.xx.ip3:2379 del {}

#如下命令表示删除前缀为/registry/events/所有的键

ETCDCTL_API=3 /app/prophet/opt/k8s/bin/etcdctl --cacert=/app/prophet/opt/k8s/etc/kubernetes/ssl/ca.pem --cert=/app/prophet/opt/k8s/etc/kubernetes/ssl/etcd.pem --key=/app/prophet/opt/k8s/etc/kubernetes/ssl/etcd-key.pem --endpoints=xx.xx.xx.ip1:2379,xx.xx.xx.ip2:2379,xx.xx.xx.ip3:2379 del --prefix /registry/events/

###收缩碎片内存

ETCDCTL_API=3 /app/prophet/opt/k8s/bin/etcdctl --cacert=/app/prophet/opt/k8s/etc/kubernetes/ssl/ca.pem --cert=/app/prophet/opt/k8s/etc/kubernetes/ssl/etcd.pem --key=/app/prophet/opt/k8s/etc/kubernetes/ssl/etcd-key.pem --endpoints=xx.xx.xx.ip1:2379,xx.xx.xx.ip2:2379,xx.xx.xx.ip3:2379 defrag

####消除警告

ETCDCTL_API=3 /app/prophet/opt/k8s/bin/etcdctl --cacert=/app/prophet/opt/k8s/etc/kubernetes/ssl/ca.pem --cert=/app/prophet/opt/k8s/etc/kubernetes/ssl/etcd.pem --key=/app/prophet/opt/k8s/etc/kubernetes/ssl/etcd-key.pem --endpoints=xx.xx.xx.ip1:2379,xx.xx.xx.ip2:2379,xx.xx.xx.ip3:2379 alarm disarm

返回:memberID:13803658152347727308 alarm:NOSPACE

####查看效果

ETCDCTL_API=3 /app/prophet/opt/k8s/bin/etcdctl --cacert=/app/prophet/opt/k8s/etc/kubernetes/ssl/ca.pem --cert=/app/prophet/opt/k8s/etc/kubernetes/ssl/etcd.pem --key=/app/prophet/opt/k8s/etc/kubernetes/ssl/etcd-key.pem --endpoints=xx.xx.xx.ip1:2379,xx.xx.xx.ip2:2379,xx.xx.xx.ip3:2379 endpoint status

#####重启etcd

systemctl restart kube-etcd

#####回滚恢复

#首先保证保证所有 etcd 节点服务处于停止状态

systemctl stop etcd && systemctl status etcd

#所有节点 etcd 数据目录是空的

mkdir /mnt/disk1/etcd.bak && mv /mnt/disk1/etcd/* /mnt/disk1/etcd.bak # 或者 rm -rf /mnt/disk1/etcd/*

#恢复数据(注意,如果备份文件来源于 etcd 数据目录 member/snap/db 文件,则在恢复时需要添加 --skip-hash-check=true 参数 )

分别在3个节点执行:

ETCDCTL_API=3 /app/prophet/opt/k8s/bin/etcdctl --name=scorepht-a --initial-cluster-token=etcd-cluster-0 --initial-advertise-peer-urls=https://10.80.88.x1:2380 --initial-cluster=scorepht-a=https://10.80.88.x2:2380,scorepht-b=https://10.80.88.95:2380,scorepht-c=https://10.80.88.x3:2380 --data-dir=/mnt/disk1/etcd --skip-hash-check=true snapshot restore /data/etcd-snapshot-20190920-11\:09\:1568950186.db

#依次启动各节点 etcd 服务:

systemctl start etcd

#测试验证:

ETCDCTL_API=3 /app/prophet/opt/k8s/bin/etcdctl --endpoints=xx.xx.xx.ip1:2379,xx.xx.xx.ip2:2379,xx.xx.xx.ip3:2379 --cert=/etc/kubernetes/cert/kubernetes.pem --key=/etc/kubernetes/cert/kubernetes-key.pem --cacert=/etc/kubernetes/cert/ca.pem get /zj-test

/zj-test

1234

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值