ETCD 集群部署
0.測試環境
?? ?Linux(ubuntu18.04)*3 ?etcd 3.x
?? ?192.168.0.104 ? 節點1
?? ?192.168.0.107 ? 節點2
?? ?192.168.0.108 ? 節點3
1.安裝,可以直接下載二進制,也可以直接apt安裝,這里直接apt安裝(三個節點都要安裝)
?? ?
?? ?apt-get update ? ? ? //更新apt
?? ?apt install etcd ? ? //安裝etcd
?? ?export ETCDCTL_API=3 //etcdctl默認2.x的版本操作,這里聲明用3.x版本操作
?? ?etcdctl version ? ? ?//確認安裝成功
2.創建配置文件etcd.conf 目錄自己定,我是放在 /etc/etcd3/etcd.conf
三個節點的內容如下(三個節點都要配置)(替換成自己的IP和路徑)
name: etcd-1
data-dir: /etc/etcd3/data
listen-client-urls: http://0.0.0.0:2379,http://127.0.0.1:2379
advertise-client-urls: http://192.168.0.104:2379
listen-peer-urls: http://0.0.0.0:2380
initial-advertise-peer-urls: http://192.168.0.104:2380
initial-cluster: etcd-1=http://192.168.0.104:2380,etcd-2=http://192.168.0.107:2380,etcd-3=http://192.168.0.108:2380
initial-cluster-token: etcd-cluster-my
initial-cluster-state: new
name: etcd-2
data-dir: /etc/etcd3/data
listen-client-urls: http://0.0.0.0:2379
advertise-client-urls: http://192.168.0.107:2379
listen-peer-urls: http://0.0.0.0:2380
initial-advertise-peer-urls: http://192.168.0.107:2380
initial-cluster: etcd-1=http://192.168.0.104:2380,etcd-2=http://192.168.0.107:2380,etcd-3=http://192.168.0.108:2380
initial-cluster-token: etcd-cluster-my
initial-cluster-state: exist
name: etcd-3
data-dir: /etc/etcd3/data
listen-client-urls: http://0.0.0.0:2379
advertise-client-urls: http://192.168.0.108:2379
listen-peer-urls: http://0.0.0.0:2380
initial-advertise-peer-urls: http://192.168.0.108:2380
initial-cluster: etcd-1=http://192.168.0.104:2380,etcd-2=http://192.168.0.107:2380,etcd-3=http://192.168.0.108:2380
initial-cluster-token: etcd-cluster-my
initial-cluster-state: exist
字段說明
?? ?name:本member的名稱
?? ?data-dir:存儲的數據目錄
?? ?listen-client-urls:用于監聽客戶端etcdctl或者curl連接;0.0.0.0表示監聽本機所有地址
?? ?listen-peer-urls:用于監聽集群中其它member的連接;0.0.0.0表示監聽本機所有地址
?? ?advertise-client-urls: 本機地址, 用于通知客戶端,客戶端通過此IPs與集群通信
?? ?initial-advertise-peer-urls:本機地址,用于通知集群member,與member通信
?? ?initial-cluster:描述集群中所有節點的信息,描述每個節點名稱、ip、端口,集群靜態啟動使用,本member根據此信息去聯系其他member
?? ?initial-cluster-token:集群唯一標示
?? ?initial-cluster-state:集群狀態,新建集群時候設置為new,若是想加入某個已經存在的集群設置為existing
?? ?
4.啟動執行(替換成自己的路徑)
?? ?etcd --config-file /etc/etcd3/etcd.conf
?? ?
5.查看集群狀態
看下節點列表
?? ?etcdctl member list
結果
?? ?5eda8a03ef4ff59e, started, etcd-3, http://192.168.0.108:2380, http://192.168.0.108:2379
?? ?882a1d2f17c73e06, started, etcd-1, http://192.168.0.104:2380, http://192.168.0.104:2379
?? ?9cac2257803e1d3d, started, etcd-2, http://192.168.0.107:2380, http://192.168.0.107:2379
看下健康狀態(每臺機器都可以單獨執行查看)
?? ?etcdctl endpoint health?
結果?? ?
?? ?127.0.0.1:2379 is healthy: successfully committed proposal: took = 4.595363ms
?? ?
PS:要關防火墻,不然在數據同步或者選舉的時候一直提示超時。ubuntu關閉防火墻直接執行 sudo ufw disable
6.測試
? 找一個節點執行put一下,找另一個節點get一下,看看數據能不能同步過來就行了。
??
最后:
? ETCD集群是支持HTTPS安全配置的,之后會把這個補充上,同時還有很多細節可以自行研究,比如說
? export ETCDCTL_API=3 這個是版本,每次打開bash的時候都要設置,可以直接
? echo 'export ETCDCTL_API=3' >> ?~/.bashrc 一次性配置。
? 在比如說etcd通常是要開機自啟動的,可以配置服務來做。等等。
? 后期還會整理補充一些原理性的東西,比如選舉算法。節點壞掉會怎么樣,還有就是很重要的一個 etcd分布式鎖的部分。
??
?
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
- 上一篇: etcd权限控制
- 下一篇: ETCD-节点挂掉会怎样?