部署etcd

修改hosts配置文件

  1. vim /etc/hosts
  2. 200.100.128.13 sxsz-spzw-clddb1 1.mongodb.private 1.etcd.private
  3. 200.100.128.14 sxsz-spzw-clddb2 2.mongodb.private 2.etcd.private
  4. 200.100.128.15 sxsz-spzw-clddb3 3.mongodb.private 3.etcd.private

修改环境变量
  1. vim /etc/profile
  2. # etcd
  3. export ETCD_UNSUPPORTED_ARCH=arm64

修改配置文件

  1. vim /opt/etcd/etcd.yaml
  2. data-dir: /data/etcd
  3. debug: false
  4. election-timeout: 1000
  5. heartbeat-interval: 100
  6. initial-advertise-peer-urls: http://3.etcd.private:2380
  7. initial-cluster: 1.etcd.private=http://1.etcd.private:2380,2.etcd.private=http://2.etcd.private:2380,3.etcd.private=http://3.etcd.private:2380
  8. initial-cluster-state: new
  9. initial-cluster-token: test-etcd-cluster
  10. listen-client-urls: http://200.100.128.15:2379
  11. listen-peer-urls: http://200.100.128.15:2380
  12. logger: zap
  13. max-request-bytes: 10485760
  14. max-snapshots: 5
  15. max-wals: 5
  16. name: 3.etcd.private
  17. snapshot-count: 10000

启动ETCD

  1. cd /opt/etcd
  2. ./start.sh
  3. ps -ef | grep etcd
  4. root 12913 1 1 22:38 pts/1 00:00:00 ./etcd --config-file etcd.yml
  5. root 13011 5702 0 22:39 pts/1 00:00:00 grep --color=auto etcd

etcd 添加节点

查看etcd集群状态

  1. export ETCDCTL_API=3
  2. /opt/etcd/etcdctl --endpoints "1.etcd.private:2380" member list
  3. 64a01b5e3fd1cf8, started, 3.etcd.private, http://3.etcd.private:2380, http://localhost:2379
  4. 4f90f03639cbe614, started, 1.etcd.private, http://1.etcd.private:2380, http://localhost:2379

添加新的节点

  1. /opt/etcd/etcdctl --endpoints "1.etcd.private:2380,3.etcd.private:2380" member add 2.etcd.private --peer-urls=http://2.etcd.private:2380
  2. 364a01b5e3fd1cf8, started, 3.etcd.private, http://3.etcd.private:2380, http://localhost:2379
  3. 4f90f03639cbe614, started, 1.etcd.private, http://1.etcd.private:2380, http://localhost:2379
  4. ba38730b22aeca28, unstarted, , http://2.etcd.private:2380,

新节点启动

  1. vim /opt/etcd/etcd.yml
  2. initial-cluster-state: existing

新部署的时候是new

需要把new改为existing

更新新节点状态

  1. /opt/etcd/etcdctl --endpoints "1.etcd.private:2380,3.etcd.private:2380" member update 31a4904602aedcf9 --peer-urls=http://2.etcd.private:2380
  2. /opt/etcd/etcdctl --endpoints "1.etcd.private:2380" member list
  3. 364a01b5e3fd1cf8, started, 3.etcd.private, http://3.etcd.private:2380, http://localhost:2379
  4. 4f90f03639cbe614, started, 1.etcd.private, http://1.etcd.private:2380, http://localhost:2379
  5. ba38730b22aeca28, started, 2.etcd.private, http://2.etcd.private:2380, http://localhost:2379