-
Notifications
You must be signed in to change notification settings - Fork 2
/
init-compute-node
executable file
·167 lines (141 loc) · 5.56 KB
/
init-compute-node
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
#!/bin/bash
#
# Copyright 2010 Jeremy Schneider
#
# This file is part of EC2-RAC-BUILDER.
#
# EC2-RAC-BUILDER 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.
#
# EC2-RAC-BUILDER 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 EC2-RAC-BUILDER. If not, see <http://www.gnu.org/licenses/>.
#
#
[ -n "$DEBUG" ] && set -x
[ -z "$2" ] && { echo "Usage: init-compute-node <instance-id> <network-id>" && exit 1; }
[ $2 -gt 0 ] || { echo "ERROR: network-id must be between 1 and 20" && exit 1; };
[ $2 -lt 21 ] || { echo "ERROR: network-id must be between 1 and 20" && exit 1; };
. $(dirname $0)/env
# wait for node to come online
echo "ec2 load instance" >&2
DOUT="$(ec2din)"
ADDR=$(echo "$DOUT"|awk '/running/{if($2=="'$1'"){print$4}}')
while [ -z "$ADDR" ]; do
[ -z "$(echo "$DOUT"|grep ^INSTANCE)" ] && echo "$DOUT" && echo "ERROR - can't find instance '$1'" && exit 1
DOUT="$(ec2din)"
ADDR=$(echo "$DOUT"|awk '/running/{if($2=="'$1'"){print$4}}')
done
echo "$DOUT"
CL=$(echo "$DOUT"|awk '/^TAG/{if(($3=="'$1'")&&($4=="Cluster")){print$5}}')
echo $ADDR >/tmp/amazon/cluster$CL-n$2.ip
# wait for storage and network nodes to come online
echo "wait strg/ntwrk" >&2
until [ `cat /tmp/amazon/cluster$CL-storage` -eq 1 ] && [ `cat /tmp/amazon/cluster$CL-network` -eq 1 ]; do sleep 5; done
# get parameters
IPUBLIC=$(echo "$DOUT"|awk '/^TAG/{if($5=="c'$CL'-switch-pub"){print$3}}')
IPRIVATE=$(echo "$DOUT"|awk '/^TAG/{if($5=="c'$CL'-switch-priv"){print$3}}')
ISTORAGE=$(echo "$DOUT"|awk '/^TAG/{if($5=="c'$CL'-storage"){print$3}}')
for I in $IPUBLIC; do
T=$(echo "$DOUT"|awk '/running/{if($2=="'$I'"){print$4}}')
[ -n "$T" ] && PUBLIC=$T
done
for I in $IPRIVATE; do
T=$(echo "$DOUT"|awk '/running/{if($2=="'$I'"){print$4}}')
[ -n "$T" ] && PRIVATE=$T
done
STORAGE=""
for I in $ISTORAGE; do
T=$(echo "$DOUT"|awk '/running/{if($2=="'$I'"){print$4}}')
[ -n "$T" ] && STORAGE="$STORAGE $T"
done
echo PUBLIC $PUBLIC
echo PRIVATE $PRIVATE
echo STORAGE $STORAGE
echo "boot O.S." >&2
until ssh $SSH_OPTS root@$ADDR date 2>&1; do sleep 5; done
echo "configure O.S." >&2
cat <<EOF >/tmp/amazon/$1.compute
#!/bin/bash
# storage
yum -y install iscsi-initiator-utils
echo InitiatorName=\$(/sbin/iscsi-iname) >/etc/iscsi/initiatorname.iscsi
cat <<_EOF2 >>/etc/iscsi/iscsid.conf
EOF
for A in $STORAGE; do echo "DiscoveryAddress = $A" >>/tmp/amazon/$1.compute; done
cat <<EOF >>/tmp/amazon/$1.compute
_EOF2
echo 'KERNEL=="sd*", BUS=="scsi", ENV{ID_VENDOR}=="IET", NAME="iscsi_%k", OWNER="oracle", GROUP="dba", MODE="660"' >/etc/udev/rules.d/55-openiscsi.rules
udevcontrol reload_rules
service iscsi start
EOF
for A in $STORAGE; do
echo "TARGET=\$(iscsiadm -m discovery -t st -p $A|awk '{print\$2}')" >>/tmp/amazon/$1.compute
echo "iscsiadm -m node -T \$TARGET --login" >>/tmp/amazon/$1.compute
done
cat <<EOF >>/tmp/amazon/$1.compute
# network
rpm -i /root/rpmforge-release-0.5.1-1.el5.rf.i386.rpm
yum -y install openvpn
cd \$HOME
wget --no-check-certificate https://vpncubed:rac@$PUBLIC:8000/credentials/cp$2.tar.gz
mv cp$2.tar.gz public.tar.gz
wget --no-check-certificate https://vpncubed:rac@$PRIVATE:8000/credentials/cp$2.tar.gz
mv cp$2.tar.gz private.tar.gz
cd /etc/openvpn/
tar xzvf \$HOME/public.tar.gz
mv ca.crt ca-public.crt
mv vpncubed.conf vpncubed-public.conf.orig
echo remote $PUBLIC 1194 >>vpncubed-public.conf.orig
sed '{s/^ca .*/ca ca-public.crt/;}' vpncubed-public.conf.orig >vpncubed-public.conf
tar xzvf \$HOME/private.tar.gz
mv ca.crt ca-private.crt
mv vpncubed.conf vpncubed-private.conf.orig
echo remote $PRIVATE 1194 >>vpncubed-private.conf.orig
sed '{s/^ca .*/ca ca-private.crt/;s/dev .*/dev tun1/;}' vpncubed-private.conf.orig >vpncubed-private.conf
service openvpn start
cp /etc/hosts /root/hosts.orig
cp /root/hosts /etc/hosts
echo search ec2.ardentperf.com >>/etc/resolv.conf
echo domain ec2.ardentperf.com >>/etc/resolv.conf
hostname n$2
cp /etc/sysconfig/network /etc/sysconfig/network.orig
sed 's/^HOSTNAME=.*/HOSTNAME=n$2.ec2.ardentperf.com/' /etc/sysconfig/network.orig >/etc/sysconfig/network
# other
telinit 3
yum -y install screen
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.orig
sed '{s/^PasswordAuthentication.*/PasswordAuthentication yes/;
s/^PermitRootlogin.*/PermitRootlogin yes/;}' /etc/ssh/sshd_config.orig >/etc/ssh/sshd_config
service sshd reload
passwd root <<_EOF2
ec2rac
ec2rac
_EOF2
passwd oracle <<_EOF2
ec2rac
ec2rac
_EOF2
cd /
tar xvf /root/oracle-ssh.tar
cat /root/.ssh/authorized_keys >>/home/oracle/.ssh/authorized_keys
mkfs.ext3 /dev/sda2
echo "/dev/sda2 /u01 ext3 defaults 0 0" >>/etc/fstab
mount /u01
/etc/init.d/iptables stop
chkconfig iptables off
mkdir /u01/app
chown oracle:oinstall /u01/app
EOF
scp $SSH_OPTS $(dirname $0)/rpmforge-release-0.5.1-1.el5.rf.i386.rpm root@$ADDR:/root/ 2>&1
scp $SSH_OPTS $(dirname $0)/oracle-ssh.tar root@$ADDR:/root/ 2>&1
scp $SSH_OPTS $(dirname $0)/hosts root@$ADDR:/root/ 2>&1
scp $SSH_OPTS /tmp/amazon/$1.compute root@$ADDR:/tmp/amazon-compute.sh 2>&1
ssh $SSH_OPTS root@$ADDR chmod +x /tmp/amazon-compute.sh 2>&1
ssh $SSH_OPTS root@$ADDR bash /tmp/amazon-compute.sh 2>&1