美文网首页
Docker 部署etcd集群

Docker 部署etcd集群

作者: john瀚 | 来源:发表于2020-09-28 15:24 被阅读0次

    image

    docker pull bitnami/etcd:3.4.7
    docker image tag bitnami/etcd:3.4.7 quay.io/coreos/etcd:3.4.7
    

    启动脚本

    REGISTRY=quay.io/coreos/etcd
    
    # For each machine
    ETCD_VERSION=3.4.7
    TOKEN=my-etcd-token
    CLUSTER_STATE=new
    NAME_1=etcd-node-0
    NAME_2=etcd-node-1
    NAME_3=etcd-node-2
    HOST_1= 192.168.202.128
    HOST_2= 192.168.202.129
    HOST_3= 192.168.202.130
    CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380
    DATA_DIR=/var/lib/etcd
    
    # For node 1
    THIS_NAME=${NAME_1}
    THIS_IP=${HOST_1}
    docker run \
      -p 2379:2379 \
      -p 2380:2380 \
      --volume=${DATA_DIR}:/etcd-data \
      --name etcd ${REGISTRY}:${ETCD_VERSION} \
      /usr/local/bin/etcd \
      --data-dir=/etcd-data --name ${THIS_NAME} \
      --initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://0.0.0.0:2380 \
      --advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://0.0.0.0:2379 \
      --initial-cluster ${CLUSTER} \
      --initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}
    
    # For node 2
    THIS_NAME=${NAME_2}
    THIS_IP=${HOST_2}
    docker run \
      -p 2379:2379 \
      -p 2380:2380 \
      --volume=${DATA_DIR}:/etcd-data \
      --name etcd ${REGISTRY}:${ETCD_VERSION} \
      /usr/local/bin/etcd \
      --data-dir=/etcd-data --name ${THIS_NAME} \
      --initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://0.0.0.0:2380 \
      --advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://0.0.0.0:2379 \
      --initial-cluster ${CLUSTER} \
      --initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}
    
    # For node 3
    THIS_NAME=${NAME_3}
    THIS_IP=${HOST_3}
    docker run \
      -p 2379:2379 \
      -p 2380:2380 \
      --volume=${DATA_DIR}:/etcd-data \
      --name etcd ${REGISTRY}:${ETCD_VERSION} \
      /usr/local/bin/etcd \
      --data-dir=/etcd-data --name ${THIS_NAME} \
      --initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://0.0.0.0:2380 \
      --advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://0.0.0.0:2379 \
      --initial-cluster ${CLUSTER} \
      --initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}
    

    上面的脚本是部署在三台机器上面,每台机器执行对应的脚本即可

    相关文章

      网友评论

          本文标题:Docker 部署etcd集群

          本文链接:https://www.haomeiwen.com/subject/poiduktx.html