-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathinstall_dcos_onpremise.sh
More file actions
351 lines (269 loc) · 8.57 KB
/
Copy pathinstall_dcos_onpremise.sh
File metadata and controls
351 lines (269 loc) · 8.57 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#!/bin/bash
NETWORK_DEVICE=enp0s8
if [ "$#" -ne 3 ];then
echo "Usage: $0 <numMasters> <numAgents> <numPublicAgents>"
echo "Example: $0 1 3 1"
exit 99
fi
NUM_MASTERS=$1
NUM_AGENTS=$2
NUM_PUBLIC_AGENTS=$3
re='^[0-9]+$'
if ! [[ $NUM_MASTERS =~ $re ]] ; then
echo "Usage: $0 <numMasters> <numAgents> <numPublicAgents>"
echo "numMasters must be a number"
exit 91
fi
if ! [[ $NUM_AGENTS =~ $re ]] ; then
echo "Usage: $0 <numMasters> <numAgents> <numPublicAgents>"
echo "numAgents must be a number"
exit 92
fi
if ! [[ $NUM_PUBLIC_AGENTS =~ $re ]] ; then
echo "Usage: $0 <numMasters> <numAgents> <numPublicAgents>"
echo "numPublicAgents must be a number"
exit 93
fi
# If installer fails and you need to rerun.
# In some cases you can just try again.
# If that doesn't work
# Delete everything from root's home except the PKI private key and the this script using the rm command.
# Stop docker instances Run "docker ps" if nginx is running then run "docker stop <id>" and then "docker rm <id>"
# Now run the install script again.
if [ $NUM_MASTERS -eq 0 ]; then
echo "reset"
rm -f *.log
rm -f docker.repo
rm -f overlay.conf
rm -f override.conf
rm -f install.sh
rm -rf genconf
rm -f dcos-genconf*.tar
rm -f dcos_generate*.sh
CONTAINER=$(docker ps | grep nginx | cut -d ' ' -f 1)
docker stop $CONTAINER
docker rm $CONTAINER
echo "You might see an error message about docker; that's ok."
exit 0
fi
# https://dcos.io/releases/
DCOS_URL=https://downloads.dcos.io/dcos/stable/dcos_generate_config.sh
PS3='Which version of DCOS do you want to install: '
options=("Latest Community Edition" "Version 1.9.1" "Version 1.9.0" "Custom")
select opt in "${options[@]}"
do
case $opt in
"Latest Community Edition")
DCOS_URL=https://downloads.dcos.io/dcos/stable/dcos_generate_config.sh
break
;;
"Version 1.9.1")
DCOS_URL=https://downloads.dcos.io/dcos/stable/1.9.1/dcos_generate_config.sh
break
;;
"Version 1.9.0")
DCOS_URL=https://downloads.dcos.io/dcos/stable/commit/0ce03387884523f02624d3fb56c7fbe2e06e181b/dcos_generate_config.sh
break
;;
"Custom")
echo -n "Enter the URL to DCOS installer: "
read DCOS_URL
break
;;
*) echo invalid option;;
esac
done
# OS Username and Password
USERNAME="centos"
echo -n "Enter OS Username (${USERNAME}): "
read USER
if [ ! -z "${USER}" ]; then
USERNAME=${USER}
fi
PKIFILE="centos.pem"
echo -n "Enter PKI Filename (${PKIFILE}): "
read PKIF
if [ ! -z "${PKIF}" ]; then
PKIFILE=${PKIF}
fi
if [ ! -e ${PKIFILE} ]; then
echo "This PKI file does not exist: " + ${PKIFILE}
exit 3
fi
echo
echo "Install Details"
echo "DCOS_URL: " ${DCOS_URL}
echo "OS Username: " ${USERNAME}
echo "PKI Filename: " ${PKIFILE}
echo "Number of Masters: " ${NUM_MASTERS}
echo "Number of Agents: " ${NUM_AGENTS}
echo "Number of Public Agents:" ${NUM_PUBLIC_AGENTS}
echo
echo "Press Enter to Continue or Ctrl-C to abort"
read OK
# For Community Edition ADMIN_PASSWORD to "" to disable security; Set ADMIN_PASSWORD for OAUTH
ADMIN_PASSWORD=""
# See if this is AWS
boot_log="boot.log"
# Start Time
echo "Start Boot Setup"
echo "Boot Setup should take about 5 minutes. If it takes longer than 10 minutes then use Ctrl-C to exit this Script and review the log files (e.g. boot.log)"
st=$(date +%s)
# Create docker.repo
docker_repo="[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/\$releasever/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg"
echo "$docker_repo" > docker.repo
# Create overlay.conf
overlay="overlay"
echo "$overlay" > overlay.conf
# Create override.conf
override="[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --storage-driver=overlay"
echo "$override" > override.conf
# Copy files
cp overlay.conf /etc/modules-load.d/
cp docker.repo /etc/yum.repos.d/
mkdir /etc/systemd/system/docker.service.d
cp override.conf /etc/systemd/system/docker.service.d/
yum install -y docker-engine > $boot_log 2>&1
systemctl start docker >> $boot_log 2>&1
systemctl enable docker >> $boot_log 2>&1
systemctl daemon-reload >> $boot_log 2>&1
setenforce permissive >> $boot_log 2>&1
if [[ ! -e genconf ]]; then
mkdir genconf
fi
# Create ip-detect
ip_detect="#!/usr/bin/env bash
set -o nounset -o errexit
export PATH=/usr/sbin:/usr/bin:$PATH
echo \$(ip addr show ${NETWORK_DEVICE} | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1)"
echo "$ip_detect" > genconf/ip-detect
bootip=$(bash ./genconf/ip-detect)
os_config="curl -O $bootip/overlay.conf
curl -O $bootip/override.conf
curl -O $bootip/docker.repo
yum -y install ipset
yum -y install unzip
groupadd nogroup
cp /tmp/dcos/overlay.conf /etc/modules-load.d/
cp /tmp/dcos/docker.repo /etc/yum.repos.d/
mkdir /etc/systemd/system/docker.service.d
cp /tmp/dcos/override.conf /etc/systemd/system/docker.service.d/
yum -y install docker-engine
systemctl start docker
systemctl enable docker
systemctl stop dnsmasq
systemctl disable dnsmasq
sed -i -e 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce permissive
sed -i '$ i vm.max_map_count=262144' /etc/sysctl.conf
sysctl -w vm.max_map_count=262144"
# Create install.bat
install="#!/bin/bash
mkdir /tmp/dcos
cd /tmp/dcos
$os_config
curl -O $bootip/dcos_install.sh
bash dcos_install.sh \$1"
echo "$install" > install.sh
curl -O --silent $DCOS_URL >> $boot_log 2>&1
dcos_cmd=$(basename $DCOS_URL)
bash $dcos_cmd --help >> $boot_log 2>&1
search=$(cat /etc/resolv.conf | grep search | cut -d ' ' -f2)
ns=$(cat /etc/resolv.conf | grep nameserver | cut -d ' ' -f2)
bootline=$(grep boot /etc/hosts)
master_list=""
for (( i=1; i<=$NUM_MASTERS; i++))
do
server="m$i"
ip=$(getent hosts $server | cut -d ' ' -f1)
echo "$server $ip" >> $boot_log
master_list="$master_list""- "$ip$'\n'
done
echo "master_list"
echo "$master_list"
echo 'search: ' + $search >> $boot_log
echo 'nameserver: ' + $ns >> $boot_log
# create the config.yaml
oauthval="'false'"
pwlines=""
if [ ! -z $ADMIN_PASSWORD ]; then
oauthval="'true'"
pw=$(bash $dcos_cmd --hash-password $ADMIN_PASSWORD)
pwlines="""superuser_password_hash: $pw
superuser_username: admin"""
fi
config_yaml="---
bootstrap_url: http://$bootip
cluster_name: 'dcos'
exhibitor_storage_backend: static
ip_detect_filename: /genconf/ip-detect
oauth_enabled: $oauthval
master_discovery: static
check_time: 'false'
dns_search: $search
master_list:
"$master_list"
resolvers:
- $ns
$pwlines"
echo "$config_yaml" > genconf/config.yaml
# Run dcos_cmd
bash $dcos_cmd >> $boot_log 2>&1
# Copy files to serve folder AWS doesn't need some of these
mv docker.repo genconf/serve/
mv override.conf genconf/serve/
mv overlay.conf genconf/serve/
mv install.sh genconf/serve/
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo "Move files to genconf/serve folder failed!. Check boot.log for more details"
exit 4
fi
docker run -d -p 80:80 -v $PWD/genconf/serve:/usr/share/nginx/html:ro nginx >> $boot_log 2>&1
echo "Boot Setup Complete"
boot_fin=$(date +%s)
et=$(expr $boot_fin - $st)
echo "Time Elapsed (Seconds): $et"
echo
echo "Installing DC/OS."
echo "This should take about 5 minutes or less. If it takes longer than 10 minutes then use Ctrl-C to exit this Script and review the log files (e.g. m1.log)"
DCOSTYPE=master
for (( i=1; i<=$NUM_MASTERS; i++))
do
SERVER="m$i"
ssh -t -t -o "StrictHostKeyChecking no" -i $PKIFILE $USERNAME@$SERVER "sudo curl -O $bootip/install.sh;sudo bash install.sh $DCOSTYPE" >$SERVER.log 2>$SERVER.log &
done
DCOSTYPE=slave
for (( i=1; i<=$NUM_AGENTS; i++))
do
SERVER="a$i"
ssh -t -t -o "StrictHostKeyChecking no" -i $PKIFILE $USERNAME@$SERVER "sudo curl -O $bootip/install.sh;sudo bash install.sh $DCOSTYPE" >$SERVER.log 2>$SERVER.log &
done
DCOSTYPE=slave_public
for (( i=1; i<=$NUM_PUBLIC_AGENTS; i++))
do
SERVER="p$i"
ssh -t -t -o "StrictHostKeyChecking no" -i $PKIFILE $USERNAME@$SERVER "sudo curl -O $bootip/install.sh;sudo bash install.sh $DCOSTYPE" >$SERVER.log 2>$SERVER.log &
done
# Watch Master; when port 80 becomes active then its ready
curl --output /dev/null --head --silent http://m1:80
until [ "$?" == "0" ]; do
printf '.'
sleep 5
curl --output /dev/null --head --silent http://m1:80
done
dcos_fin=$(date +%s)
et2=$(expr $dcos_fin - $boot_fin) # Number of seconds it too from boot finished until DCOS ready
et3=$(expr $et + $et2)
echo "Boot Server Installation (sec): $et"
echo "DCOS Installation (sec): $et2"
echo "Total Time (sec): $et3"
echo
echo "DCOS is Ready"