-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit-etcd
68 lines (52 loc) · 1.55 KB
/
init-etcd
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
#!/usr/bin/bash
if [ $# -ne 3 ]; then
echo 'HELP: '
echo './init-etcd ETCD_NAME HOST_IP CLUSTER_INFO'
exit 0;
fi
#ETCD_NAME=etcd4
ETCD_NAME=$1
#HOST_IP=10.12.1.104
HOST_IP=$2
#CLUSTER=etcd0=http://10.12.1.100:2380,etcd1=http://10.12.1.101:2380,etcd2=http://10.12.1.102:2380,etcd3=http://10.12.1.103:2380,etcd4=http://10.12.1.104:2380
CLUSTER=$3
TOKEN=etcd-cluster-1
#init etcd2 data folder
DATA_DIR=/var/lib/etcd2
sudo mkdir -p ${DATA_DIR}
sudo chown -Rh etcd:etcd ${DATA_DIR}
cat <<EOF > /tmp/cloud-init-etcd-example.yaml
==== CoreOS cloud init script START ====
coreos:
etcd2:
name: ${ETCD_NAME}
advertise-client-urls: http://${HOST_IP}:2379
listen-peer-urls: http://${HOST_IP}:2380
listen-client-urls: http://${HOST_IP}:2379,http://127.0.0.1:2379
initial-advertise-peer-urls: http://${HOST_IP}:2380
initial-cluster: ${CLUSTER}
data-dir: ${DATA_DIR}
units:
- name: etcd2.service
command: start
==== CoreOS cloud init script END ====
EOF
cat /tmp/cloud-init-etcd-example.yaml
function pause() {
prompt="$1"
echo -e -n "\033[1;36m$prompt"
echo -e -n '\033[0m'
read
clear
}
pause "Press enter to continue...\n"
sudo -u etcd /bin/etcd2 \
-name ${ETCD_NAME} \
-advertise-client-urls http://${HOST_IP}:2379 \
-listen-peer-urls http://${HOST_IP}:2380 \
-listen-client-urls http://${HOST_IP}:2379,http://127.0.0.1:2379 \
-initial-advertise-peer-urls http://${HOST_IP}:2380 \
-initial-cluster-token ${TOKEN} \
-initial-cluster ${CLUSTER} \
-initial-cluster-state new \
-data-dir ${DATA_DIR}