This repository has been archived by the owner on Apr 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
/
install.sh
executable file
·358 lines (288 loc) · 11.3 KB
/
install.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
#!/bin/bash
# Copyright 2014 Intel Corporation, All Rights Reserved.
# 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.
#-------------------------------------------------------------------------------
# Usage
#-------------------------------------------------------------------------------
function usage() {
cat << EOF
Usage: install.sh
Auto deploy vsm:
The tool can help you to deploy the vsm envirement automatically.
Please run such as bash +x install.sh
Options:
--help | -h
Print usage information.
--manifest [manifest directory] | -m [manifest directory]
The directory to store the server.manifest and cluster.manifest.
--version [master] | -v [master]
The version of vsm dependences to download(Default=master).
--keyfile [key file] | -k [key file]
The key file required for ssh/scp connection at the environment where certificate based authentication is enabled.
--user | -u
The user will be used to connect remote nodes to deploy vsm
EOF
exit 0
}
MANIFEST_PATH=""
DEPENDENCE_BRANCH="master"
USER=`whoami`
SSH='ssh'
SCP='scp'
while [ $# -gt 0 ]; do
case "$1" in
-h) usage ;;
--help) usage ;;
-m| --manifest) shift; MANIFEST_PATH=$1 ;;
-v| --version) shift; DEPENDENCE_BRANCH=$1 ;;
-k| --key) shift; keyfile=$1; export SSH='ssh -i $keyfile'; export SCP='scp -i $keyfile' ;;
-u| --user) shift; USER=$1 ;;
*) shift ;;
esac
shift
done
set -e
set -o xtrace
echo "Before auto deploy the vsm, please be sure that you have set the manifest
such as manifest/192.168.100.100/server.manifest. And you have changed the file, too."
sleep 5
TOPDIR=$(cd $(dirname "$0") && pwd)
TEMP=`mktemp`; rm -rfv $TEMP >/dev/null; mkdir -p $TEMP;
HOSTNAME=`hostname`
#HOSTIP=`hostname -I|sed s/[[:space:]]//g`
HOSTIP=`hostname -I`
source $TOPDIR/installrc
is_controller=0
for ip in $HOSTIP; do
if [ $ip == $CONTROLLER_ADDRESS ]; then
is_controller=1
fi
done
if [[ $HOSTNAME == $CONTROLLER_ADDRESS ]]; then
is_controller=1
fi
if [ $is_controller -eq 0 ]; then
echo "[Info]: You run the tool in a third server."
else
echo "[Info]: You run the tool in the controller server."
fi
#-------------------------------------------------------------------------------
# checking packages
#-------------------------------------------------------------------------------
echo "+++++++++++++++start checking packages+++++++++++++++"
if [ ! -d vsmrepo ]; then
echo "You should have the vsmrepo folder, please check and try again"
exit 1
fi
cd vsmrepo
is_python_vsmclient=`ls|grep python-vsmclient*.rpm|wc -l`
is_vsm=`ls|grep -v python-vsmclient|grep -v vsm-dashboard|grep -v vsm-deploy|grep vsm|wc -l`
is_vsm_dashboard=`ls|grep vsm-dashboard*.rpm|wc -l`
is_vsm_deploy=`ls|grep vsm-deploy*.rpm|wc -l`
if [ $is_python_vsmclient -gt 0 ] && [ $is_vsm -gt 0 ] && [ $is_vsm_dashboard -gt 0 ] && [ $is_vsm_deploy -gt 0 ]; then
echo "The vsm pachages have been already prepared"
else
echo "please check the vsm packages, then try again"
exit 1
fi
cd $TOPDIR
echo "+++++++++++++++finish checking packages+++++++++++++++"
#-------------------------------------------------------------------------------
# setting the iptables and selinux
#-------------------------------------------------------------------------------
echo "+++++++++++++++start setting the iptables and selinux+++++++++++++++"
function set_iptables_selinux() {
$SSH $USER@$1 "service iptables stop"
$SSH $USER@$1 "chkconfig iptables off"
$SSH $USER@$1 "sed -i \"s/SELINUX=enforcing/SELINUX=disabled/g\" /etc/selinux/config"
# $SSH $USER@$1 "setenforce 0"
}
if [ $is_controller -eq 0 ]; then
set_iptables_selinux $CONTROLLER_ADDRESS
else
service iptables stop
chkconfig iptables off
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
# setenforce 0
fi
for ip in $AGENT_ADDRESS_LIST; do
set_iptables_selinux $ip
done
echo "+++++++++++++++finish setting the iptables and selinux+++++++++++++++"
#-------------------------------------------------------------------------------
# downloading the dependences
#-------------------------------------------------------------------------------
if [ ! -d /opt/vsm-dep-repo ] && [ ! -d vsm-dep-repo ]; then
wget https://github.com/01org/vsm-dependencies/archive/"$DEPENDENCE_BRANCH".zip
unzip $DEPENDENCE_BRANCH
mv vsm-dependencies-$DEPENDENCE_BRANCH/repo vsm-dep-repo
is_createrepo=`rpm -qa|grep createrepo|wc -l`
if [[ $is_createrepo -gt 0 ]]; then
createrepo vsm-dep-repo
fi
rm -rf vsm-dependencies-$DEPENDENCE_BRANCH
rm -rf $DEPENDENCE_BRANCH
fi
if [ $is_controller -eq 0 ]; then
$SSH $USER@$CONTROLLER_ADDRESS "rm -rf /opt/vsm-dep-repo"
$SCP -r vsm-dep-repo $USER@$CONTROLLER_ADDRESS:/opt
else
if [ -d vsm-dep-repo ]; then
rm -rf /opt/vsm-dep-repo
cp -rf vsm-dep-repo /opt
fi
fi
#-------------------------------------------------------------------------------
# setting the repo
#-------------------------------------------------------------------------------
echo "+++++++++++++++start setting the repo+++++++++++++++"
is_httpd=`rpm -qa|grep httpd|grep -v httpd-tools|wc -l`
if [[ $is_httpd -gt 0 ]]; then
sed -i "s,#*Listen 80,Listen 80,g" /etc/httpd/conf/httpd.conf
service httpd restart
fi
rm -rf vsm.repo
cat <<"EOF" >vsm.repo
[vsm-dep-repo]
name=vsm-dep-repo
baseurl=file:///opt/vsm-dep-repo
gpgcheck=0
enabled=1
proxy=_none_
EOF
oldurl="file:///opt/vsm-dep-repo"
newurl="http://$CONTROLLER_ADDRESS/vsm-dep-repo"
if [ $is_controller -eq 0 ]; then
$SCP vsm.repo $USER@$CONTROLLER_ADDRESS:/etc/yum.repos.d
$SSH $USER@$CONTROLLER_ADDRESS "yum makecache; yum -y install httpd; service httpd restart; rm -rf /var/www/html/vsm-dep-repo; cp -rf /opt/vsm-dep-repo /var/www/html"
$SSH $USER@$CONTROLLER_ADDRESS "sed -i \"s,$oldurl,$newurl,g\" /etc/yum.repos.d/vsm.repo; yum makecache"
else
cp vsm.repo /etc/yum.repos.d
yum makecache; yum -y install httpd; service httpd restart; rm -rf /var/www/html/vsm-dep-repo; cp -rf /opt/vsm-dep-repo /var/www/html
sed -i "s,$oldurl,$newurl,g" /etc/yum.repos.d/vsm.repo
yum makecache
fi
sed -i "s,$oldurl,$newurl,g" vsm.repo
function set_repo() {
$SSH $USER@$1 "rm -rf /etc/yum.repos.d/vsm.repo"
$SCP vsm.repo $USER@$1:/etc/yum.repos.d
$SSH $USER@$1 "yum makecache"
}
for ip in $AGENT_ADDRESS_LIST; do
set_repo $ip
done
echo "+++++++++++++++finish setting the repo+++++++++++++++"
#-------------------------------------------------------------------------------
# install vsm rpm and dependences
#-------------------------------------------------------------------------------
echo "+++++++++++++++install vsm rpm and dependences+++++++++++++++"
function install_vsm_controller() {
$SSH $USER@$1 "mkdir -p /opt/vsm_install"
$SCP vsmrepo/python-vsmclient*.rpm vsmrepo/vsm*.rpm $USER@$1:/opt/vsm_install
$SSH $USER@$1 "cd /opt/vsm_install; yum -y localinstall python-vsmclient*.rpm vsm*.rpm"
$SSH $USER@$1 "preinstall"
$SSH $USER@$1 "cd /opt; rm -rf /opt/vsm_install"
}
function install_vsm_storage() {
$SSH $USER@$1 "mkdir -p /opt/vsm_install"
$SCP vsmrepo/vsm*.rpm $USER@$1:/opt/vsm_install
$SSH $USER@$1 "cd /opt/vsm_install; rm -rf vsm-dashboard*; yum -y localinstall vsm*.rpm"
$SSH $USER@$1 "preinstall"
$SSH $USER@$1 "cd /opt; rm -rf /opt/vsm_install"
}
if [ $is_controller -eq 0 ]; then
install_vsm_controller $CONTROLLER_ADDRESS
else
yum -y localinstall vsmrepo/python-vsmclient*.rpm vsmrepo/vsm*.rpm
preinstall
fi
for ip in $AGENT_ADDRESS_LIST; do
install_vsm_storage $ip
done
echo "+++++++++++++++finish install vsm rpm and dependences+++++++++++++++"
#-------------------------------------------------------------------------------
# setup vsm controller node
#-------------------------------------------------------------------------------
if [ -z $MANIFEST_PATH ]; then
MANIFEST_PATH="manifest"
fi
function setup_controller() {
$SSH $USER@$CONTROLLER_ADDRESS "rm -rf /etc/manifest/cluster_manifest"
$SCP $MANIFEST_PATH/$CONTROLLER_ADDRESS/cluster.manifest $USER@$CONTROLLER_ADDRESS:/etc/manifest
$SSH $USER@$CONTROLLER_ADDRESS "chown root:vsm /etc/manifest/cluster.manifest; chmod 755 /etc/manifest/cluster.manifest"
is_cluster_manifest_error=`$SSH $USER@$CONTROLLER_ADDRESS "cluster_manifest|grep error|wc -l"`
if [ $is_cluster_manifest_error -gt 0 ]; then
echo "please check the cluster.manifest, then try again"
exit 1
else
$SSH $USER@$CONTROLLER_ADDRESS "vsm-controller"
fi
}
if [ $is_controller -eq 0 ]; then
setup_controller
else
rm -rf /etc/manifest/cluster.manifest
cp $MANIFEST_PATH/$CONTROLLER_ADDRESS/cluster.manifest /etc/manifest
chown root:vsm /etc/manifest/cluster.manifest
chmod 755 /etc/manifest/cluster.manifest
if [ `cluster_manifest|grep error|wc -l` -gt 0 ]; then
echo "please check the cluster.manifest, then try again"
exit 1
else
vsm-controller
fi
fi
#-------------------------------------------------------------------------------
# setup vsm storage node
#-------------------------------------------------------------------------------
count_ip=0
for ip in $AGENT_ADDRESS_LIST; do
let count_ip=$count_ip+1
done
let count_ip=$count_ip+2+1
if [ `ls $MANIFEST_PATH|wc -l` != $count_ip ]; then
echo "please check the manifest folder"
exit 1
fi
success=""
failure=""
if [ $is_controller -eq 0 ]; then
token=`$SSH $USER@$CONTROLLER_ADDRESS "agent-token"`
else
token=`agent-token`
fi
function setup_storage() {
$SSH $USER@$1 "rm -rf /etc/manifest/server.manifest"
#sed -i "s/token-tenant/$token/g" $MANIFEST_PATH/$1/server.manifest
#old_str=`cat $MANIFEST_PATH/$1/server.manifest| grep ".*-.*" | grep -v by | grep -v "\["`
#sed -i "s/$old_str/$token/g" $MANIFEST_PATH/$1/server.manifest
sed -i "/^\[auth_key\]$/,/^\[.*\]/ s/^.*-.*$/$TOKEN/" $MANIFEST_PATH/$1/server.manifest
$SCP $MANIFEST_PATH/$1/server.manifest $USER@$1:/etc/manifest
$SSH $USER@$1 "chown root:vsm /etc/manifest/server.manifest; chmod 755 /etc/manifest/server.manifest"
is_server_manifest_error=`$SSH $USER@$1 "server_manifest" |grep ERROR|wc -l`
if [ $is_server_manifest_error -gt 0 ]; then
echo "[warning]: The server.manifest in $1 is wrong, so fail to setup in $1 storage node"
failure=$failure"$1 "
else
$SSH $USER@$1 "vsm-node"
success=$success"$1 "
fi
}
for ip in $AGENT_ADDRESS_LIST; do
setup_storage $ip
done
#-------------------------------------------------------------------------------
# finish auto deploy
#-------------------------------------------------------------------------------
echo "Successful storage node ip: $success"
echo "Failure storage node ip: $failure"
set +o xtrace