您好,登錄后才能下訂單哦!
本文小編為大家詳細介紹“怎么使用docker compose搭建etcd集群”,內容詳細,步驟清晰,細節處理妥當,希望這篇“怎么使用docker compose搭建etcd集群”文章能幫助大家解決疑惑,下面跟著小編的思路慢慢深入,一起來學習新知識吧。
節點 | IP |
---|---|
etcd1 | 10.10.239.31 |
etcd2 | 10.10.239.32 |
etcd3 | 10.10.239.33 |
ymal文件
version: "3.0" services: etcd1: image: bitnami/etcd:latest container_name: etcd1 restart: always ports: - "2379:2379" - "2380:2380" environment: - ALLOW_NONE_AUTHENTICATION=yes #示例中我們不設置密碼 - ETCD_NAME=etcd1 #節點自己的名字 - ETCD_ADVERTISE_CLIENT_URLS=http://10.10.239.31:2379 #告知集群自己的客戶端地址 - ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379 #設置監聽客戶端通訊的URL列表 - ETCD_INITIAL_ADVERTISE_PEER_URLS=http://10.10.239.31:2380 #告知集群自己集群通訊地址 - ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380 #用于監聽伙伴通訊的URL列表 - ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster #etcd 集群的初始化集群記號 - ETCD_INITIAL_CLUSTER=etcd1=http://10.10.239.31:2380,etcd2=http://10.10.239.32:2380,etcd3=http://10.10.239.33:2380 #集群成員 - ETCD_INITIAL_CLUSTER_STATE=new #初始化集群狀態 volumes: - ./data:/bitnami/etcd
持久化
如果此時啟動,會在當前目錄下創建 ./data 目錄,掛載到容器的 /bitnami/etcd ,但我們要注意的是,容器中啟動etcd的用戶并不是root用戶,很可能沒有在目錄下創建文件的權限。我們有兩個方案:
【方法一】給777權限(不建議)
【方法二】所屬主改成對應宿主機用戶(建議)
方法二操作:
先給./data目錄777權限
查看新生成的文件屬主是宿主機哪個用戶,就將./data目錄屬主改為哪個用戶
再將權限改回755或750,重啟容器
啟動服務
[root@liubei-01 etcd1]# docker-compose up -d
查看結果
[root@liubei-01 etcd1]# docker-compose ps Name Command State Ports ----------------------------------------------------------------------------------------------- etcd1 /opt/bitnami/scripts/etcd/ ... Up 0.0.0.0:2379->2379/tcp, 0.0.0.0:2380->2380/tcp
ymal文件
version: "3.0" services: etcd1: image: bitnami/etcd:latest container_name: etcd2 restart: always ports: - "2379:2379" - "2380:2380" environment: - ALLOW_NONE_AUTHENTICATION=yes - ETCD_NAME=etcd2 - ETCD_ADVERTISE_CLIENT_URLS=http://10.10.239.32:2379 - ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379 - ETCD_INITIAL_ADVERTISE_PEER_URLS=http://10.10.239.32:2380 - ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380 - ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster - ETCD_INITIAL_CLUSTER=etcd1=http://10.10.239.31:2380,etcd2=http://10.10.239.32:2380,etcd3=http://10.10.239.33:2380 - ETCD_INITIAL_CLUSTER_STATE=new volumes: - ./data:/bitnami/etcd
持久化(同上)
啟動服務(同上)
ymal文件
version: "3.0" services: etcd1: image: bitnami/etcd:latest container_name: etcd3 restart: always ports: - "2379:2379" - "2380:2380" environment: - ALLOW_NONE_AUTHENTICATION=yes - ETCD_NAME=etcd3 - ETCD_ADVERTISE_CLIENT_URLS=http://10.10.239.33:2379 - ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379 - ETCD_INITIAL_ADVERTISE_PEER_URLS=http://10.10.239.33:2380 - ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380 - ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster - ETCD_INITIAL_CLUSTER=etcd1=http://10.10.239.31:2380,etcd2=http://10.10.239.32:2380,etcd3=http://10.10.239.33:2380 - ETCD_INITIAL_CLUSTER_STATE=new volumes: - ./data:/bitnami/etcd
持久化(同上)
啟動服務(同上)
查看集群成員
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --write-out=table member list +------------------+---------+-------+--------------------------+--------------------------+------------+ | ID | STATUS | NAME | PEER ADDRS | CLIENT ADDRS | IS LEARNER | +------------------+---------+-------+--------------------------+--------------------------+------------+ | 57d6f74aaa8d5d3e | started | etcd1 | http://10.10.239.31:2380 | http://10.10.239.31:2379 | false | | 9107e491ab549324 | started | etcd3 | http://10.10.239.33:2380 | http://10.10.239.33:2379 | false | | e7b147006e212ca5 | started | etcd2 | http://10.10.239.32:2380 | http://10.10.239.32:2379 | false | +------------------+---------+-------+--------------------------+--------------------------+------------+
查看本節點狀態
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --write-out=table endpoint status +----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ | ENDPOINT | ID | VERSION | DB SIZE | IS LEADER | IS LEARNER | RAFT TERM | RAFT INDEX | RAFT APPLIED INDEX | ERRORS | +----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+ | 127.0.0.1:2379 | 57d6f74aaa8d5d3e | 3.5.4 | 20 kB | true | false | 2 | 10 | 10 | | +----------------+------------------+---------+---------+-----------+------------+-----------+------------+--------------------+--------+
查看本節點健康狀態
I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl --write-out=table endpoint health +----------------+--------+------------+-------+ | ENDPOINT | HEALTH | TOOK | ERROR | +----------------+--------+------------+-------+ | 127.0.0.1:2379 | true | 3.736825ms | | +----------------+--------+------------+-------+
登錄其中一個節點,進入容器,寫一條數據
zai
[root@liubei-01 etcd3]# docker exec -it 788 bash I have no name!@788dd01aaa79:/opt/bitnami/etcd$ etcd etcd etcdctl I have no name!@788dd01aaa79:/opt/bitnami/etcd$ etcdctl put name "liubei" OK
登錄另一個節點,進入容器,讀取數據
[root@liubei-02 ~]# docker exec -it 555 bash I have no name!@555187fb758c:/opt/bitnami/etcd$ etcdctl get name name liubei
讀到這里,這篇“怎么使用docker compose搭建etcd集群”文章已經介紹完畢,想要掌握這篇文章的知識點還需要大家自己動手實踐使用過才能領會,如果想了解更多相關內容的文章,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。