-
Notifications
You must be signed in to change notification settings - Fork 5
/
distribute_deploy_openstack.sh
409 lines (351 loc) · 15.1 KB
/
distribute_deploy_openstack.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
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
#!/bin/bash
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License
#Wirte by keanlee on May 19th
#------------------------------This script can help you depoly a lots of controller node and compute node
ESC=$(printf "\e")
GREEN="$ESC[0;32m"
NO_COLOR="$ESC[0;0m"
RED="$ESC[0;31m"
MAGENTA="$ESC[0;35m"
YELLOW="$ESC[0;33m"
BLUE="$ESC[0;34m"
WHITE="$ESC[0;37m"
#PURPLE="$ESC[0;35m"
CYAN="$ESC[0;36m"
option=(
Help
Edit-env-variable
Config-repository
SSH-key-nodes
Check-nodes-system-info
Deploy-all
Deploy-controller-node
Deploy-compute-node
Deploy-block-node
Deploy-network-node
Deploy-galera-cluster
Exit
)
source ./deploy-openstack/bin/VARIABLE
debug(){
if [[ $1 -ne 0 ]]; then
echo $RED $2 $NO_COLOR
exit 1
fi
}
function help(){
which pv 1>/dev/null 2>&1 || rpm -ivh ./deploy-openstack/lib/pv* 1>/dev/null 2>&1
debug "$?" "install pv failed "
echo -e $CYAN $(cat ./deploy-openstack/README.txt) $NO_COLOR | pv -qL 30
cat 1>&2 <<__EOF__
$MAGENTA==================================================================================
--------Usage as below ---------
${MAGENTA}1. SSH-key-nodes
$BLUE#Generating a new SSH key and adding it to the target hosts $NO_COLOR
${MAGENTA}2. Check-nodes-system-info
$BLUE#To check all node system info CPU/Mem/NIC/Disk $NO_COLOR
${MAGENTA}3. Deploy-controller-node
$BLUE#To deploy controller/controller-as-network node$NO_COLOR
${MAGENTA}4. Deploy-compute-node
$BLUE#To deploy compute/compute-as-network/compute-as-block node$NO_COLOR
${MAGENTA}5. Deploy-block-node
$BLUE#To deploy block node (Single with No HA)$NO_COLOR
${MAGENTA}6. Deploy-network-node
$BLUE#To deploy network node (Single with No HA) $NO_COLOR
${MAGENTA}7. Deploy-galera-cluster
$BLUE#To deploy galera cluster(Separate with the controller) $NO_COLOR
${MAGENTA}8. Deploy-all
$BLUE#To deploy controller node,network node,compute node,block node$NO_COLOR${MAGENTA}
==================================================================================
$NO_COLOR
__EOF__
}
function ssh_key(){
#make sure that all node can reachable from deploy host
for ips in ${CONTROLLER_IP[*]};do
ping -c 1 ${ips} 1>/dev/null 2>&1
debug "$?" "The ${YELLOW}$ips${RED} which belongs to CONTROLLER_IP is unreachable from Deploy Host"
done
for ips in ${COMPUTE_NODE_IP[*]};do
ping -c 1 ${ips} 1>/dev/null 2>&1
debug "$?" "The ${YELLOW}$ips${RED} which belongs to COMPUTE_NODE_IP is unreachable from Deploy Host"
done
for ips in ${NETWORK_NODE_IP[*]};do
ping -c 1 ${ips} 1>/dev/null 2>&1
debug "$?" "The ${YELLOW}$ips${RED} which belongs to NETWORK_NODE_IP is unreachable from Deploy Host"
done
for ips in ${BLOCK_NODE_IP[*]};do
ping -c 1 ${ips} 1>/dev/null 2>&1
debug "$?" "The ${YELLOW}$ips${RED} which belongs to BLOCK_NODE_IP is unreachable from Deploy Host"
done
#do ssh-key to nodes
if [[ -e ~/.ssh/id_rsa.pub ]];then
rm -rf ~/.ssh/id_rsa*
fi
echo $BLUE Generating public/private rsa key pair $NO_COLOR
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa 1>/dev/null
#-N "" tells it to use an empty passphrase (the same as two of the enters in an interactive script)
#-f my.key tells it to store the key into my.key (change as you see fit).
which sshpass 1>/dev/null 2>&1 || rpm -ivh ./deploy-openstack/lib/sshpass* 1>/dev/null 2>&1
echo -n $BLUE Please type the correct password for server: $NO_COLOR
read Password
if [[ -e ~/.ssh/known_hosts ]];then
continue
else
touch ~/.ssh/known_hosts
fi
if [[ ${#CONTROLLER_IP[*]} -ge 1 ]];then
echo $BLUE copy public key to controller hosts: $NO_COLOR
for ips in ${CONTROLLER_IP[*]};do
if [[ $(cat ~/.ssh/known_hosts | grep $ips | wc -l) -ge 2 ]];then
sed -i "/${ips}/d" ~/.ssh/known_hosts
ssh-keyscan $ips >> ~/.ssh/known_hosts
else
ssh-keyscan $ips >> ~/.ssh/known_hosts
fi
done
for ips in ${CONTROLLER_IP[*]};
do sshpass -p $Password ssh-copy-id -i ~/.ssh/id_rsa.pub $ips;
done
fi
if [[ ${#COMPUTE_NODE_IP[*]} -ge 1 ]];then
echo $BLUE copy public key to compute hosts: $NO_COLOR
for ips in ${COMPUTE_NODE_IP[*]};do
if [[ $(cat ~/.ssh/known_hosts | grep $ips | wc -l) -ge 2 ]];then
sed -i "/${ips}/d" ~/.ssh/known_hosts
ssh-keyscan $ips >> ~/.ssh/known_hosts
else
ssh-keyscan $ips >> ~/.ssh/known_hosts
fi
done
for ips in ${COMPUTE_NODE_IP[*]};
do sshpass -p $Password ssh-copy-id -i ~/.ssh/id_rsa.pub $ips;
done
fi
if [[ ${#NETWORK_NODE_IP[*]} -ge 1 ]];then
echo $BLUE copy public key to network hosts: $NO_COLOR
for ips in ${NETWORK_NODE_IP[*]};do
if [[ $(cat ~/.ssh/known_hosts | grep $ips | wc -l) -ge 2 ]];then
sed -i "/${ips}/d" ~/.ssh/known_hosts
ssh-keyscan $ips >> ~/.ssh/known_hosts
else
ssh-keyscan $ips >> ~/.ssh/known_hosts
fi
done
for ips in ${NETWORK_NODE_IP[*]};
do sshpass -p $Password ssh-copy-id -i ~/.ssh/id_rsa.pub $ips;
done
fi
if [[ ${#BLOCK_NODE_IP[*]} -ge 1 ]];then
echo $BLUE copy public key to storage hosts: $NO_COLOR
for ips in ${BLOCK_NODE_IP[*]};do
if [[ $(cat ~/.ssh/known_hosts | grep $ips | wc -l) -ge 2 ]];then
sed -i "/${ips}/d" ~/.ssh/known_hosts
ssh-keyscan $ips >> ~/.ssh/known_hosts
else
ssh-keyscan $ips >> ~/.ssh/known_hosts
fi
done
for ips in ${BLOCK_NODE_IP[*]};
do sshpass -p $Password ssh-copy-id -i ~/.ssh/id_rsa.pub $ips;
done
fi
}
#----------------------------------controller node deploy ---------------------
function controller(){
#deploy controller node and galera node
if [[ $# -eq 0 ]];then
local SCRIPT=install.sh
local VALUE=controller
elif [[ $1 = "controller-as-network-node" ]];then
local SCRIPT=install.sh
local VALUE=controller-as-network-node
elif [[ $1 = "galera" ]];then
local SCRIPT=bin/ha_proxy.sh galera
local VALUE=galera
else
debug "1" "function cannot support your parameter "
fi
for ips in ${CONTROLLER_IP[*]}; do scp -r deploy-openstack/ \
$ips:/home/; \
debug "$?" "Failed scp deploy script to $ips host" ; done 1>/dev/null 2>&1
for ips in ${CONTROLLER_IP[*]}; do ssh -n $ips /bin/bash /home/deploy-openstack/${SCRIPT} \
${VALUE} | tee ./log/${VALUE}-$ips-$(date "+%Y-%m-%d--%H:%M")-debug.log ; \
debug "$?" "bash remote execute on remote host <$ips> error "; done
for ips in ${CONTROLLER_IP[*]}; do ssh -n $ips 'rm -rf /home/deploy-openstack/' ;done
}
#---------------------------------compute node deploy -----------------
function compute(){
#Deploy the compute node and block node
if [[ $# -eq 0 ]];then
local VALUE=compute
elif [[ $1 = "compute-as-network-node" ]];then
local VALUE=compute-as-network-node
elif [[ $1 = "block" ]];then
local VALUE=deploy-block-node
else
debug "1" "function cannot support your parameter "
fi
if [[ $1 = "block" ]];then
for ips in ${BLOCK_NODE_IP[*]}; do scp -r deploy-openstack/ $ips:/home/; \
debug "$?" "Failed scp deploy script to $ips host" ; done 1>/dev/null 2>&1
for ips in ${BLOCK_NODE_IP[*]}; do ssh -n root@$ips /bin/bash /home/deploy-openstack/install.sh \
${VALUE} | tee ./log/${VALUE}-$ips-$(date "+%Y-%m-%d--%H:%M")-debug.log ; \
debug "$?" "bash remote execute on remote host <$ips> error "; done
for ips in ${BLOCK_NODE_IP[*]}; do ssh -n root@$ips 'rm -rf /home/deploy-openstack/';done
else
for ips in ${COMPUTE_NODE_IP[*]}; do scp -r deploy-openstack/ $ips:/home/; \
debug "$?" "Failed scp deploy script to $ips host" ; done 1>/dev/null 2>&1
for ips in ${COMPUTE_NODE_IP[*]}; do ssh -n root@$ips /bin/bash /home/deploy-openstack/install.sh \
${VALUE} | tee ./log/${VALUE}-$ips-$(date "+%Y-%m-%d--%H:%M")-debug.log ; \
debug "$?" "bash remote execute on remote host <$ips> error "; done
for ips in ${COMPUTE_NODE_IP[*]}; do ssh -n root@$ips 'rm -rf /home/deploy-openstack/';done
fi
}
#----------------------------------network node deploy-----------------------
function network_node(){
#Only deploy the network node
for ips in ${NETWORK_NODE_IP[*]} ; do scp -r deploy-openstack/ $ips:/home/; \
debug "$?" "Failed scp deploy script to $ips host" ; done 1>/dev/null 2>&1
for ips in ${NETWORK_NODE_IP[*]}; do ssh -n root@$ips /bin/bash /home/deploy-openstack/install.sh \
network | tee ./log/network-node-$ips-$(date "+%Y-%m-%d--%H:%M")-debug.log;done
for ips in ${NETWORK_NODE_IP[*]}; do ssh -n root@$ips 'rm -rf /home/deploy-openstack/' ;done
}
#-----------------------------show target host system info-------------------------------------
function check_info(){
#check the target host system infor
#for controller nodes
if [[ ${#CONTROLLER_IP[*]} -ge 1 ]];then
#for controller nodes
echo $MAGENTA Check Controller/Galera Node System Info: $NO_COLOR
for ips in ${CONTROLLER_IP[*]}; do scp ./deploy-openstack/bin/system_info.sh root@$ips:/home/; \
debug "$?" "Failed scp deploy script to $ips host" ; done 1>/dev/null 2>&1
for ips in ${CONTROLLER_IP[*]}; do ssh -n root@$ips /bin/bash /home/system_info.sh; \
debug "$?" "bash remote execute on remote host <$ips> error "; done
for ips in ${CONTROLLER_IP[*]}; do ssh -n root@$ips 'rm -rf /home/system_info.sh';done
fi
if [[ ${#COMPUTE_NODE_IP[*]} -ge 1 ]];then
#for compute nodes
echo $MAGENTA Check Compute Node System Info: $NO_COLOR
for ips in ${COMPUTE_NODE_IP[*]}; do scp ./deploy-openstack/bin/system_info.sh root@$ips:/home/; \
debug "$?" "Failed scp deploy script to $ips host" ; done 1>/dev/null 2>&1
for ips in ${COMPUTE_NODE_IP[*]}; do ssh -n root@$ips /bin/bash /home/system_info.sh; \
debug "$?" "bash remote execute on remote host <$ips> error "; done
for ips in ${COMPUTE_NODE_IP[*]}; do ssh -n root@$ips 'rm -rf /home/system_info.sh';done
fi
if [[ ${#NETWORK_NODE_IP[*]} -ge 1 ]];then
#for network nodes
echo $MAGENTA Check Network Node System Info: $NO_COLOR
for ips in ${NETWORK_NODE_IP[*]}; do scp ./deploy-openstack/bin/system_info.sh root@$ips:/home/; \
debug "$?" "Failed scp deploy script to $ips host" ; done 1>/dev/null 2>&1
for ips in ${NETWORK_NODE_IP[*]}; do ssh -n root@$ips /bin/bash /home/system_info.sh; \
debug "$?" "bash remote execute on remote host <$ips> error "; done
for ips in ${NETWORK_NODE_IP[*]}; do ssh -n root@$ips 'rm -rf /home/system_info.sh';done
fi
if [[ ${#BLOCK_NODE_IP[*]} -ge 1 ]];then
#for block nodes
echo $MAGENTA Check Block Node System Info: $NO_COLOR
for ips in ${BLOCK_NODE_IP[*]}; do scp ./deploy-openstack/bin/system_info.sh root@$ips:/home/; \
debug "$?" "Failed scp deploy script to $ips host" ; done 1>/dev/null 2>&1
for ips in ${BLOCK_NODE_IP[*]}; do ssh -n root@$ips /bin/bash /home/system_info.sh; \
debug "$?" "bash remote execute on remote host <$ips> error "; done
for ips in ${BLOCK_NODE_IP[*]}; do ssh -n root@$ips 'rm -rf /home/system_info.sh';done
fi
}
cat 1>&2 <<__EOF__
$MAGENTA===============================================================================
Thanks you use this script to deploy openstack !
Author: Kean Lee
This script provide the below option:
===============================================================================
$NO_COLOR
__EOF__
PS3="$BLUE Please Select a Number To Execute: $NO_COLOR"
export PS3
select OPTION in ${option[*]};do
break
done
case $OPTION in
Deploy-controller-node)
if [[ ${#CONTROLLER_IP[*]} -eq 3 ]] && [[ ${#CONTROLLER_HOSTNAME[*]} -eq 3 ]];then
if [[ $(echo $CONTROLLER_VIP | awk -F "." '{print $1 $2 }') -eq $(echo ${CONTROLLER_IP[0]} | awk -F "." '{print $1 $2 }' ) ]];then
controller galera
controller
else
debug "1" "The ${YELLOW}CONTROLLER_VIP${RED} must be a network segment with controller's ip"
fi
else
if [[ ${#CONTROLLER_IP[*]} -eq 1 ]] && [[ ${NETWORK_NODE_IP[0]} = ${CONTROLLER_IP[0]} ]];then
controller controller-as-network-node
elif [[ ${#CONTROLLER_IP[*]} -eq 1 ]] && [[ ${NETWORK_NODE_IP[0]} != ${CONTROLLER_IP[0]} ]];then
controller
elif [[ ${#NETWORK_NODE_IP[*]} -gt 1 ]];then
debug "1" "The ${YELLOW}NETWORK_NODE_IP${RED} just support one right now (No HA right now)"
else
debug "1" "Deployer doesn't know how to deploy controller node,please check the variable "
fi
fi
;;
Edit-env-variable)
which vim 1>/dev/null 2>&1 || vi ./deploy-openstack/bin/VARIABLE
vim ./deploy-openstack/bin/VARIABLE 2>/dev/null
;;
Config-repository)
which vim 1>/dev/null 2>&1 || vi ./deploy-openstack/repos/*
vim ./deploy-openstack/repos/* 2>/dev/null
;;
Deploy-galera-cluster)
controller galera
;;
Deploy-compute-node)
if [[ ${#COMPUTE_NODE_IP[*]} -eq 1 ]] && [[ ${NETWORK_NODE_IP[0]} = ${COMPUTE_NODE_IP[0]} ]];then
compute compute-as-network-node
if [[ ${#BLOCK_NODE_IP[*]} -eq 1 ]] && [[ ${COMPUTE_NODE_IP[0]} = ${BLOCK_NODE_IP[0]} ]];then
compute block
fi
elif [[ ${NETWORK_NODE_IP[0]} != ${COMPUTE_NODE_IP[0]} ]] && [[ ${COMPUTE_NODE_IP[0]} = ${BLOCK_NODE_IP[0]} ]];then
compute
compute block
else
compute
fi
;;
Deploy-block-node)
compute block
;;
Deploy-network-node)
network_node
;;
Deploy-all)
controller
network_node
compute
;;
Check-nodes-system-info)
check_info
;;
SSH-key-nodes)
ssh_key
;;
Help)
help
;;
Exit)
echo $GREEN =================================== $NO_COLOR
echo $GREEN =========== GoodBye !!! =========== $NO_COLOR
echo $GREEN =================================== $NO_COLOR
;;
*)
echo $RED Your typed is Invalid Option, Try another one option that is listed above !!! $NO_COLOR
esac