目录
1、构建集群
1.1 静态配置集群信息
$ etcd --name n1 \
--initial-cluster-token cluster1 \
--initial-cluster-state new \
--listen-client-urls http://Node1:2379,http://localhost:2379 \
--listen-peer-urls http://Node1:2380 \
--advertise-client-urls http://Node1:2379 \
--initial-advertise-peer-urls http://Node1:2380 \
--initial-cluster n1=http://Node1:2380,n2=http://Node2:2380,n3=http://Node3:2380
$ etcd --name n2 \
--initial-cluster-token cluster1 \
--initial-cluster-state new \
--listen-client-urls http://Node2:2379,http://localhost:2379 \
--listen-peer-urls http://Node2:2380 \
--advertise-client-urls http://Node2:2379 \
--initial-advertise-peer-urls http://Node2:2380 \
--initial-cluster n1=http://Node1:2380,n2=http://Node2:2380,n3=http://Node3:2380
$ etcd --name n3 \
--initial-cluster-token cluster1 \
--initial-cluster-state new \
--listen-client-urls http://Node3:2379,http://localhost:2379 \
--listen-peer-urls http://Node3:2380 \
--advertise-client-urls http://Node3:2379 \
--initial-advertise-peer-urls http://Node3:2380 \
--initial-cluster n1=http://Node1:2380,n2=http://Node2:2380,n3=http://Node3:2380
$ etcdctl member list 228428dce5a59f3b: name=n3 peerURLs=http://Node3:2380
clientURLs=http://Node3:2379
5051932762b33d8e: name=n1 peerURLs=http://Node1:2380 clientURLs=http://Node1:2379
8ee612d82821a4e7: name=n2 peerURLs=http://Node2:2380 clientURLs=http://Node2:2379
1.2 动态发现
$ curl https://discovery.etcd.io/new?size=3
https://discovery.etcd.io/7f66dc8d468a1c940969a8c329ee329a
$ etcd --name n1 \
--initial-cluster-token cluster1 \
--initial-cluster-state new \
--listen-client-urls http://Node1:2379,http://localhost:2379 \
--listen-peer-urls http://Node1:2380 \
--advertise-client-urls http://Node1:2379 \
--initial-advertise-peer-urls http://Node1:2380 \
--discovery https://discovery.etcd.io/7f66dc8d468a1c940969a8c329ee329a
$ etcd --name n2 \
--initial-cluster-token cluster1 \
--initial-cluster-state new \
--listen-client-urls http://Node2:2379,http://localhost:2379 \
--listen-peer-urls http://Node2:2380 \
--advertise-client-urls http://Node2:2379 \
--initial-advertise-peer-urls http://Node2:2380 \
--discovery https://discovery.etcd.io/7f66dc8d468a1c940969a8c329ee329a
$ etcd --name n3 \
--initial-cluster-token cluster1 \
--initial-cluster-state new \
--listen-client-urls http://Node3:2379,http://localhost:2379 \
--listen-peer-urls http://Node3:2380 \
--advertise-client-urls http://Node3:2379 \
--initial-advertise-peer-urls http://Node3:2380 \
--discovery https://discovery.etcd.io/7f66dc8d468a1c940969a8c329ee329a
2、集群参数配置
2.1 时钟同步
$ sudo aptitude install ntp
$ sudo service ntp restart
2.2 心跳消息时间间隔和选举时间间隔
$ etcd -heartbeat-interval=200 -election-timeout=2000
$ ETCD_HEARTBEAT_INTERVAL=100 ETCD_ELECTION_TIMEOUT=500 etcd
2.3 snapshot频率
$ etcd -snapshot-count=2000
ETCD_SNAPSHOT_COUNT=2000 etcd