-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetupConsulClient.sh
88 lines (71 loc) · 2.42 KB
/
setupConsulClient.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
#!/usr/bin/env bash
echo "Inside setupConsulServer.sh"
export DEBIAN_FRONTEND="noninteractive"
export PATH="$PATH:/usr/local/bin"
echo "Installing dependencies ..."
apt-get -y install unzip curl
echo "Installing Enterprise Version"
cp /vagrant/ent/consul-enterprise_*.zip ./consul.zip
unzip consul.zip
chown root:root consul
chmod 0755 consul
mv consul /usr/local/bin
rm -f consul.zip
echo "Creating Consul service account ..."
useradd -r -d /etc/consul -s /bin/false consul
echo "Creating Consul directory structure ..."
mkdir -p /etc/consul/{config.d,pki}
chown -R root:consul /etc/consul
chmod -R 0750 /etc/consul
mkdir /var/{lib,log}/consul
chown consul:consul /var/{lib,log}/consul
chmod 0750 /var/{lib,log}/consul
echo "Creating Consul configuration file ..."
NETWORK_INTERFACE=$(ls -1 /sys/class/net | grep -v lo | sort -r | head -n 1)
IP_ADDRESS=$(ip address show $NETWORK_INTERFACE | awk '{print $2}' | egrep -o '([0-9]+\.){3}[0-9]+')
HOSTNAME=$(hostname -s)
echo "IP Address is ${IP_ADDRESS} Host Name is ${HOSTNAME}"
cat > /etc/consul/config.d/consul.hcl << EOF
server = false
datacenter = "dc1"
node_name = "${HOSTNAME}"
data_dir = "/var/lib/consul"
log_file = "/var/log/consul/consul.log"
log_level = "DEBUG"
enable_syslog = true
acl_enforce_version_8 = false
bind_addr = "${IP_ADDRESS}"
client_addr = "127.0.0.1"
retry_join = ["10.100.1.11", "10.100.1.12", "10.100.1.13"]
EOF
chown root:consul /etc/consul/config.d/*
chmod 0640 /etc/consul/config.d/*
# Systemd configuration
echo "Setting up Consul system service ..."
cat > /etc/systemd/system/consul.service << EOF
[Unit]
Description=Consul client agent
Requires=network-online.target
After=network-online.target
ConditionFileNotEmpty=/etc/consul/config.d/consul.hcl
[Service]
User=consul
Group=consul
PIDFile=/var/run/consul/consul.pid
PermissionsStartOnly=true
ExecStartPre=-/bin/mkdir -p /var/run/consul
ExecStartPre=/bin/chown -R consul:consul /var/run/consul
ExecStart=/usr/local/bin/consul agent -config-dir=/etc/consul/config.d -pid-file=/var/run/consul/consul.pid
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
KillSignal=SIGTERM
Restart=on-failure
RestartSec=42s
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF
echo "Starting Consul client service ..."
systemctl daemon-reload
systemctl enable consul
systemctl restart consul