Deploy etcd cluster using Docker image

Deploy etcd cluster using Docker image

 

refer to:

official reference

https://github.com/coreos/etcd/blob/master/Documentation/op-guide/container.md#docker

etcd use

http://blog.csdn.net/u010424605/article/details/44592533

docker network configuration

http://www.infoq.com/cn/articles/docker-network-and-pipework-open-source-explanation-practice/

 

etcd version, the latest version v3.1.0

Docker startup script

Start three containers, specifying the IP of each container

In this example, three containers are placed on the same physical machine for experimentation. In practical applications, they need to be deployed on different physical machines (you can use the --net=host flag to make the container use the host network).

Use the docker inspect command to view the gateway of docker0 on the physical machine, and then configure three ip addresses HOST_1~3

Use three container aliases etcd1~3

 

 

# For each machine

ETCD_VERSION=v3.1.0

TOKEN=my-etcd-token

CLUSTER_STATE=new

NAME_1=etcd-node-0

NAME_2=etcd-node-1

NAME_3=etcd-node-2

HOST_1=172.17.0.2

HOST_2=172.17.0.3

HOST_3=172.17.0.4

CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380

 

# For node 1

THIS_NAME=${NAME_1}

THIS_IP=${HOST_1}

docker run -d --name etcd1 quay.io/coreos/etcd:${ETCD_VERSION} \

    /usr/local/bin/etcd \

    --data-dir=data.etcd --name ${THIS_NAME} \

    --initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \

    --advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}: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 -d --name etcd2 quay.io/coreos/etcd:${ETCD_VERSION} \

    /usr/local/bin/etcd \

    --data-dir=data.etcd --name ${THIS_NAME} \

    --initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \

    --advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}: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 -d --name etcd3 quay.io/coreos/etcd:${ETCD_VERSION} \

    /usr/local/bin/etcd \

    --data-dir=data.etcd --name ${THIS_NAME} \

    --initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \

    --advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 \

    --initial-cluster ${CLUSTER} \

    --initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}

    

 

Access etcd interface through HTTP interface

 

View version

curl -L http://172.17.0.2:2379/version

* Set the value of a key

curl http://172.17.0.2:2379/v2/keys/message -XPUT -d value="Hello world"

* Get the value of a key

curl http://172.17.0.2:2379/v2/keys/message

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326716693&siteId=291194637