一 介紹
etcd 高可用一致性鍵值存儲系統,使用Raft一直算法處理日志復制以保證數據一致性。主要在搭建kubernates時關注到etcd來研究部署etcd。使用golang語言編寫,和zookeeper一樣可用用於服務注冊發現,以及配置管理等。github地址:https://github.com/coreos/etcd
二 單點部署
1. 使用 git,wget 下載源碼
2. cd etcd-master
3. etcd 啟動

4. 測試
使用 etcdctrl 測試

以上通過單點部署etcd 以及測試體驗etcd作為鍵值存儲所做的工作。
三 實現etcd集群的部署
1. 部署環境
為了方便部署過程只在通過IP指定無需修改host文件指定hostname。
只在一台機器搭建集群通過端口地址不同來區別。
192.168.100.128:2381
192.168.100.128:2382
192.168.100.128:2383
github 集群搭建地址:https://github.com/coreos/etcd/blob/master/Documentation/op-guide/clustering.md#etcd-discovery
2. 啟動
node1:
etcd --name infra0 --initial-advertise-peer-urls http://192.168.100.128:2381 \
--listen-peer-urls http://192.168.100.128:2381 \ --listen-client-urls http://192.168.100.128:2279,http://127.0.0.1:2279 \ --advertise-client-urls http://192.168.100.128:2279 \ --initial-cluster-token etcd-cluster-1 \ --initial-cluster infra0=http://192.168.100.128:2381,infra1=http://192.168.100.128:2382,infra2=http://192.168.100.128:2383 \ --initial-cluster-state newnode2:
etcd --name infra1 --initial-advertise-peer-urls http://192.168.100.128:2382 \
--listen-peer-urls http://192.168.100.128:2382 \ --listen-client-urls http://192.168.100.128:2280,http://127.0.0.1:2280 \ --advertise-client-urls http://192.168.100.128:2280 \ --initial-cluster-token etcd-cluster-1 \ --initial-cluster infra0=http://192.168.100.128:2381,infra1=http://192.168.100.128:2382,infra2=http://192.168.100.128:2383 \ --initial-cluster-state newnode3:
etcd --name infra2 --initial-advertise-peer-urls http://192.168.100.128:2383 \
--listen-peer-urls http://192.168.100.128:2383 \ --listen-client-urls http://192.168.100.128:2281,http://127.0.0.1:2281 \ --advertise-client-urls http://192.168.100.128:2281 \ --initial-cluster-token etcd-cluster-1 \ --initial-cluster infra0=http://192.168.100.128:2381,infra1=http://192.168.100.128:2382,infra2=http://192.168.100.128:2383 \ --initial-cluster-state new3 效果圖
四 描述
另外文檔還給出了TLS ca證書安裝部署方式,以及自動自動證書安裝 部署方式,以及使用DNS啟動部署。
五 docker 環境 etcd 啟動
在github中有Dockerfile文件可以構建鏡像然后根據所需搭建etcd集群容器。
六 總結
etcd 和 zookeeper一樣解決了數據一致性以及通過自動選舉算法實現解決容災問題,保證數據的高可用性以及強一致性。我們可以用etcd做服務注冊發現以及配置管理等。當也可以當作key,vlue存儲鍵值數據。
研究部署etcd主要是為了搭建kubernates服務,因為kubernates系統資源調度使用etcd做服務注冊發現。



