etcd Single Node
| Server IP | Host Role |
|---|---|
| 192.168.10.31 | etcd Server |
etcd Server
-
Download the etcd installation package
- Servers with Internet Access
- Servers without Internet Access
wget https://pdpublic.mingdao.com/private-deployment/offline/common/etcd-v3.6.11-linux-amd64.tar.gz# etcd installation package download link. Download and upload it to the deployment server.https://pdpublic.mingdao.com/private-deployment/offline/common/etcd-v3.6.11-linux-amd64.tar.gz -
Create the etcd runtime user
useradd -M -s /sbin/nologin etcd -
Extract the etcd package and install the binaries
mkdir -p /usr/local/etcd/bintar -zxf etcd-v3.6.11-linux-amd64.tar.gzcp etcd-v3.6.11-linux-amd64/etcd /usr/local/etcd/bin/cp etcd-v3.6.11-linux-amd64/etcdctl /usr/local/etcd/bin/cp etcd-v3.6.11-linux-amd64/etcdutl /usr/local/etcd/bin/chmod +x /usr/local/etcd/bin/etcd*chown -R etcd:etcd /usr/local/etcd -
Create data and log directories
mkdir -p /data/etcdmkdir -p /data/logs/etcdchown -R etcd:etcd /data/etcd /data/logs/etcd -
Modify the etcd configuration file
cat > /usr/local/etcd/etcd.conf.yml <<'EOF'name: etcddata-dir: /data/etcdlisten-client-urls: http://192.168.10.31:2379,http://127.0.0.1:2379advertise-client-urls: http://192.168.10.31:2379listen-peer-urls: http://192.168.10.31:2380initial-advertise-peer-urls: http://192.168.10.31:2380listen-metrics-urls: http://192.168.10.31:2381,http://127.0.0.1:2381initial-cluster: etcd=http://192.168.10.31:2380initial-cluster-token: hap-milvus-etcdinitial-cluster-state: newauto-compaction-mode: periodicauto-compaction-retention: 10hquota-backend-bytes: 8589934592snapshot-count: 100000max-snapshots: 5max-wals: 5strict-reconfig-check: truepre-vote: trueenable-v2: falsemetrics: basiclogger: zaplog-level: infolog-outputs:- /data/logs/etcd/etcd.logenable-log-rotation: truelog-rotation-config-json: '{"maxsize":100,"maxage":180,"maxbackups":0,"localtime":true,"compress":true}'EOF- Replace the IP addresses in
listen-client-urlsandadvertise-client-urlswith the actual deployment server IP.
- Replace the IP addresses in
-
Configure systemd to manage etcd
cat > /etc/systemd/system/etcd.service <<'EOF'[Unit]Description=etcdDocumentation=https://etcd.io/docs/After=network-online.targetWants=network-online.target[Service]Type=simpleUser=etcdGroup=etcdExecStart=/usr/local/etcd/bin/etcd --config-file=/usr/local/etcd/etcd.conf.ymlRestart=on-failureRestartSec=5sLimitNOFILE=65536LimitNPROC=65536OOMScoreAdjust=-999[Install]WantedBy=multi-user.targetEOF -
Start etcd and enable startup on boot
systemctl daemon-reloadsystemctl start etcdsystemctl enable etcd -
Check Service Status
systemctl status etcd --no-pager -
View Runtime Logs
journalctl -u etcd -n 100 -l --no-pager -
Verify the Service
export ETCD_ENDPOINTS=http://192.168.10.31:2379/usr/local/etcd/bin/etcdctl --endpoints=${ETCD_ENDPOINTS} endpoint health -w table/usr/local/etcd/bin/etcdctl --endpoints=${ETCD_ENDPOINTS} endpoint status -w table/usr/local/etcd/bin/etcdctl --endpoints=${ETCD_ENDPOINTS} put /etcd-test/hello world/usr/local/etcd/bin/etcdctl --endpoints=${ETCD_ENDPOINTS} get /etcd-test/hello/usr/local/etcd/bin/etcdctl --endpoints=${ETCD_ENDPOINTS} del /etcd-test/hello -
Enable Authentication
-
Set variables
export ETCD_ENDPOINTS=http://192.168.10.31:2379export ETCD_ROOT_PASSWORD='replace_with_strong_root_password'ETCD_ENDPOINTSspecifies the access endpoint of the current etcd service. All subsequent authentication-related commands use it.ETCD_ROOT_PASSWORDspecifies the root user password. Replace it with a strong password in production deployments.
-
Confirm that the root password variable is set
test -n "$ETCD_ROOT_PASSWORD" && echo "ETCD_ROOT_PASSWORD is set" || echo "ETCD_ROOT_PASSWORD is not set"- Check whether the root password variable is set to avoid using an empty password in later commands.
-
Create the root user
/usr/local/etcd/bin/etcdctl --endpoints=${ETCD_ENDPOINTS} user add "root:${ETCD_ROOT_PASSWORD}"user addcreates therootuser and sets its password.
-
Grant the root role
/usr/local/etcd/bin/etcdctl --endpoints=${ETCD_ENDPOINTS} user grant-role root rootuser grant-role root rootgrants therootrole to therootuser so that it has administrator privileges.
-
View root user information
/usr/local/etcd/bin/etcdctl --endpoints=${ETCD_ENDPOINTS} user get rootuser get rootdisplays information about therootuser and confirms that the user was created successfully.
-
Enable authentication
/usr/local/etcd/bin/etcdctl --endpoints=${ETCD_ENDPOINTS} auth enableauth enableenables etcd authentication. After it is enabled, client access must include user credentials.
-
Verify authentication
/usr/local/etcd/bin/etcdctl --endpoints=${ETCD_ENDPOINTS} --user="root:${ETCD_ROOT_PASSWORD}" auth status/usr/local/etcd/bin/etcdctl --endpoints=${ETCD_ENDPOINTS} --user="root:${ETCD_ROOT_PASSWORD}" endpoint health -w table/usr/local/etcd/bin/etcdctl --endpoints=${ETCD_ENDPOINTS} --user="root:${ETCD_ROOT_PASSWORD}" endpoint status -w table/usr/local/etcd/bin/etcdctl --endpoints=${ETCD_ENDPOINTS} --user="root:${ETCD_ROOT_PASSWORD}" member list -w tableauth statusshows the current authentication status and confirms whether authentication is enabled.endpoint health -w tablechecks endpoint health and confirms that the service remains accessible after authentication is enabled.endpoint status -w tableshows detailed endpoint status and confirms that the single-node instance is running normally.member list -w tableshows the member list and confirms that member information is complete.
-