This repository has been archived by the owner on May 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launchETCDcluster
executable file
·65 lines (63 loc) · 3.65 KB
/
launchETCDcluster
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
export ETCDCTL_API=3
CLUSTER_NODES=3
CLUSTER_TAG=etcd-$1
CLUSTER_STATE=new
CPUS=2
MEM=2G
DISK=4G
export TOKEN=token-01
declare -a IP_ADDRESS
unset ENDPOINTS
#
clear
for ((CNT=1; CNT<=$CLUSTER_NODES; CNT+=1)); do
echo "*****************************************************************************************************************"
multipass launch lts --name $CLUSTER_TAG-$CNT --cpus $CPUS --mem $MEM --disk $DISK
IP_ADDRESS[$CNT]="$(multipass info ${CLUSTER_TAG}-${CNT} | grep "IPv4" | awk -F' ' '{print $2}')"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "sudo apt-get update -y -qq"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "sudo apt-get upgrade --assume-yes -qq"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "export ETCDCTL_API=3 && sudo apt-get install -y etcd -qq"
export ENDPOINTS=${ENDPOINTS}${IP_ADDRESS[$CNT]}":2379,"
done
#
export CLUSTER=$CLUSTER_TAG-1=http://${IP_ADDRESS[1]}:2380,$CLUSTER_TAG-2=http://${IP_ADDRESS[2]}:2380,$CLUSTER_TAG-3=http://${IP_ADDRESS[3]}:2380
export ENDPOINTS=${ENDPOINTS%?}
echo "*****************************************************************************************************************"
echo "initial Cluster: $CLUSTER"
echo "ENDPOINTS: $ENDPOINTS"
#
for ((CNT=1; CNT<=$CLUSTER_NODES; CNT+=1)); do
echo "*****************************************************************************************************************"
echo "Host: ${CLUSTER_TAG}-${CNT}"
echo "IP : ${IP_ADDRESS[$CNT]}"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "sudo mkdir ~/data.etcd"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "sudo chgrp etcd ~/data.etcd"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "sudo chmod 770 ~/data.etcd"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "sudo chmod 777 /etc/default/etcd"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "echo 'ETCD_NAME=${CLUSTER_TAG}-${CNT}' >> /etc/default/etcd"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "echo 'ETCD_DATA_DIR=/home/ubuntu/data.etcd' >> /etc/default/etcd"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "echo 'ETCD_INITIAL_CLUSTER_STATE=${CLUSTER_STATE}' >> /etc/default/etcd"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "echo 'ETCD_INITIAL_CLUSTER_TOKEN=${TOKEN}' >> /etc/default/etcd"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "echo 'ETCD_INITIAL_CLUSTER=${CLUSTER}' >> /etc/default/etcd"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "echo 'ETCD_INITIAL_ADVERTISE_PEER_URLS=http://${IP_ADDRESS[$CNT]}:2380' >> /etc/default/etcd"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "echo 'ETCD_ADVERTISE_CLIENT_URLS=http://${IP_ADDRESS[$CNT]}:2379' >> /etc/default/etcd"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "echo 'ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380' >> /etc/default/etcd"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "echo 'ETCD_LISTEN_CLIENT_URLS=http://${IP_ADDRESS[$CNT]}:2379' >> /etc/default/etcd"
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "sudo chmod 544 /etc/default/etcd"
sleep 1
multipass exec $CLUSTER_TAG-$CNT -- /bin/bash -c "sudo systemctl restart etcd"
done
#
echo "*****************************************************************************************************************"
echo Type:
echo "export ETCDCTL_API=3"
echo "export ENDPOINTS=${ENDPOINTS}"
echo "etcdctl --endpoints="\$"ENDPOINTS member list --write-out="\""table"\"" "
echo "export ETCDCTL_API=3" > setetcd
echo "export ENDPOINTS=${ENDPOINTS}" >> setetcd
echo "etcdctl --endpoints="\$"ENDPOINTS member list --write-out="\""table"\"" " >> setetcd
echo "or type:"
echo "source ./setetcd"
chmod 777 setetcd
echo "*****************************************************************************************************************"