• docker搭建etcd集群环境


    其实关于集群网上说的方案已经很多了,尤其是官网,只是这里我个人只有一个虚拟机,在开发环境下建议用docker-compose来搭建etcd集群.

    1.拉取etcd镜像

    docker pull quay.io/coreos/etcd

    2.编辑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:
          - "12379: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:
          - "22379: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:
          - "32379:2379"
          - 2380
        networks:
          - byfn

    3.启动服务验证:

    docker-compose up
    #docker-compose down
    curl -L http://127.0.0.1:12379/v2/members #查看etcd1的数据
    curl -L http://127.0.0.1:22379/v2/members #查看etcd2的数据
    curl -L http://127.0.0.1:32379/v2/members #查看etcd3的数据
    #也可以用命令行工具etcdctl
    docker exec -t etcd1 etcdctl member list
    #我们往一个node上上传数据,在其他node上就能下载到
    curl -L http://127.0.0.1:12379/v2/keys/foo -XPUT -d value="Hello foo"
    curl -L http://127.0.0.1:12379/v2/keys/foo1/foo1 -XPUT -d value="Hello foo1"
    curl -L http://127.0.0.1:12379/v2/keys/foo2/foo2 -XPUT -d value="Hello foo2"
    curl -L http://127.0.0.1:12379/v2/keys/foo2/foo21/foo21 -XPUT -d value="Hello foo21"
    curl -L http://127.0.0.1:22379/v2/keys/foo
    curl -L http://127.0.0.1:22379/v2/keys/foo2
    curl -L http://127.0.0.1:22379/v2/keys/foo2?recursive=true

    参考:

    ETCD 与 服务发现

    Docker 搭建 etcd 集群 

    Etcd项目介绍

    etcd-io/etcd

  • 相关阅读:
    安卓app_sl3_18_19列表视图
    安卓app_sl3_17列表选择框Spinner
    安卓app_sl3_15复选框按钮示范
    eclipse如何新建安卓app项目程序
    安卓app_sl3_21日期拾取器,为时间拾取器设置监听器
    eclipse 安卓app开发环境搭建
    android从入门到精通
    安卓app_sl3_16图像视图线性布局
    安卓app_sl3_22计时器_显示当前时间_系统时间
    二叉树及其三种遍历
  • 原文地址:https://www.cnblogs.com/majiang/p/11414200.html
Copyright © 2020-2023  润新知