ETCD成员维护

# For each machineTOKEN=my-etcd-token-1CLUSTER_STATE=newNAME_1=etcd-node-1NAME_2=etcd-node-2NAME_3=etcd-node-3HOST_1=10.240.0.13HOST_2=10.240.0.14HOST_3=10.240.0.15CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380# For node 1THIS_NAME=${NAME_1}THIS_IP=${HOST_1}etcd --data-dir=data.etcd --name ${THIS_NAME} \--initial-advertise-peer-urls http://${THIS_IP}:2380 \--listen-peer-urls http://${THIS_IP}:2380 \--advertise-client-urls http://${THIS_IP}:2379 \--listen-client-urls http://${THIS_IP}:2379 \--initial-cluster ${CLUSTER} \--initial-cluster-state ${CLUSTER_STATE} \--initial-cluster-token ${TOKEN}# For node 2THIS_NAME=${NAME_2}THIS_IP=${HOST_2}etcd --data-dir=data.etcd --name ${THIS_NAME} \--initial-advertise-peer-urls http://${THIS_IP}:2380 \--listen-peer-urls http://${THIS_IP}:2380 \--advertise-client-urls http://${THIS_IP}:2379 \--listen-client-urls http://${THIS_IP}:2379 \--initial-cluster ${CLUSTER} \--initial-cluster-state ${CLUSTER_STATE} \--initial-cluster-token ${TOKEN}# For node 3THIS_NAME=${NAME_3}THIS_IP=${HOST_3}etcd --data-dir=data.etcd --name ${THIS_NAME} \--initial-advertise-peer-urls http://${THIS_IP}:2380 \--listen-peer-urls http://${THIS_IP}:2380 \--advertise-client-urls http://${THIS_IP}:2379 \--listen-client-urls http://${THIS_IP}:2379 \--initial-cluster ${CLUSTER} \--initial-cluster-state ${CLUSTER_STATE} \--initial-cluster-token ${TOKEN}

Then replace a member with member remove and member add commands:

# get member IDexport ETCDCTL_API=3HOST_1=10.240.0.13HOST_2=10.240.0.14HOST_3=10.240.0.15etcdctl --endpoints=${HOST_1}:2379,${HOST_2}:2379,${HOST_3}:2379 member list# remove the memberMEMBER_ID=278c654c9a6dfd3betcdctl --endpoints=${HOST_1}:2379,${HOST_2}:2379,${HOST_3}:2379 \member remove ${MEMBER_ID}# add a new member (node 4)export ETCDCTL_API=3NAME_1=etcd-node-1NAME_2=etcd-node-2NAME_4=etcd-node-4HOST_1=10.240.0.13HOST_2=10.240.0.14HOST_4=10.240.0.16 # new memberetcdctl --endpoints=${HOST_1}:2379,${HOST_2}:2379 \member add ${NAME_4} \--peer-urls=http://${HOST_4}:2380

Next, start the new member with --initial-cluster-state existing flag:

# [WARNING] If the new member starts from the same disk space,# make sure to remove the data directory of the old member## restart with 'existing' flagTOKEN=my-etcd-token-1CLUSTER_STATE=existingNAME_1=etcd-node-1NAME_2=etcd-node-2NAME_4=etcd-node-4HOST_1=10.240.0.13HOST_2=10.240.0.14HOST_4=10.240.0.16 # new memberCLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_4}=http://${HOST_4}:2380THIS_NAME=${NAME_4}THIS_IP=${HOST_4}etcd --data-dir=data.etcd --name ${THIS_NAME} \--initial-advertise-peer-urls http://${THIS_IP}:2380 \--listen-peer-urls http://${THIS_IP}:2380 \--advertise-client-urls http://${THIS_IP}:2379 \--listen-client-urls http://${THIS_IP}:2379 \--initial-cluster ${CLUSTER} \--initial-cluster-state ${CLUSTER_STATE} \--initial-cluster-token ${TOKEN}
计算机