forked from derdanu/azure-openshift
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstore.sh
executable file
·182 lines (159 loc) · 5.49 KB
/
store.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
#!/bin/bash
RESOURCEGROUP=${1}
USERNAME=${2}
SSHPRIVATEDATA=${3}
SSHPUBLICDATA=${4}
SSHPUBLICDATA2=${5}
SSHPUBLICDATA3=${6}
export OSEUSERNAME=$2
ps -ef | grep store.sh > cmdline.out
mkdir -p /home/$USERNAME/.ssh
echo $SSHPUBLICDATA $SSHPUBLICDATA2 $SSHPUBLICDATA3 > /home/$USERNAME/.ssh/id_rsa.pub
echo $SSHPRIVATEDATA | base64 --d > /home/$USERNAME/.ssh/id_rsa
chown $USERNAME /home/$USERNAME/.ssh/id_rsa.pub
chmod 600 /home/$USERNAME/.ssh/id_rsa.pub
chown $USERNAME /home/$USERNAME/.ssh/id_rsa
chmod 600 /home/$USERNAME/.ssh/id_rsa
mkdir -p /root/.ssh
echo $SSHPRIVATEDATA | base64 --d > /root/.ssh/id_rsa
echo $SSHPUBLICDATA $SSHPUBLICDATA2 $SSHPUBLICDATA3 > /root/.ssh/id_rsa.pub
chown root /root/.ssh/id_rsa.pub
chmod 600 /root/.ssh/id_rsa.pub
chown root /root/.ssh/id_rsa
chmod 600 /root/.ssh/id_rsa
yum -y update
yum -y install targetcli
yum -y install lvm2
systemctl start target
systemctl enable target
systemctl restart target.service
firewall-cmd --permanent --add-port=3260/tcp
firewall-cmd --reload
touch /root/.updateok
pvcreate /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg /dev/sdh /dev/sdi /dev/sdj
parted --script -a optimal /dev/sdc mklabel gpt mkpart primary xfs 1M 100% set 1 lvm on
parted --script -a optimal /dev/sdd mklabel gpt mkpart primary xfs 1M 100% set 1 lvm on
parted --script -a optimal /dev/sde mklabel gpt mkpart primary xfs 1M 100% set 1 lvm on
parted --script -a optimal /dev/sdf mklabel gpt mkpart primary xfs 1M 100% set 1 lvm on
parted --script -a optimal /dev/sdg mklabel gpt mkpart primary xfs 1M 100% set 1 lvm on
parted --script -a optimal /dev/sdh mklabel gpt mkpart primary xfs 1M 100% set 1 lvm on
parted --script -a optimal /dev/sdi mklabel gpt mkpart primary xfs 1M 100% set 1 lvm on
parted --script -a optimal /dev/sdj mklabel gpt mkpart primary xfs 1M 100% set 1 lvm on
pvcreate /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1 /dev/sdg1 /dev/sdh1 /dev/sdi1 /dev/sdj1
vgcreate vg1 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1 /dev/sdg1 /dev/sdh1 /dev/sdi1 /dev/sdj1
cat << 'EOFZ' > /root/ose_pvcreate_lun
#!/bin/bash
# $1 = volumegroup
# $2 = size
# #3 = count
if [[ -z ${stripsize+x} ]]; then
stripsize=8
fi
if [ $# -eq 0 ]; then
echo "pvcreatelun volgroup size count"
echo " volgroup is the volgroup as created by vgcreate"
echo " size - example 1G"
echo " count - Optional - Number of luns to create"
echo " $OSEUSERNAME should be set to the Openshift User Name"
exit 0
fi
# Call ourselves recursively to do repeats
if [ $# -eq 3 ]; then
for ((i=0;i < $3;i++))
do
./ose_pvcreate_lun $1 $2
done
exit 0
fi
STOREIP=$(hostname --ip-address)
LUNFILE=~/.oseluncount.cnt
DEVFILE=~/.osedevcount.cnt
TAG=$0
if [ -e ${LUNFILE} ]; then
count=$(cat ${LUNFILE})
else
touch "$LUNFILE"
count=0
fi
if [ -e ${DEVFILE} ]; then
dcount=$(cat ${DEVFILE})
else
touch "$DEVFILE"
dcount=1
echo ${dcount} > ${DEVFILE}
fi
lunid=${count}
((count++))
echo ${count} > ${LUNFILE}
printf -v padcnt "%03d" $count
export padcnt
export volname="ose${dcount}n${padcnt}x$2"
lvcreate -L $2G -i$stripsize -I64 -n $volname $1 | logger --tag $TAG
mkfs.ext4 -q -F /dev/vg1/$volname 2>&1 | logger --tag $TAG
if [ ${count} -eq 1 ]; then
echo "Setup device"
targetcli /iscsi create iqn.2016-02.local.store${dcount}:t1 | logger --tag $TAG
targetcli /iscsi/iqn.2016-02.local.store${dcount}:t1/tpg1/acls create iqn.2016-02.local.azure.nodes | logger --tag $TAG
targetcli /iscsi/iqn.2016-02.local.store${dcount}:t1/tpg1/ set attribute authentication=0 | logger --tag $TAG
targetcli /iscsi/iqn.2016-02.local.store${dcount}:t1/tpg1/ set parameter DefaultTime2Retain=60 | logger --tag $TAG
targetcli /iscsi/iqn.2016-02.local.store${dcount}:t1/tpg1/ set parameter DefaultTime2Wait=12 | logger --tag $TAG
targetcli /iscsi/iqn.2016-02.local.store${dcount}:t1/tpg1/ set parameter MaxConnections=10000 | logger --tag $TAG
targetcli /iscsi/iqn.2016-02.local.store${dcount}:t1/tpg1/ set attribute prod_mode_write_protect=0 | logger --tag $TAG
targetcli saveconfig
fi
targetcli backstores/block/ create "$volname" /dev/vg1/"$volname" | logger --tag $TAG
targetcli /iscsi/iqn.2016-02.local.store${dcount}:t1/tpg1/luns create /backstores/block/"$volname" | logger --tag $TAG
targetcli saveconfig | logger --tag $TAG
cat <<EOF > $volname.yml
apiVersion: v1
kind: PersistentVolume
metadata:
name: iscsipv${dcount}x${padcnt}
spec:
capacity:
storage: ${2}Gi
accessModes:
- ReadWriteOnce
iscsi:
targetPortal: $STOREIP
iqn: iqn.2016-02.local.store${dcount}:t1
lun: ${lunid}
fsType: 'ext4'
readOnly: false
EOF
oc create -f $volname.yml
rm -f $volname.yml
if [ ${count} -eq 100 ]; then
((dcount++))
count=0
echo ${count} > ${LUNFILE}
echo ${dcount} > ${DEVFILE}
fi
EOFZ
firewall-cmd --permanent --add-port=3260/tcp
firewall-cmd --reload
chmod +x /root/ose_pvcreate_lun
cd ~
while true
do
STATUS=$(curl -k -s -o /dev/null -w '%{http_code}' https://master1:8443/api)
if [ $STATUS -eq 200 ]; then
echo "Got 200! All done!"
break
else
echo "."
fi
sleep 10
done
cd /root
mkdir .kube
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${USERNAME}@master1:~/.kube/config /tmp/kube-config
cp /tmp/kube-config /root/.kube/config
mkdir /home/${USERNAME}/.kube
cp /tmp/kube-config /home/${USERNAME}/.kube/config
chown --recursive ${USERNAME} /home/${USERNAME}/.kube
rm -f /tmp/kube-config
./ose_pvcreate_lun vg1 10 20
./ose_pvcreate_lun vg1 50 4
./ose_pvcreate_lun vg1 1 400
systemctl restart target.service