etcd-3.5.4集群搭建

tar -xvf etcd-v3.5.4-linux-amd64.tar.gz
cd etcd-v3.5.4-linux-amd64
ls -l
sudo cp etcd etcdctl /usr/local/bin/
etcd --version
etcdctl version
sudo vim /etc/systemd/system/etcd.service
[Unit]
Description=etcd key-value store
Documentation=https://github.com/etcd-io/etcd
After=network.target

[Service]
Type=notify
# 如果你的二进制文件不在 /usr/local/bin/,请修改这里的路径
ExecStart=/usr/local/bin/etcd
Restart=always
RestartSec=10s
LimitNOFILE=40000

[Install]
WantedBy=multi-user.target
# 重新加载 systemd 配置
sudo systemctl daemon-reload
# 启动 etcd 服务
sudo systemctl start etcd
# 设置开机自启
sudo systemctl enable etcd
# 查看服务状态
sudo systemctl status etcd

#基本测试
etcdctl put mykey "Hello Etcd"
etcdctl get mykey
etcdctl endpoint health
#配置etcd集群启动指令,3个节点都要配置,模板如下
cat /etc/systemd/system/etcd.service
[Unit]
Description=etcd distributed key-value store
Documentation=https://github.com/etcd-io/etcd
After=network.target

[Service]
Type=notify
ExecStart=/usr/local/bin/etcd \
  --name etcd-1 \
  --data-dir /var/lib/etcd \
  --listen-client-urls http://10.57.86.216:2379,http://127.0.0.1:2379 \
  --advertise-client-urls http://10.57.86.216:2379 \
  --listen-peer-urls http://10.57.86.216:2380 \
  --initial-advertise-peer-urls http://10.57.86.216:2380 \
  --initial-cluster-token my-etcd-cluster \
  --initial-cluster etcd-0=http://10.57.86.217:2380,etcd-1=http://10.57.86.216:2380,etcd-2=http://10.57.86.202:2380 \
  --initial-cluster-state new
Restart=always
RestartSec=10s
LimitNOFILE=40000

[Install]
WantedBy=multi-user.target
查看集群状态
etcdctl --endpoints=http://127.0.0.1:2379 endpoint health
etcdctl --endpoints=http://127.0.0.1:2379 member list
增删key,测试
etcdctl --endpoints=http://10.57.86.217:2379 put /app/config/database_url "test:12345"
etcdctl --endpoints=http://10.57.86.217:2379 get /app/config/database_url
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容