50% off 所有套餐限时优惠,起价 $2.48/mo
etcd

etcd

etcd 是一个分布式键值存储系统,是 Kubernetes、Consul 和 CoreOS 的核心组件。它基于 Raft 协议实现跨节点的可靠一致性,使用 Go 编写,开源,是服务发现与分布式配置管理的首选方案。

Version

v3.6.9

Operating System

Ubuntu Server 24.04 LTS

Min. RAM

1 GB

IP Types

IPV4,IPV6

Service Overview

  • System user: etcd
  • 默认节点名称:自动生成 etcd-<timestamp>
  • Config file: /etc/etcd/etcd.yml
  • Data directory: /var/lib/etcd
  • Binaries: /usr/local/bin/etcd, /usr/local/bin/etcdctl, and /usr/local/bin/etcdutl
  • Log level: debug

Network & Ports

  • Client traffic: http://localhost:2379
  • Peer traffic: http://localhost:2380
  • 默认仅允许本地访问(绑定到 localhost)

Systemd Management

systemctl status etcd         # Check status
systemctl restart etcd        # Start service
systemctl stop etcd           # Stop service
systemctl restart etcd        # Restart service

Basic Commands

# Check etcd server version
etcd --version

# Check etcdctl client version
etcdctl version

# Check etcdutl version
etcdutl version

# Set a key
etcdctl put mykey "HelloEtcd"

# Get a key
etcdctl get mykey

# List all keys with values
etcdctl get "" --prefix

# List only key names
etcdctl get "" --prefix --keys-only

# Delete a key
etcdctl del mykey

# Check cluster health
etcdctl endpoint health

# List cluster members
etcdctl --endpoints=http://127.0.0.1:2379 member list

# Show cluster leader
etcdctl endpoint status --write-out=table

# Watch a key for changes
etcdctl watch mykey

备份与恢复

备份快照(将当前 etcd 状态保存到文件):

etcdctl snapshot save /root/etcd-backup.db

查看快照状态:

etcdutl snapshot status /root/etcd-backup.db -w table

停止 etcd 服务以避免冲突:

systemctl stop etcd

清空数据目录中的现有内容:

rm -rf /var/lib/etcd/*

恢复快照:

etcdutl snapshot restore /root/etcd-backup.db --data-dir /var/lib/etcd

确认权限设置正确:

chown -R etcd:etcd /var/lib/etcd

重新启动 etcd 服务:

systemctl start etcd

Notes

  • 默认为单节点集群,适合开发和测试使用。
  • 日志级别配置为 debug。
  • 在生产环境中,请为客户端和节点间通信启用 TLS。
  • 建议搭建多节点集群以实现高可用。
  • 使用防火墙规则,将端口 2379(客户端)和 2380(节点间通信)限制为可信主机访问。
  • Modify /etc/etcd/etcd.yml 进行高级配置后,重启 etcd 服务以使更改生效。
  • 执行破坏性操作(删除/还原/压缩)前,务必先备份数据。
  • Ensure /var/lib/etcd is owned by etcd:etcd;权限配置错误可能导致 etcd 在还原或数据变更后无法启动。

更多数据库工具

Related apps.

立即部署 etcd。 From $2.48/mo.