forked from uksysadmin/OpenStackInstaller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OSinstall.sh
470 lines (402 loc) · 11.7 KB
/
OSinstall.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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
#!/bin/bash
# Author K. Jackson ([email protected]) 18 Feb 2011
#
# OSinstall.sh - Simple bash script installer for Openstack
# Copyright (C) 2011 Kevin Jackson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Script will either take arguments on the command line or install defaults
# This will form the basis of an automated script to install the relevant components of OpenStack
export LANG=C
# Check we're running as root
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root"
exit 1
fi
usage() {
cat << USAGE
Syntax
OSinstall.sh -T {type} -s { network size } -n {number of networks} -p {public interface} -P {private interface} -f {floating_range} -F {fixed_range} -V {VLAN start} -C {Controller Address} -A {admin} -v {qemu | kvm}
-T: Installation type: all (single node) | controller | compute
-s: Network size (IP address range on this network)
-n: Number of networks to create
-p: Public network interface
-f: Floating (Public) IP range
-P: Private network interface
-F: Fixed (Private) IP range e.g. 10.0.0.0/8
-V: VLAN Start
-C: Cloud Controller Address (if left blank, will work it out but is required for node installs)
-A: Admin username
-v: Virtualization type: qemu for software, kvm for kvm (hardware)
USAGE
exit 1
}
mask2cidr() {
# Credit http://www.linuxquestions.org/questions/programming-9/bash-cidr-calculator-646701/
nbits=0
if [ ! -z "$1" ]
then
IFS=.
for dec in $1 ; do
case $dec in
255) let nbits+=8;;
254) let nbits+=7;;
252) let nbits+=6;;
248) let nbits+=5;;
240) let nbits+=4;;
224) let nbits+=3;;
192) let nbits+=2;;
128) let nbits+=1;;
0);;
*) echo "Error: $dec is not recognised"; exit 1
esac
done
fi
echo "$nbits"
}
LOGFILE=/var/log/nova/nova-install.log
mkdir -p /var/log/nova
touch /var/log/nova/nova-install.log
# Defaults
DEFAULT_ADMIN=kevinj
DEFAULT_NETWORK_SIZE=64
DEFAULT_NUM_NETWORKS=1
DEFAULT_VMNET="10.0.0.0/8"
DEFAULT_MYSQL_PASS="nova"
DEFAULT_INTERFACE=eth0
DEFAULT_PRIVATE_INTERFACE=eth1
DEFAULT_VLAN_START=100
DEFAULT_VIRT="qemu"
DEFAULT_INSTALL="all"
# Process Command Line
while getopts T:N:s:n:p:f:P:F:V:C:A:v:hy opts
do
case $opts in
T)
INSTALL=$(echo "${OPTARG}" | tr [A-Z] [a-z])
case ${INSTALL} in
all|single|controller|compute|node)
;;
*)
usage
;;
esac
;;
s)
NETWORK_SIZE=${OPTARG}
;;
n)
NUM_NETWORKS=${OPTARG}
;;
p)
INTERFACE=${OPTARG}
;;
f)
FLOATING_RANGE=${OPTARG}
;;
P)
PRIVATE_INTERFACE=${OPTARG}
;;
F)
VMNET=${OPTARG}
;;
V)
VLAN_START=${OPTARG}
;;
C)
CC_ADDR=${OPTARG}
;;
A)
ADMIN=${OPTARG}
;;
v)
VIRT=${OPTARG}
;;
y)
AUTO=1
;;
h)
usage
;;
esac
done
# Check defaults / parameters passed to it
if [ -z ${VMNET} ]
then
VMNET=${DEFAULT_VMNET}
fi
if [ -z ${ADMIN} ]
then
ADMIN=${DEFAULT_ADMIN}
fi
if [ -z ${MYSQL_PASS} ]
then
MYSQL_PASS=${DEFAULT_MYSQL_PASS}
fi
if [ -z ${NETWORK_SIZE} ]
then
NETWORK_SIZE=${DEFAULT_NETWORK_SIZE}
fi
if [ -z ${NUM_NETWORKS} ]
then
NUM_NETWORKS=${DEFAULT_NUM_NETWORKS}
fi
if [ -z ${INTERFACE} ]
then
INTERFACE=${DEFAULT_INTERFACE}
fi
if [ -z ${PRIVATE_INTERFACE} ]
then
PRIVATE_INTERFACE=${DEFAULT_PRIVATE_INTERFACE}
fi
if [ -z ${VLAN_START} ]
then
VLAN_START=${DEFAULT_VLAN_START}
fi
if [ -z ${VIRT} ]
then
VIRT=${DEFAULT_VIRT}
fi
if [ -z ${INSTALL} ]
then
INSTALL=${DEFAULT_INSTALL}
fi
# Work out DEFAULT_FLOATING from public interface
_NETWORK=$(/sbin/route -n | grep ${INTERFACE} | egrep -v UG | awk '{print $1}')
_NETMASK=$(/sbin/route -n | grep ${INTERFACE} | egrep -v UG | awk '{print $3}')
_CIDR=$(mask2cidr $_NETMASK)
DEFAULT_FLOATING="$_NETWORK/$_CIDR"
if [ -z ${FLOATING_RANGE} ]
then
FLOATING_RANGE=${DEFAULT_FLOATING}
fi
if [ -z ${CC_ADDR} ]
then
# Check we're not a compute node install
case ${INSTALL} in
all|single|controller)
# DEFAULT_INTERFACE=$(/sbin/route -n | grep ^0\.0\.0\.0 | awk '{print $8}')
CC_ADDR=$(/sbin/ifconfig ${INTERFACE} | awk '/inet addr/ {split ($2,A,":"); print A[2]}')
if [ -z ${CC_ADDR} ]
then
echo "Error, no IP set for ${INTERFACE}, your Public API interface you've chosen."
exit 1
fi
;;
*)
echo
echo "You must specify the Cloud Controller Address (-C xxx.xxx.xxx.xxx) for a compute node install"
echo
exit 1
;;
esac
fi
# Verification (if -y isn't specified)
cat << CONFIG
OpenStack will be installed with these options:
Installation: ${INSTALL}
Admin user: ${ADMIN}
Networking: VLAN (${VLAN_START})
Private Interface = ${PRIVATE_INTERFACE}
>> Private Network: ${VMNET} ${NUM_NETWORKS} ${NETWORK_SIZE}
Public Interface = ${INTERFACE}
>> Public Floating network = ${FLOATING_RANGE}
Cloud Controller = ${CC_ADDR}
Virtualization Type: ${VIRT}
CONFIG
if [ -z ${AUTO} ]
then
echo "Are you sure you want to continue? [Y/n]"
read YESNO
if [ "${YESNO}" = "n" ]
then
echo "Aborting!"
exit 1
fi
fi
# Packages to install per install type
case ${INSTALL} in
all|single)
NOVA_PACKAGES="nova-api nova-objectstore nova-scheduler nova-network nova-compute glance"
EXTRA_PACKAGES="euca2ools unzip qemu"
MYSQL_INSTALL=1
RABBITMQ_INSTALL=1
;;
controller)
NOVA_PACKAGES="nova-api nova-objectstore nova-scheduler nova-network nova-compute glance"
EXTRA_PACKAGES="euca2ools unzip qemu"
MYSQL_INSTALL=1
RABBITMQ_INSTALL=1
;;
compute|node)
NOVA_PACKAGES="nova-compute"
EXTRA_PACKAGES="euca2ools unzip qemu"
;;
esac
# All installation types need to do the following
echo "Setting up repos and installing software"
apt-get install -y python-software-properties 2>&1 >> ${LOGFILE}
# For Diablo, this is part of Oneiric Ocelot, so check Ubuntu distribution and either add PPA or not
if [ $(lsb_release -r | awk '{print $2}') != "11.10" ]
then
echo "Not running Oneiric Ocelot 11.10, add PPA" >> ${LOGFILE}
add-apt-repository ppa:openstack-release/2011.3 2>&1 >> ${LOGFILE}
fi
apt-get update 2>&1 >> ${LOGFILE}
# Install based on type
if [ ! -z ${RABBITMQ_INSTALL} ]
then
apt-get install -y rabbitmq-server 2>&1 >> ${LOGFILE}
fi
apt-get install -y ${NOVA_PACKAGES} ${EXTRA_PACKAGES} 2>&1 >> ${LOGFILE}
# Configure the /etc/nova/nova.conf file
cat > /etc/nova/nova.conf << EOF
--daemonize=1
--dhcpbridge_flagfile=/etc/nova/nova.conf
--dhcpbridge=/usr/bin/nova-dhcpbridge
--logdir=/var/log/nova
--state_path=/var/lib/nova
--verbose
--libvirt_type=${VIRT}
--sql_connection=mysql://root:nova@${CC_ADDR}/nova
--s3_host=${CC_ADDR}
--rabbit_host=${CC_ADDR}
--ec2_host=${CC_ADDR}
--ec2_dmz_host=${CC_ADDR}
--ec2_url=http://${CC_ADDR}:8773/services/Cloud
--fixed_range=${VMNET}
--network_size=${NETWORK_SIZE}
--num_networks=${NUM_NETWORKS}
--FAKE_subdomain=ec2
--public_interface=${INTERFACE}
--state_path=/var/lib/nova
--lock_path=/var/lock/nova
--glance_host=${CC_ADDR}
--image_service=nova.image.glance.GlanceImageService
--glance_api_servers=${CC_ADDR}:9292
--vlan_start=${VLAN_START}
--vlan_interface=${PRIVATE_INTERFACE}
EOF
if [ ! -z ${MYSQL_INSTALL} ]
then
echo "Configuring MySQL for OpenStack"
# MySQL
MYSQL_PASS=nova
cat <<MYSQL_PRESEED | debconf-set-selections
mysql-server-5.1 mysql-server/root_password password $MYSQL_PASS
mysql-server-5.1 mysql-server/root_password_again password $MYSQL_PASS
mysql-server-5.1 mysql-server/start_on_boot boolean true
MYSQL_PRESEED
apt-get install -y mysql-server 2>&1 >> ${LOGFILE}
sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
service mysql restart
mysql -uroot -p$MYSQL_PASS -e 'CREATE DATABASE nova;'
mysql -uroot -p$MYSQL_PASS -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;"
mysql -uroot -p$MYSQL_PASS -e "SET PASSWORD FOR 'root'@'%' = PASSWORD('$MYSQL_PASS');"
fi
case ${INSTALL} in
"all"|"single")
# Configure the networking for this environment
echo "Configuring OpenStack VM Network: ${VMNET} ${NUM_NETWORKS} ${NETWORK_SIZE}"
nova-manage db sync
nova-manage network create vmnet --fixed_range_v4=${VMNET} --network_size=${NETWORK_SIZE} --bridge_interface=${INTERFACE}
nova-manage floating create --ip_range=${FLOATING_RANGE}
service libvirt-bin restart 2>&1 >> ${LOGFILE}
;;
"controller")
# Configure the networking for this environment
echo "Configuring OpenStack VM Network: ${VMNET} ${NUMBER_NETWORKS} ${NETWORK_SIZE}"
nova-manage db sync
nova-manage network create ${VMNET} ${NUM_NETWORKS} ${NETWORK_SIZE}
nova-manage floating create --ip_range=${FLOATING_RANGE}
service libvirt-bin restart 2>&1 >> ${LOGFILE}
;;
"compute"|"node")
nova-manage db sync
service libvirt-bin restart 2>&1 >> ${LOGFILE}
;;
esac
# Modify Authentication
if [ -f /etc/nova/api-paste.ini ]
then
sed -i "s/authenticate\ /ec2noauth /g" /etc/nova/api-paste.ini
fi
echo "Restarting service to finalize changes..."
for P in `ls /etc/init.d/nova*`
do
SERVICE_NAME=`basename ${P}`
service ${SERVICE_NAME} restart 2>&1 >> ${LOGFILE}
if [ "$?" != "0" ]; then
service ${SERVICE_NAME} start 2>&1 >> ${LOGFILE}
fi
done
if [[ -x /etc/init.d/glance-api ]]
then
for P in `ls /etc/init.d/glance*`
do
SERVICE_NAME=`basename ${P}`
service ${SERVICE_NAME} restart 2>&1 >> ${LOGFILE}
if [ "$?" != "0" ]; then
service ${SERVICE_NAME} start 2>&1 >> ${LOGFILE}
fi
done
fi
# Instructions
case ${INSTALL} in
"compute"|"node")
HOST=$(hostname -s)
MYIP=$(/sbin/ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}')
cat << INSTRUCTIONS
Ensure that the following is in DNS or in /etc/hosts
# Host Entry to ensure controller can find compute node via hostname
${MYIP} ${HOST}
INSTRUCTIONS
;;
*)
cat << INSTRUCTIONS
To set up your environment and a test VM execute the following:
[On this host running OpenStack]
sudo nova-manage user admin ${ADMIN}
sudo nova-manage role add ${ADMIN} cloudadmin
sudo nova-manage project create myproject ${ADMIN}
sudo nova-manage project zipfile myproject ${ADMIN}
[On your client computer after you have downloaded Euca2ools (apt-get install euca2ools)]
scp ${ADMIN}@`hostname`:nova.zip .
mkdir -p cloud/creds
cd cloud/creds
unzip ~${ADMIN}/nova.zip
. novarc
cd
Example test UEC image:
wget http://smoser.brickies.net/ubuntu/ttylinux-uec/ttylinux-uec-amd64-12.1_2.6.35-22_1.tar.gz
cloud-publish-tarball ttylinux-uec-amd64-12.1_2.6.35-22_1.tar.gz mybucket
Add a keypair to your environment so you can access the guests using keys:
euca-add-keypair openstack > cloud/creds/openstack.pem
chmod 0600 cloud/creds/*
Set the security group defaults (iptables):
euca-authorize default -P tcp -p 22 -s 0.0.0.0/0
euca-authorize default -P tcp -p 80 -s 0.0.0.0/0
euca-authorize default -P tcp -p 8080 -s 0.0.0.0/0
euca-authorize default -P icmp -t -1:-1
*****************************************************
To run, check, connect and terminate an instance
euca-run-instances \$emi -k openstack -t m1.tiny
euca-describe-instances
ssh -i cloud/creds/openstack.pem root@ipaddress
euca-terminate-instances instanceid
*****************************************************
INSTRUCTIONS
;;
esac