docklet/tools/etcd-multi-nodes.sh

56 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 16:16:15 +08:00
echo "Usage: `basename $0` index selfip 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
2017-05-15 16:16:15 +08:00
selfip=$1
shift
2016-09-26 15:49:49 +08:00
etcd_1=$1
index=1
while [ $# -gt 0 ] ; do
2017-12-11 15:12:55 +08:00
h="etcd_$index"
if [ $index -eq 1 ] ; then
CLUSTER="$h=http://$1:2380"
else
CLUSTER="$CLUSTER,$h=http://$1:2380"
2017-12-11 15:12:55 +08:00
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
2017-12-11 15:12:55 +08:00
# : 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 \
2017-05-15 16:16:15 +08:00
--initial-advertise-peer-urls http://$selfip:2380 \
--listen-peer-urls http://$selfip:2380 \
2017-12-11 15:12:55 +08:00
--listen-client-urls http://$selfip:2379,http://127.0.0.1:2379 \
2017-05-15 16:16:15 +08:00
--advertise-client-urls http://$selfip:2379 \
--initial-cluster-token etcd-cluster \
--initial-cluster $CLUSTER \
2017-12-11 15:12:55 +08:00
--initial-cluster-state new > $tempdir/log/etcd.log 2>&1 &
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