-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_consul.sh
102 lines (75 loc) · 2.53 KB
/
install_consul.sh
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/bash
# Terraform variables will be "injected" via interpolation and data source configuration in main template
# Used for setting up Consul Server inter-node encrpyted settings
CONSUL_ENCRYPT="${consul_encrpyt}"
CONSUL_DATACENTER="${consul_datacenter}"
CONSUL_VERSION="${consul_version}"
CONSUL_DOWNLOAD_PATH="/tmp/consul_"$CONSUL_VERSION"_linux_amd64.zip"
CONSUL_DOWNLOAD_URL="https://releases.hashicorp.com/consul/"$CONSUL_VERSION"/consul_"$CONSUL_VERSION"_linux_amd64.zip"
# Used for getting cluster IP addresses for Consul bootstrapping/join
AZURE_SCALE_SET_NAME="${scale_set_name}"
AZURE_SUBSCRIPTION_ID="${subscription_id}"
AZURE_TENENT_ID="${tenant_id}"
AZURE_CLIENT_ID="${client_id}"
AZURE_SECRET_ACCESS_KEY="${secret_access_key}"
apt update
apt install -y unzip jq
wget -P /tmp "$CONSUL_DOWNLOAD_URL"
unzip -d /tmp "$CONSUL_DOWNLOAD_PATH"
chown root:root /tmp/consul
mv /tmp/consul /usr/local/bin/
consul -autocomplete-install
complete -C /usr/local/bin/consul consul
useradd --system --home /etc/consul.d --shell /bin/false consul
mkdir --parents /opt/consul
chown --recursive consul:consul /opt/consul
touch /etc/systemd/system/consul.service
cat >/etc/systemd/system/consul.service <<EOF
[Unit]
Description="HashiCorp Consul - A service mesh solution"
Documentation=https://www.consul.io/
Requires=network-online.target
After=network-online.target
ConditionFileNotEmpty=/etc/consul.d/consul.hcl
[Service]
User=consul
Group=consul
ExecStart=/bin/bash /etc/consul.d/start-consul.sh
ExecReload=/usr/local/bin/consul reload
KillMode=process
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
mkdir --parents /etc/consul.d
chown --recursive consul:consul /etc/consul.d
touch /etc/consul.d/start-consul.sh
chmod 740 /etc/consul.d/start-consul.sh
cat >/etc/consul.d/start-consul.sh <<EOF
#!/usr/bin/env bash
export CONSUL_BIND_ADDR=$(ifconfig eth0 | grep "inet " | awk '{ print $2 }')
consul agent -config-dir=/etc/consul.d/ -bind=$CONSUL_BIND_ADDR
EOF
touch /etc/consul.d/consul.hcl
chmod 640 /etc/consul.d/consul.hcl
cat >/etc/consul.d/consul.hcl <<EOF
datacenter = "dc1"
data_dir = "/opt/consul"
encrypt = "$CONSUL_ENCRYPT"
retry_join = ["192.168.0.4", "192.168.0.5", "192.168.0.6"]
EOF
touch /etc/consul.d/server.hcl
chmod 640 /etc/consul.d/server.hcl
cat >/etc/consul.d/server.hcl <<EOF
server = true
bootstrap_expect = 3
ui = true
connect {
enabled = true
}
EOF
systemctl enable consul
systemctl start consul
systemctl status consul
# consul agent -retry-join 'provider=azure config=val config2="some other val" ...'