ドッキングウィンドウ-COMPOSEビルドetcdクラスタ環境を使用します
etcdは、次の構成管理機能を管理するためのクラスタ環境、マイクロサービスアーキテクチャです。
分散、信頼性がキーと値のストア 、分散システムの最も重要なデータのために。
この記事では、ドッキングウィンドウetcdクラスタ環境を構築する方法の基本的なステップです。
私たちは、ドッキングウィンドウ-構成クラスタ環境を構築するには、次のetcdを使用します。
クラスタは3つのノードで構成されていますetcd1、etcd2、etcd3
1.領事のドッキングウィンドウの画像をダウンロード
$ docker pull quay.io/coreos/etcd
2. [編集]ドッキングウィンドウ-compose.yamlファイル
$ cat docker-compose.yaml
version: '2'
networks:
byfn:
services:
etcd1:
image: quay.io/coreos/etcd
container_name: etcd1
command: etcd -name etcd1 -advertise-client-urls http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380" -initial-cluster-state new
ports:
- 2379
- 2380
networks:
- byfn
etcd2:
image: quay.io/coreos/etcd
container_name: etcd2
command: etcd -name etcd2 -advertise-client-urls http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380" -initial-cluster-state new
ports:
- 2379
- 2380
networks:
- byfn
etcd3:
image: quay.io/coreos/etcd
container_name: etcd3
command: etcd -name etcd3 -advertise-client-urls http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379 -listen-peer-urls http://0.0.0.0:2380 -initial-cluster-token etcd-cluster -initial-cluster "etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380" -initial-cluster-state new
ports:
- 2379
- 2380
networks:
- byfn
- サービスを開始
$ docker-compose up
- クラスタの状態を確認します
同じ3つの値から返さV2 /メンバーノードデータを検証します。
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
33785a959d95 quay.io/coreos/etcd "etcd -name etcd1 ..." 2 hours ago Up 2 hours 0.0.0.0:32791->2379/tcp, 0.0.0.0:32790->2380/tcp etcd1
106ba12b1c25 quay.io/coreos/etcd "etcd -name etcd2 ..." 2 hours ago Up 2 hours 0.0.0.0:32789->2379/tcp, 0.0.0.0:32788->2380/tcp etcd2
76cd127439a3 quay.io/coreos/etcd "etcd -name etcd3 ..." 2 hours ago Up 2 hours 0.0.0.0:32787->2379/tcp, 0.0.0.0:32786->2380/tcp etcd3
$ curl -L http://127.0.0.1:32787/v2/members
{"members":[{"id":"ade526d28b1f92f7","name":"etcd1","peerURLs":["http://etcd1:2380"],"clientURLs":["http://0.0.0.0:2379"]},{"id":"bd388e7810915853","name":"etcd3","peerURLs":["http://etcd3:2380"],"clientURLs":["http://0.0.0.0:2379"]},{"id":"d282ac2ce600c1ce","name":"etcd2","peerURLs":["http://etcd2:2380"],"clientURLs":["http://0.0.0.0:2379"]}]}
$ curl -L http://127.0.0.1:32789/v2/members
{"members":[{"id":"ade526d28b1f92f7","name":"etcd1","peerURLs":["http://etcd1:2380"],"clientURLs":["http://0.0.0.0:2379"]},{"id":"bd388e7810915853","name":"etcd3","peerURLs":["http://etcd3:2380"],"clientURLs":["http://0.0.0.0:2379"]},{"id":"d282ac2ce600c1ce","name":"etcd2","peerURLs":["http://etcd2:2380"],"clientURLs":["http://0.0.0.0:2379"]}]}
$ curl -L http://127.0.0.1:32791/v2/members
{"members":[{"id":"ade526d28b1f92f7","name":"etcd1","peerURLs":["http://etcd1:2380"],"clientURLs":["http://0.0.0.0:2379"]},{"id":"bd388e7810915853","name":"etcd3","peerURLs":["http://etcd3:2380"],"clientURLs":["http://0.0.0.0:2379"]},{"id":"d282ac2ce600c1ce","name":"etcd2","peerURLs":["http://etcd2:2380"],"clientURLs":["http://0.0.0.0:2379"]}]}
また、コマンドラインツールのetcdctlを使用することができます。
$ docker exec -t etcd1 etcdctl member list
ade526d28b1f92f7: name=etcd1 peerURLs=http://etcd1:2380 clientURLs=http://0.0.0.0:2379 isLeader=false
bd388e7810915853: name=etcd3 peerURLs=http://etcd3:2380 clientURLs=http://0.0.0.0:2379 isLeader=false
d282ac2ce600c1ce: name=etcd2 peerURLs=http://etcd2:2380 clientURLs=http://0.0.0.0:2379 isLeader=true
$ docker exec -t etcd3 etcdctl -C http://etcd1:2379,http://etcd2:2379,http://etcd3:2379 member list
ade526d28b1f92f7: name=etcd1 peerURLs=http://etcd1:2380 clientURLs=http://0.0.0.0:2379 isLeader=false
bd388e7810915853: name=etcd3 peerURLs=http://etcd3:2380 clientURLs=http://0.0.0.0:2379 isLeader=false
d282ac2ce600c1ce: name=etcd2 peerURLs=http://etcd2:2380 clientURLs=http://0.0.0.0:2379 isLeader=true
クラスタの4.
# 我们往一个node上上传数据,在其他node上就能下载到
curl -L http://127.0.0.1:32789/v2/keys/foo -XPUT -d value="Hello foo"
curl -L http://127.0.0.1:32789/v2/keys/foo1/foo1 -XPUT -d value="Hello foo1"
curl -L http://127.0.0.1:32789/v2/keys/foo2/foo2 -XPUT -d value="Hello foo2"
curl -L http://127.0.0.1:32789/v2/keys/foo2/foo21/foo21 -XPUT -d value="Hello foo21"
curl -L http://127.0.0.1:32787/v2/keys/foo
curl -L http://127.0.0.1:32787/v2/keys/foo2
curl -L http://127.0.0.1:32787/v2/keys/foo2?recursive=true