Service Overview
- System user:
etcd - Default node name: auto-generated
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 - Local access only by default (binds to 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
Backup and Restore
Backup a snapshot (save the current etcd state to a file):
etcdctl snapshot save /root/etcd-backup.db
Check snapshot status:
etcdutl snapshot status /root/etcd-backup.db -w table
Stop the etcd service to avoid conflicts:
systemctl stop etcd
Remove existing contents of the data directory:
rm -rf /var/lib/etcd/*
Restore the snapshot:
etcdutl snapshot restore /root/etcd-backup.db --data-dir /var/lib/etcd
Make sure permissions are correct:
chown -R etcd:etcd /var/lib/etcd
Start the etcd service again:
systemctl start etcd
Notes
- Single-node cluster by default, suitable for development/testing.
- Configured with debug log-level.
- For production, enable TLS for client and peer communication.
- Consider setting up a multi-node cluster for high availability.
- Restrict ports 2379 (client) and 2380 (peer) to trusted hosts using firewall rules.
- Modify
/etc/etcd/etcd.ymlfor advanced configuration and restart theetcdservice to apply changes. - Always backup data before performing destructive operations (delete/restore/compact).
- Ensure
/var/lib/etcdis owned byetcd:etcd; incorrect permissions can prevent etcd from starting after restores or data changes.