1. 下載ectd鏡像
docker pull quay.io/coreos/etcd
2. 編輯docker-compose.yaml文件
version: '3'
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:
- "23791:2379"
- "23801: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:
- "23792:2379"
- "23802: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:
- "23793:2379"
- "23803:2380"
networks:
- byfn
3. 啟動服務(wù)
docker-compose up
4. 查看集群狀態(tài)
$ docker ps
792cd737a147 quay.io/coreos/etcd "etcd -name etcd3 -a…" 14 hours ago Up 34 minutes 0.0.0.0:23793->2379/tcp, 0.0.0.0:23803->2380/tcp etcd3
fb3be391c3c3 quay.io/coreos/etcd "etcd -name etcd1 -a…" 14 hours ago Up 34 minutes 0.0.0.0:23791->2379/tcp, 0.0.0.0:23801->2380/tcp etcd1
1c4361e3983b quay.io/coreos/etcd "etcd -name etcd2 -a…" 14 hours ago Up 34 minutes 0.0.0.0:23792->2379/tcp, 0.0.0.0:23802->2380/tcp etcd2
5. 使用集群: 從一個節(jié)點(diǎn)添加數(shù)據(jù)搀暑,另一個節(jié)點(diǎn)獲取數(shù)據(jù)
curl http://127.0.0.1:23791/v2/keys/foo -XPUT -d value="hello foo"
curl http://127.0.0.1:23791/v2/keys/foo1/foo1 -XPUT -d value="hello foo1"
curl http://127.0.0.1:23792/v2/keys/foo
curl http://127.0.0.1:23792/v2/keys/foo1
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者