7

ETCD配额问题处理与验证 Error: etcdserver: mvcc: database space exceeded

 3 years ago
source link: http://www.eryajf.net/5393.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
database space exceeded |坐而言不如起而行! 二丫讲梵
> 迎刃而解 > ETCD配额问题处理与验证 Error: etcdserver: mvcc: database space exceeded
本文预计阅读时间 11 分钟

先来部署一个单机版的etcd。国外难以下载,感谢华为镜像站:https://mirrors.huaweicloud.com/etcd/

下载到本机解压放到对应目录:

  1. tar xf etcd-v3.3.11-linux-amd64.tar.gz
  2. cd etcd-v3.3.11-linux-amd64/
  3. mv etcd etcdctl /usr/bin/

因为默认的空间配额是2G,官方下载的包内,有如下说明:

  1. The default storage size limit is 2GB, configurable with `--quota-backend-bytes` flag. 8GB is a suggested maximum size for normal environments and etcd warns at startup if the configured value exceeds it.

这里将配额指定为16M便于测试:

  1. $ etcd --quota-backend-bytes=$((16*1024*1024))

启动之后,首先查看一下状态:

  1. $ETCDCTL_API=3 etcdctl --endpoints="http://127.0.0.1:2379" --write-out=table endpoint status
  2. +-----------------------+------------------+---------+---------+-----------+-----------+------------+
  3. | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
  4. +-----------------------+------------------+---------+---------+-----------+-----------+------------+
  5. | http://127.0.0.1:2379 | 8e9e05c52164694d | 3.3.11 | 20 KB | true | 2 | 15 |
  6. +-----------------------+------------------+---------+---------+-----------+-----------+------------+

接着批量写入,查看状态:

  1. $ while [ 1 ]; do dd if=/dev/urandom bs=1024 count=1024 | ETCDCTL_API=3 etcdctl put key || break; done
  2. 。。。。。。
  3. 1024+0 records in
  4. 1024+0 records out
  5. 1048576 bytes (1.0 MB) copied, 0.0830886 s, 12.6 MB/s
  6. Error: etcdserver: mvcc: database space exceeded

看到一个报错说:Error: etcdserver: mvcc: database space exceeded,亦即超出了配额,执行简单的写入:

  1. $ ETCDCTL_API=3 etcdctl put newkey 123
  2. Error: etcdserver: mvcc: database space exceeded

依然是这个错误,再看服务状态:

  1. $ ETCDCTL_API=3 etcdctl --endpoints="http://127.0.0.1:2379" --write-out=table endpoint status
  2. +-----------------------+------------------+---------+---------+-----------+-----------+------------+
  3. | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
  4. +-----------------------+------------------+---------+---------+-----------+-----------+------------+
  5. | http://127.0.0.1:2379 | 8e9e05c52164694d | 3.3.11 | 17 MB | true | 3 | 18 |
  6. +-----------------------+------------------+---------+---------+-----------+-----------+------------+

很明显超出了配额。

使用如下命令查看告警信息:

  1. $ ETCDCTL_API=3 etcdctl put newkey 123
  2. Error: etcdserver: mvcc: database space exceeded

所有的运维管理都在操作 Etcd 的存储空间。存储空间的配额用于控制 Etcd 数据空间的大小,如果 Etcd 节点磁盘空间不足了,配额会触发告警,然后 Etcd 系统将进入操作受限的维护模式。

处理的方案是可以针对如上内容进行压缩。

  1. #使用API3
  2. $ export ETCDCTL_API=3
  3. # 获取当前版本
  4. $ rev=$(etcdctl --endpoints=http://127.0.0.1:2379 endpoint status --write-out="json" | egrep -o '"revision":[0-9]*' | egrep -o '[0-9].*')
  5. # 压缩掉所有旧版本
  6. etcdctl --endpoints=http://127.0.0.1:2379 compact $rev
  7. # 整理多余的空间
  8. etcdctl --endpoints=http://127.0.0.1:2379 defrag
  9. # 取消告警信息
  10. etcdctl --endpoints=http://127.0.0.1:2379 alarm disarm

然后再次查看状态:

  1. $ETCDCTL_API=3 etcdctl --endpoints="http://127.0.0.1:2379" --write-out=table endpoint status
  2. +-----------------------+------------------+---------+---------+-----------+-----------+------------+
  3. | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | RAFT TERM | RAFT INDEX |
  4. +-----------------------+------------------+---------+---------+-----------+-----------+------------+
  5. | http://127.0.0.1:2379 | 8e9e05c52164694d | 3.3.11 | 1.1 MB | true | 3 | 21 |
  6. +-----------------------+------------------+---------+---------+-----------+-----------+------------+

验证写入:

  1. $ ETCDCTL_API=3 etcdctl put eryajf test
  2. OK
  3. $ ETCDCTL_API=3 etcdctl get eryajf
  4. eryajf
  5. test

服务正常了。

dc37be98ce0a1d1e.jpg

4,systemd管理

通常我们使用systemd管理服务,于是可以在启动的时候加入配置信息:

  1. $cat /etc/systemd/system/etcd.service
  2. [Unit]
  3. Description=Etcd
  4. After=network.target
  5. Before=flanneld.service
  6. [Service]
  7. User=root
  8. ExecStart=/usr/bin/etcd -name etcd1 -data-dir /var/lib/etcd --advertise-client-urls http://10.3.7.7:2379,http://127.0.0.1:2379 --listen-client-urls http://10.3.7.7:2379,http://127.0.0.1:2379 --auto-compaction-retention=1 --quota-backend-bytes=8388608000
  9. Restart=on-failure
  10. Type=notify
  11. LimitNOFILE=65536
  12. [Install]
  13. WantedBy=multi-user.target
  • auto-compaction-retention:表示每隔一个小时自动压缩一次
  • quota-backend-bytes:磁盘空间调整为8G,官方建议最大8G。

然后重启即可。

参考:https://etcd.io/docs/v3.4/faq/#what-does-mvcc-database-space-exceeded-mean-and-how-do-i-fix-it


weinxin


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK