[root@ray-aliyun etcd-cluster]# ls docker-compose.yml [root@ray-aliyun etcd-cluster]# docker-compose up -d Creating network "etcd-cluster_etcd-net" with driver "bridge" Creating volume "etcd-cluster_etcd1_data" with local driver Creating volume "etcd-cluster_etcd2_data" with local driver Creating volume "etcd-cluster_etcd3_data" with local driver Creating etcd1 ... done Creating etcd2 ... done Creating etcd3 ... done
检查搭建状态
查看节点启动情况
1 2 3 4 5
[root@ray-aliyun etcd-cluster]# docker ps -f name=etcd CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1fb56aba5292 bitnami/etcd:3.3.27 "/opt/bitnami/script…" About an hour ago Up About an hour 0.0.0.0:20000->2379/tcp, :::20000->2379/tcp, 0.0.0.0:20001->2380/tcp, :::20001->2380/tcp etcd1 0c8086970946 bitnami/etcd:3.3.27 "/opt/bitnami/script…" About an hour ago Up About an hour 0.0.0.0:20002->2379/tcp, :::20002->2379/tcp, 0.0.0.0:20003->2380/tcp, :::20003->2380/tcp etcd2 cd942ecc6a9a bitnami/etcd:3.3.27 "/opt/bitnami/script…" About an hour ago Up About an hour 0.0.0.0:20004->2379/tcp, :::20004->2379/tcp, 0.0.0.0:20005->2380/tcp, :::20005->2380/tcp etcd3
查看挂载的数据卷
1 2 3 4 5
[root@ray-aliyun etcd-cluster]# docker volume ls DRIVER VOLUME NAME local etcd-cluster_etcd1_data local etcd-cluster_etcd2_data local etcd-cluster_etcd3_data
[root@ray-aliyun etcd-cluster]# docker exec -it etcd1 bash I have no name!@1fb56aba5292:/opt/bitnami/etcd$ etcdctl put name "i am ray" OK
从etcd2和etcd3读取该value
1 2 3 4 5 6 7 8 9 10
[root@ray-aliyun etcd-cluster]# docker exec -it etcd2 bash I have no name!@0c8086970946:/opt/bitnami/etcd$ etcdctl get name name i am ray I have no name!@0c8086970946:/opt/bitnami/etcd$ exit exit [root@ray-aliyun etcd-cluster]# docker exec -it etcd3 bash I have no name!@cd942ecc6a9a:/opt/bitnami/etcd$ etcdctl get name name i am ray