ETCD 是一個高可用的分布式鍵值數據庫,可用于服務發現。ETCD 采用 raft 一致性算法,基于 Go 語言實現,隨著CoreOS和Kubernetes等項目在開源社區日益火熱,它們項目中都用到的etcd組件作為一個高可用強一致性的服務發現存儲倉庫,漸漸為開發人員所關注。在云計算時代,如何讓服務快速透明地接入到計算集群中,如何讓共享配置信息快速被集群中的所有機器發現,更為重要的是,如何構建這樣一套高可用、安全、易于部署以及響應快速的服務集群,已經成為了迫切需要解決的問題。etcd為解決這類問題帶來了福音,本文將從etcd的應用場景開始,深入解讀etcd的實現方式,以供開發者們更為充分地享用etcd所帶來的便利。
特點
簡單:安裝配置使用簡單,提供 HTTP API
安全:支持 SSL 證書
可靠:采用 raft 算法,實現分布式系統數據的可用性和一致性
下載安裝包:
[root@master ~]# wget https://github.com/coreos/etcd/releases/download/v3.3.2/etcd-v3.3.2-linux-amd64.tar.gz
復制安裝包到各接點:
[root@master ~]# ansible k8s -m copy -a'src=/root/etcd-v3.3.2-linux-amd64.tar.gz dest=/root/'
部署環境三臺機子:IP--主機名--集群結點名
192.168.27.211 client1 (etcd1)
192.168.27.212 client2 (etcd2)
192.168.27.213 client3 (etcd3)
創新互聯是一家專業提供金臺企業網站建設,專注與成都網站設計、網站制作、H5高端網站建設、小程序制作等業務。10年已為金臺眾多企業、政府機構等服務。創新互聯專業網站設計公司優惠進行中。
[Service]
Type=notify
WorkingDirectory=/etc/etcd-v3.3.2
#User=etcd
ExecStart=/etc/etcd-v3.3.2/etcd --config-file /etc/etcd-v3.3.2/etcd.conf
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
注意:192.168.27.212,192.168.27.213部署如同上面步驟,只需要將步驟4里面接點名字、ip改為自己ip即可。
name: etcd2
data-dir: /etc/etcd-v3.3.2/data
listen-client-urls: http://0.0.0.0:2379
advertise-client-urls: http://192.168.27.212:2379
listen-peer-urls: http://0.0.0.0:2380
initial-advertise-peer-urls: http://192.168.27.212:2380
initial-cluster: etcd1=http://192.168.27.211:2380,etcd2=http://192.168.27.212:2380,etcd3=http://192.168.27.213:2380
initial-cluster-token: etcd-cluster-my
initial-cluster-state: new
name: etcd3
data-dir: /etc/etcd-v3.3.2/data
listen-client-urls: http://0.0.0.0:2379
advertise-client-urls: http://192.168.27.213:2379
listen-peer-urls: http://0.0.0.0:2380
initial-advertise-peer-urls: http://192.168.27.213:2380
initial-cluster: etcd1=http://192.168.27.211:2380,etcd2=http://192.168.27.212:2380,etcd3=http://192.168.27.213:2380
initial-cluster-token: etcd-cluster-my
initial-cluster-state: new
6、啟動成功后查看集群成員及狀態:
[root@client3 etcd-v3.3.2]# etcdctl member list
etcdctl endpoint health --endpoints=192.168.27.211:2379,192.168.27.212:2379,192.168.27.213:2379
[root@client3 etcd-v3.3.2]# etcdctl endpoint status --endpoints=192.168.27.211:2379,192.168.27.212:2379,192.168.27.213:2379
[root@client3 etcd-v3.3.2]# etcdctl endpoint status --endpoints=192.168.27.211:2379
通過非ETCD集群成員訪問測試:
[root@master etcd-v3.3.2]# etcdctl endpoint status --endpoints=192.168.27.211:2379
192.168.27.211:2379, f4e909b85dbd820b, 3.3.2, 25 kB, false, 69, 71
[root@master etcd-v3.3.2]# etcdctl endpoint status --endpoints=192.168.27.211:2379
192.168.27.211:2379, f4e909b85dbd820b, 3.3.2, 25 kB, false, 69, 71
[root@master etcd-v3.3.2]# etcdctl endpoint status --endpoints=192.168.27.211:2379,192.168.27.212:2379,192.168.27.213:2379
192.168.27.211:2379, f4e909b85dbd820b, 3.3.2, 25 kB, false, 69, 71
192.168.27.212:2379, 265ebeb3298fa51f, 3.3.2, 25 kB, false, 69, 71
192.168.27.213:2379, 510ff85ed64c7436, 3.3.2, 25 kB, true, 69, 71
[root@master etcd-v3.3.2]# etcdctl put name jerry --endpoints=192.168.27.211:2379,192.168.27.212:2379,192.168.27.213:2379
OK
[root@master etcd-v3.3.2]# etcdctl put topic "this is a etcd client test" --endpoints=192.168.27.211:2379,192.168.27.212:2379,192.168.27.213:2379
OK
[root@master etcd-v3.3.2]# etcdctl get topic --endpoints=192.168.27.211:2379,192.168.27.212:2379,192.168.27.213:2379
topic
this is a etcd client test
[root@master etcd-v3.3.2]# etcdctl get topic --endpoints=192.168.27.211:2379
topic
this is a etcd client test
Etcd使用:
讀寫鍵值:
[root@client1 etcd-v3.3.2]# etcdctl put key1 value1
OK
[root@client1 etcd-v3.3.2]# etcdctl get key1
key1
value1
前綴讀(將所有前綴是key的鍵值對都讀出來)
鍵值刪除:
[root@client1 etcd-v3.3.2]# etcdctl del key
0
[root@client1 etcd-v3.3.2]# etcdctl get key
[root@client1 etcd-v3.3.2]# etcdctl get key1
key1
value1
[root@client1 etcd-v3.3.2]# etcdctl del key1
1
[root@client1 etcd-v3.3.2]# etcdctl get key1
觀察已無KEY1鍵及值的存在。
按前綴全部刪除
觀察已無鍵值及數據
重新創建三個鍵值:
其它ETCD集群成員上訪問鍵值測試:
監聽某個鍵,每次鍵值有變化
[root@client1 etcd-v3.3.2]# etcdctl watch key --prefix
PUT
key1
value
PUT
key2
jerry
設置過期時間TTL
[root@client2 etcd-v3.3.2]# etcdctl lease grant 30
lease 251f6cf538287411 granted with TTL(30s)
[root@client2 etcd-v3.3.2]# etcdctl put key5 value5 --lease=251f6cf538287411
Error: etcdserver: requested lease not found
[root@client2 etcd-v3.3.2]# etcdctl lease grant 30
lease 251f6cf538287414 granted with TTL(30s)
[root@client2 etcd-v3.3.2]# etcdctl put key5 value5 --lease=251f6cf538287414
OK
[root@client2 etcd-v3.3.2]# etcdctl lease keep-alive 251f6cf538287414
lease 251f6cf538287414 expired or revoked.
[root@client2 etcd-v3.3.2]# etcdctl get key5
[root@client2 etcd-v3.3.2]# etcdctl get key5
網頁題目:分布式鍵值高可用存儲集群架構搭建(ETCD)
網頁URL:http://m.kartarina.com/article14/gecide.html
成都網站建設公司_創新互聯,為您提供電子商務、網站排名、網頁設計公司、商城網站、關鍵詞優化、域名注冊
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯