使用环境变量运行新节点,将节点加入集群
代码语言:javascript复制[root@h102 etcd-v2.2.4-linux-amd64]# ETCD_NAME="new-h102" ETCD_INITIAL_CLUSTER="h104=http://192.168.100.104:2380,docker=http://192.168.100.103:2380,new-h102=http://192.168.100.102:2380" ETCD_INITIAL_CLUSTER_STATE="existing" /usr/local/src/etcd/etcd-v2.2.4-linux-amd64/etcd -listen-client-urls http://192.168.100.102:2379,http://127.0.0.1:2379 -advertise-client-urls http://192.168.100.102:2379 -listen-peer-urls http://192.168.100.102:2380 -initial-advertise-peer-urls http://192.168.100.102:2380
2016-02-16 18:46:13.884181 I | flags: recognized and used environment variable ETCD_INITIAL_CLUSTER=h104=http://192.168.100.104:2380,docker=http://192.168.100.103:2380,new-h102=http://192.168.100.102:2380
2016-02-16 18:46:13.884325 I | flags: recognized and used environment variable ETCD_INITIAL_CLUSTER_STATE=existing
2016-02-16 18:46:13.884363 I | flags: recognized and used environment variable ETCD_NAME=new-h102
2016-02-16 18:46:13.884512 I | etcdmain: etcd Version: 2.2.4
2016-02-16 18:46:13.884528 I | etcdmain: Git SHA: bdee27b
2016-02-16 18:46:13.884541 I | etcdmain: Go Version: go1.5.3
2016-02-16 18:46:13.884554 I | etcdmain: Go OS/Arch: linux/amd64
...
...
...
节点可以正常工作
代码语言:javascript复制[root@h102 etcd-v2.2.4-linux-amd64]# curl http://127.0.0.1:2379/v2/keys/message
{"action":"get","node":{"key":"/message","value":"set by h104","modifiedIndex":11,"createdIndex":11}}
[root@h102 etcd-v2.2.4-linux-amd64]#
再次查看成员状态
代码语言:javascript复制[root@h102 etcd-v2.2.4-linux-amd64]# ./etcdctl member list
1b80a88a471eb4b8: name=h104 peerURLs=http://192.168.100.104:2380 clientURLs=http://192.168.100.104:2379
940f6e83e019a03f: name=docker peerURLs=http://192.168.100.103:2380 clientURLs=http://192.168.100.103:2379
cdc1e5e338e27adc: name=new-h102 peerURLs=http://192.168.100.102:2380 clientURLs=http://192.168.100.102:2379
[root@h102 etcd-v2.2.4-linux-amd64]#
Note: 如果要添加多个节点,建议一次只添加一个,然后检查节点和集群运行状态正常后再依次逐个添加其它节点
命令汇总
hostnamectl
cd etcd-v2.2.4-linux-amd64/
./etcd --version
firewall-cmd --add-port=2379/tcp
firewall-cmd --add-port=2380/tcp
firewall-cmd --list-all
./etcd -name docker -initial-advertise-peer-urls http://192.168.100.103:2380
./etcd -name h104 -initial-advertise-peer-urls http://192.168.100.104:2380
./etcd -name h102 -initial-advertise-peer-urls http://192.168.100.102:2380 -listen-peer-urls http://192.168.100.102:2380 -listen-client-urls http://192.168.100.102:2379,http://127.0.0.1:2379 -advertise-client-urls http://192.168.100.102:2379 -initial-cluster-token etcd-cluster-test -initial-cluster docker=http://192.168.100.103:2380,h102=http://192.168.100.102:2380,h104=http://192.168.100.104:2380 -initial-cluster-state new
date
date %s
curl http://127.0.0.1:2379/v2/keys/message -XPUT -d value="set by h104"
curl http://127.0.0.1:2379/v2/keys/message
./etcdctl member --help
./etcdctl member remove 84099faad6d56427
curl http://localhost:2379/v2/members
./etcdctl member add new-h102 http://192.168.100.102:2380
./etcdctl member list
ETCD_NAME="new-h102" ETCD_INITIAL_CLUSTER="h104=http://192.168.100.104:2380,docker=http://192.168.100.103:2380,new-h102=http://192.168.100.102:2380" ETCD_INITIAL_CLUSTER_STATE="existing" /usr/local/src/etcd/etcd-v2.2.4-linux-amd64/etcd -listen-client-urls http://192.168.100.102:2379,http://127.0.0.1:2379 -advertise-client-urls http://192.168.100.102:2379 -listen-peer-urls http://192.168.100.102:2380 -initial-advertise-peer-urls http://192.168.100.102:2380
curl http://127.0.0.1:2379/v2/keys/message
原文地址