etcd节点状态

  • 在 Raft 协议中,一个节点可以处于以下三种状态之一:
    1. Leader:领导者
    2. Follower:跟随者
    3. Candidate:候选人
  • etcd节点本身有2种成员状态
    1. learner:无法被选为leader,可通过etcdctl member promete变更
    2. voting:默认,可参与leader选举

Docker方式部署(3节点增到5节点)

  • 添加节点4 docker exec -it db23999d731d etcdctl --endpoints http://localhost:2380,http://localhost:22380,http://localhost:32380 member add s4 --peer-urls=http://localhost:4380
  • 启动节点4 systemctl restart s4.service
s4.service 具体配置
  • 使用主机网络--net=host
  • 数据目录映射到--volume=/tmp/etcd/s4:/etcd-data
  • 新增--initial-cluster s4=http://localhost:4380
  • 新增节点4配置--initial-cluster-state existing
[Unit]
Description=etcd with Docker
Documentation=https://github.com/coreos/etcd

[Service]
Restart=always
RestartSec=5s
TimeoutStartSec=0
LimitNOFILE=40000

ExecStart=/usr/bin/docker \
  run \
  --rm \
  --net=host \
  --name s4-etcd-v3.5.8 \
  --volume=/tmp/etcd/s4:/etcd-data \
  gcr.io/etcd-development/etcd:v3.5.8 \
  /usr/local/bin/etcd \
  --name s4 \
  --data-dir /etcd-data \
  --listen-client-urls http://localhost:4379 \
  --advertise-client-urls http://localhost:4379 \
  --listen-peer-urls http://localhost:4380 \
  --initial-advertise-peer-urls http://localhost:4380 \
  --initial-cluster s1=http://localhost:2380,s2=http://localhost:22380,s3=http://localhost:32380,s4=http://localhost:4380 \
  --initial-cluster-token tkn \
  --initial-cluster-state existing

ExecStop=/usr/bin/docker stop etcd-v3.5.8

[Install]
WantedBy=multi-user.target

参考链接:

etcd Labs