etcd元件作為乙個高可用強一致性的服務發現儲存倉庫。我們此次在三個主機上搭建了乙個包含三個etcd節點的集群,實現了集群的動態擴充套件和收縮,並測試和驗證了etcd集群鍵——值儲存的一致性和高可用性。
一、環境準備
os: ubuntu 14.04
user: root
ipaddress: etcd01: 192.168.200.24
etcd02: 192.168.200.25
etcd03: 192.168.200.26
這裡用的是etcd-v2.3.7-linux-amd64.tar.gz
二、安裝配置etcd
etcd01上安裝
tar xf etcd-v2.3.7-linux-amd64.tar.gz
cd etcd-v2.3.7-linux-amd64
cp etcd* /usr/local/bin/
建立etcd01指令碼,可方便配置etcd啟動引數
#cat etcd01
/usr/local/bin/etcd -name etcd01 \
-data-dir /data/etcd01 \
-advertise-client-urls \
-listen-client-urls \
-initial-advertise-peer-urls
-listen-peer-urls \
-initial-cluster-token etcd-cluster-1 \
-initial-cluster etcd01= \
-initial-cluster-state new
引數說明:-name 指定名字
-data-dir 指定資料儲存目錄,預設是當前目錄
-initial-cluster-state 集群狀態 new為新建立集群 existing為已存在(可不指定)
在etcd02 etcd03上分別做相似操作
指令碼中-advertise-client-urls 和 -initial-advertis-peer-urls 引數修改一下即可
然後分別執行指令碼:nohup ./etcd01 &
三、測試
在任一台主機上執行etcdctl member list
#etcdctl member list
6a223770249e927d: name=etcd02 peerurls= clienturls= isleader=false
7e0ce16121dfea24: name=etcd01 peerurls= clienturls= isleader=true
bfc28be8765b503e: name=etcd03 peerurls= clienturls= isleader=false
可以看到集群的節點情況,並能看出哪個是leader節點
我們在etcd01上設定乙個key/value
root@etcd1:~# etcdctl set api_server
這時就可以在任意一台主機上獲取這個key/value
root@etcd2:~# etcdctl get api_server
root@etcd3:~# etcdctl get api_server
在member list上看到etcd01是leader ,這時把etcd01停掉(kill)
用etcdctl cluster-health檢視
root@etcd2:~# etcdctl cluster-health
member 6a223770249e927d is healthy: got healthy result from
failed to check the health of member 7e0ce16121dfea24 on get dial tcp 192.168.200.24:2379: getsockopt: connection refused
failed to check the health of member 7e0ce16121dfea24 on get dial tcp 192.168.200.24:4001: getsockopt: connection refused
member 7e0ce16121dfea24 is unreachable: [ are all unreachable
member bfc28be8765b503e is healthy: got healthy result from
cluster is healthy
並且集群leader進行了重新選舉
root@etcd2:~# etcdctl member list
6a223770249e927d: name=etcd02 peerurls= clienturls= isleader=true
7e0ce16121dfea24: name=etcd01 peerurls= clienturls= isleader=false
bfc28be8765b503e: name=etcd03 peerurls= clienturls= isleader=false
現在etcd02是leader了,這時我們在群集中設定兩個key/value
root@etcd2:~# etcdctl set test01 123456
123456
root@etcd2:~# etcdctl set test02 abcdefg
abcdefg
重新啟動etcd01
root@etcd1:~# etcdctl cluster-health
member 6a223770249e927d is healthy: got healthy result from
member 7e0ce16121dfea24 is healthy: got healthy result from
member bfc28be8765b503e is healthy: got healthy result from
cluster is healthy
root@etcd1:~# etcdctl get test01
123456
root@etcd1:~# etcdctl get test02
abcdefg
但這時在etcd01重新加入集群,並保持了key/value的全域性一致性,由此可見 etcd 搭建的集群是可以實現高可用的。
etcd集群如果收縮很簡單,直接在命令列輸入
etcdctl member remove
$memberid是你即將要刪除節點的etcd的id,etcd的擴充套件有一些地方需要注意一下,我在這裡操作的時候遇到了不少坑。從上文寫到現在,有乙個資料夾很重要,幾乎每個坑都與它有關,那就是-data-dir所宣告的資料夾,注意要擴充套件乙個etcd集群時,首先在集群內的任一台機器上輸入
etcdctl member add $etcd_name
$peer_url
$etcd_name:新加入的etcd節點的名字
$peer_url:一般為新加入的節點 ip:2380
k8s部署之ETCD集群
2018年05月12日 14 04 39 wget cd etcd v3.3.5 linux amd64 進入目錄 把etcd etcdctl兩個檔案複製到要安裝的目錄 mkdir var lib etcd 生成etcd執行時的配置檔案cat etcd 執行時的配置檔案我們生成好了,現在我們來生成e...
離線安裝k8s1 5高可用集群
經常遇到全新初始安裝k8s集群的問題,所以想著搞成離線模式,本著最小依賴原則,採用純shell指令碼編寫 基於centos7 1503 minimal執行指令碼測試ok,預設安裝docker1.12.3 etcd v3.0.15 k8s v1.5.1 本離線安裝所有的依賴都打包放到了網盤,不放心安全...
k8s高可用集群9集群的可用性驗證
1檢視集群中所有namespace裡的容器。發現都是running狀態 root k8s master01 kubectl get pod all namespaces 2檢視監控資料 root k8s master01 kubectl top pod n kube system 3檢查跨網是否可以...