- 簡單 : 相比於晦澀難懂的paxos算法,etcd基於相對簡單且易實現的raft算法實現一致性,並通過gRPC提供接口調用
- 安全:支持TLS通信,並可以針對不同的用戶進行對key的讀寫控制
- 高性能:10,000 /秒的寫性能
./bin/etcd
world
infra0 10.0.1.111
infra1 10.0.1.109
infra2 10.0.1.110
--advertise-client-urls
--initial-cluster-token etcd-cluster-1
--initial-cluster
--initial-cluster-state new
./etcd --name infra0 --initial-advertise-peer-urls http://10.0.1.111:2380 \
--listen-peer-urls http://10.0.1.111:2380 \
--listen-client-urls http://10.0.1.111:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://10.0.1.111:2379 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster infra0=http://10.0.1.111:2380,infra1=http://10.0.1.109:2380,infra2=http://10.0.1.110:2380 \
--initial-cluster-state new
./etcd --name infra1 --initial-advertise-peer-urls http://10.0.1.109:2380 \
--listen-peer-urls http://10.0.1.109:2380 \
--listen-client-urls http://10.0.1.109:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://10.0.1.109:2379 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster infra0=http://10.0.1.111:2380,infra1=http://10.0.1.109:2380,infra2=http://10.0.1.110:2380 \
--initial-cluster-state new
./etcd --name infra2 --initial-advertise-peer-urls http://10.0.1.110:2380 \
--listen-peer-urls http://10.0.1.110:2380 \
--listen-client-urls http://10.0.1.110:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://10.0.1.110:2379 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster infra0=http://10.0.1.111:2380,infra1=http://10.0.1.109:2380,infra2=http://10.0.1.110:2380 \
--initial-cluster-state new
[root@localhost etcd-v2.3.4]# ./etcdctl member list
4057b0d6df067950: name=infra0 peerURLs=http://10.0.1.111:2380 clientURLs=http://10.0.1.111:2379 isLeader=false
dca0fb8da20901bc: name=infra2 peerURLs=http://10.0.1.110:2380 clientURLs=http://10.0.1.110:2379 isLeader=true
dcdce7909200f701: name=infra1 peerURLs=http://10.0.1.109:2380 clientURLs=http://10.0.1.109:2379 isLeader=false
[root@localhost etcd-v2.3.4]# ./etcdctl cluster-health
member 4057b0d6df067950 is healthy: got healthy result from http://10.0.1.111:2379
member dca0fb8da20901bc is healthy: got healthy result from http://10.0.1.110:2379
member dcdce7909200f701 is healthy: got healthy result from http://10.0.1.109:2379
cluster is healthy
./etcd --name infra0 --initial-advertise-peer-urls http://10.0.1.111:2380 \
--listen-peer-urls http://10.0.1.111:2380 \
--listen-client-urls http://10.0.1.111:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://10.0.1.111:2379 \
--discovery http://10.0.1.33:2379/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0fb83
./etcd --name infra1 --initial-advertise-peer-urls http://10.0.1.109:2380 \
--listen-peer-urls http://10.0.1.109:2380 \
--listen-client-urls http://10.0.1.109:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://10.0.1.109:2379 \
--discovery http://10.0.1.33:2379/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0fb83
./etcd --name infra2 --initial-advertise-peer-urls http://10.0.1.110:2380 \
--listen-peer-urls http://10.0.1.110:2380 \
--listen-client-urls http://10.0.1.110:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://10.0.1.110:2379 \
--discovery http://10.0.1.33:2379/v2/keys/discovery/6c007a14875d53d9bf0ef5a6fc0257c817f0fb83
$
curl https://discovery.etcd.io/new?size=3 返回
https://discovery.etcd.io/5a2e5485d3579557f1a29d0e6ebe3bfb
- _etcd-server-ssl._tcp.example.com
- _etcd-server._tcp.example.com
- _etcd-client._tcp.example.com
- _etcd-client-ssl._tcp.example.com
$ dig +noall +answer SRV _etcd-server._tcp.example.com
_etcd-server._tcp.example.com. 300 IN SRV 0 0 2380 infra0.example.com.
_etcd-server._tcp.example.com. 300 IN SRV 0 0 2380 infra1.example.com.
_etcd-server._tcp.example.com. 300 IN SRV 0 0 2380 infra2.example.com.
$ dig +noall +answer SRV _etcd-client._tcp.example.com
_etcd-client._tcp.example.com. 300 IN SRV 0 0 2379 infra0.example.com.
_etcd-client._tcp.example.com. 300 IN SRV 0 0 2379 infra1.example.com.
_etcd-client._tcp.example.com. 300 IN SRV 0 0 2379 infra2.example.com.
$ dig +noall +answer infra0.example.com infra1.example.com infra2.example.com
infra0.example.com. 300 IN A 10.0.1.111
infra1.example.com. 300 IN A 10.0.1.109
infra2.example.com. 300 IN A 10.0.1.110
$ etcd --name infra0 \
--discovery-srv example.com \
--initial-advertise-peer-urls http://infra0.example.com:2380 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster-state new \
--advertise-client-urls http://infra0.example.com:2379 \
--listen-client-urls http://infra0.example.com:2379 \
--listen-peer-urls http://infra0.example.com:2380
$ etcd --name infra1 \
--discovery-srv example.com \
--initial-advertise-peer-urls http://infra1.example.com:2380 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster-state new \
--advertise-client-urls http://infra1.example.com:2379 \
--listen-client-urls http://infra1.example.com:2379 \
--listen-peer-urls http://infra1.example.com:2380
$ etcd --name infra2 \
--discovery-srv example.com \
--initial-advertise-peer-urls http://infra2.example.com:2380 \
--initial-cluster-token etcd-cluster-1 \
--initial-cluster-state new \
--advertise-client-urls http://infra2.example.com:2379 \
--listen-client-urls http://infra2.example.com:2379 \
--listen-peer-urls http://infra2.example.com:2380
3.etcd接口訪問
4. etcd使用場景簡述
- 服務啓動後向etcd註冊,並上報自己的監聽的端口以及當前的權重因子等信息,且對該信息設置ttl值。
- 服務在ttl的時間內週期性上報權重因子等信息。
- client端調用服務時向etcd獲取信息,進行調用,同時監聽該服務是否變化(通過watch方法實現)。
- 當新增服務時watch方法監聽到變化,將服務加入代用列表,當服務掛掉時ttl失效,client端檢測到變化,將服務踢出調用列表,從而實現服務的動態擴展。
- 另一方面,client端通過每次變化獲取到的權重因子來進行client端的加權調用策略,從而保證後端服務的負載均衡。
https://coreos.com/etcd/