docklet/tools/etcd-multi-nodes.sh

54 lines
1.6 KiB
Bash
Raw Normal View History

#!/bin/bash
# more details for https://coreos.com/etcd/docs/latest
which etcd &>/dev/null || { echo "etcd not installed, please install etcd first" && exit 1; }
if [ $# -eq 0 ] ; then
2017-05-15 15:26:25 +08:00
echo "Usage: `basename $0` index ip1 ip2 ip3"
echo " ip1 ip2 ip3 are the ip address of node etcd_1 etcd_2 etcd_3"
exit 1
fi
2017-05-15 15:26:25 +08:00
etcdindex=etcd_$1
shift
2016-09-26 15:49:49 +08:00
etcd_1=$1
index=1
while [ $# -gt 0 ] ; do
h="etcd_$index"
if [ $index -eq 1 ] ; then
CLUSTER="$h=http://$1:2380"
else
CLUSTER="$CLUSTER,$h=http://$1:2380"
fi
index=$(($index+1))
shift
done
# -initial-advertise-peer-urls : tell others what peer urls of me
# -listen-peer-urls : what peer urls of me
# -listen-client-urls : what client urls to listen
# -advertise-client-urls : tell others what client urls to listen of me
# -initial-cluster-state : new means join a new cluster; existing means join an existing cluster
# : new not means clear
2017-05-15 15:26:25 +08:00
depdir=${0%/*}
tempdir=/opt/docklet/local
[ ! -d $tempdir/log ] && mkdir -p $tempdir/log
[ ! -d $tempdir/run ] && mkdir -p $tempdir/run
etcd --name $etcdindex \
--initial-advertise-peer-urls http://$etcdindex:2380 \
--listen-peer-urls http://$etcdindex:2380 \
--listen-client-urls http://$etcdindex:2379 \
--advertise-client-urls http://$etcdindex:2379 \
--initial-cluster-token etcd-cluster \
--initial-cluster $CLUSTER \
--initial-cluster-state new
2017-05-15 15:26:25 +08:00
etcdpid=$!
echo "etcd start with pid: $etcdpid and log:$tempdir/log/etcd.log"
echo $etcdpid > $tempdir/run/etcd.pid