#Build Image
sudo vim Dockerfile
 
加入以下內容
FROM alpine:latest

ADD etcd /usr/local/bin/
ADD etcdctl /usr/local/bin/
RUN mkdir -p /var/etcd/
RUN mkdir -p /var/lib/etcd/

# Alpine Linux doesn't use pam, which means that there is no /etc/nsswitch.conf,
# but Golang relies on /etc/nsswitch.conf to check the order of DNS resolving
# (see https://github.com/golang/go/commit/9dee7771f561cf6aee081c0af6658cc81fac3918)
# To fix this we just create /etc/nsswitch.conf and add the following line:
RUN echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf

EXPOSE 2379 2380

# Define default command.
CMD ["/usr/local/bin/etcd"]
 
下載etcd Releases
wget https://github.com/etcd-io/etcd/releases/download/v3.3.10/etcd-v3.3.10-linux-amd64.tar.gz
解tar後將etcd,etcdctl跟Dockerfile放在同一路徑下
在此路徑下執行Build Image
docker build -t etcd .
查看是否images buile完
docker images
 
#創建docker cluster
node1 IP : 172.16.133.34
node2 IP : 172.16.133.35
node3 IP : 172.16.133.36
三台分別的docker run腳本為以下
 
node 1
#!/bin/bash

docker rm -f etcd0
docker run -d \
-p 2380:2380 \
-p 2379:2379 \
--name etcd0 etcd /usr/local/bin/etcd \
-name etcd0 \
-advertise-client-urls http://172.16.133.34:2379 \
-listen-client-urls http://0.0.0.0:2379 \
-initial-advertise-peer-urls http://172.16.133.34:2380 \
-listen-peer-urls http://0.0.0.0:2380 \
-initial-cluster-token etcd-cluster-1 \
-initial-cluster "etcd0=http://172.16.133.34:2380,etcd1=http://172.16.133.35:2380,etcd2=http://172.16.133.36:2380" \
-initial-cluster-state new
 
node 2
#!/bin/bash

docker rm -f etcd1
docker run -d \
-p 2380:2380 \
-p 2379:2379 \
--name etcd1 etcd /usr/local/bin/etcd \
-name etcd1 \
-advertise-client-urls http://172.16.133.35:2379 \
-listen-client-urls http://0.0.0.0:2379 \
-initial-advertise-peer-urls http://172.16.133.35:2380 \
-listen-peer-urls http://0.0.0.0:2380 \
-initial-cluster-token etcd-cluster-1 \
-initial-cluster "etcd0=http://172.16.133.34:2380,etcd1=http://172.16.133.35:2380,etcd2=http://172.16.133.36:2380" \
-initial-cluster-state new
 
node 3
#!/bin/bash

docker rm -f etcd2
docker run -d \
-p 2380:2380 \
-p 2379:2379 \
--name etcd2 etcd /usr/local/bin/etcd \
-name etcd2 \
-advertise-client-urls http://172.16.133.36:2379 \
-listen-client-urls http://0.0.0.0:2379 \
-initial-advertise-peer-urls http://172.16.133.36:2380 \
-listen-peer-urls http://0.0.0.0:2380 \
-initial-cluster-token etcd-cluster-1 \
-initial-cluster "etcd0=http://172.16.133.34:2380,etcd1=http://172.16.133.35:2380,etcd2=http://172.16.133.36:2380" \
-initial-cluster-state new
#Cluster 驗證
驗證Cluster members,在Cluster中查詢member應該是要一樣的
curl -L http://172.16.133.34:2379/v2/members
在某台node中推送數據,在其他台應該也要能查詢到
推送數據
 
curl -L http://172.16.133.34:2379/v2/keys/message -XPUT -d value="Hello RC"
查詢數據
curl -L http://172.16.133.34:2379/v2/keys/message
metrics連結
http://172.16.133.34:2379/metrics

By tony

自由軟體愛好者~喜歡不斷的思考各種問題,有新的事物都會想去學習嘗試 做實驗並熱衷研究 沒有所謂頂天的技術 只有謙虛及不斷的學習 精進專業,本站主要以分享系統及網路相關知識、資源而建立。 Github http://stnet253.github.io

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料