etcd 入门 - 二进制部署单节点etcd

下载地址:Releases · etcd-io/etcd (github.com)

解压

1
tar zxvf etcd-v3.5.13-linux-amd64.tar.gz

添加到环境变量目录

1
2
cd etcd-v3.5.13-linux-amd64
mv etcd etcdctl etcdutl /usr/local/bin/

创建配置文件目录与数据目录

1
2
mkdir -p /etc/etcd
mkdir -p /data/etcd

注册系统服务

1
vim /etc/systemd/system/etcd.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[Unit]
Description=Etcd Server
After=network.target
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
EnvironmentFile=/etc/etcd/etcd.conf
ExecStart=/usr/local/bin/etcd --config-file=/etc/etcd/etcd.conf
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

修改配置文件

1
2
3
4
5
6
# 节点名称
name: 'etcd-1'
# 指定节点的数据存储目录
data-dir: '/data/etcd'
# 对外提供服务的地址,客户端会连接到这里和 etcd 交互
listen-client-urls: 'http://10.20.13.10:2379,http://127.0.0.1:2379'

设置开机自启并启动

1
2
systemctl daemon-reload
systemctl enable etcd --now

测试

1
etcdctl endpoint status --cluster -w table

image-20240422160908837

image-20240422160429784