Last active
December 14, 2018 03:44
-
-
Save browny/502b2a72ce5bd8c276821815feaff869 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: | |
# sh etcd-cluster.sh <instance_name> | |
INSTANCE_NAME=$1 | |
REGISTRY=quay.io/coreos/etcd | |
# available from v3.2.5 | |
REGISTRY=gcr.io/etcd-development/etcd | |
# For each machine | |
ETCD_VERSION=latest | |
TOKEN=my-etcd-token | |
CLUSTER_STATE=new | |
NAME_1=etcd-node-0 | |
NAME_2=etcd-node-1 | |
NAME_3=etcd-node-2 | |
HOST_1=etcd0 | |
HOST_2=etcd1 | |
HOST_3=etcd2 | |
CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380 | |
DATA_DIR=/var/lib/etcd | |
if [ "$INSTANCE_NAME" = "$HOST_1" ]; then | |
THIS_NAME=${NAME_1} | |
fi | |
if [ "$INSTANCE_NAME" = "$HOST_2" ]; then | |
THIS_NAME=${NAME_2} | |
fi | |
if [ "$INSTANCE_NAME" = "$HOST_3" ]; then | |
THIS_NAME=${NAME_3} | |
fi | |
THIS_IP=${INSTANCE_NAME} | |
docker run -d \ | |
-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} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment