-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare_jump.sh
executable file
·198 lines (173 loc) · 5.88 KB
/
prepare_jump.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
#!/bin/bash -e
set -o pipefail
# Run on jump server
# Undercloud VM config
undercloud_name=rhel7
undercloud_suffix=local
root_password=c0ntrail123
stack_password=c0ntrail123
vcpus=8
vram=32000
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
# install packages
yum -y install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install openvswitch \
httpd screen yum-utils createrepo
# tune host
systemctl enable httpd
systemctl start httpd
systemctl enable libvirtd
systemctl start libvirtd
systemctl enable openvswitch
systemctl start openvswitch
systemctl stop firewalld
systemctl disable firewalld
systemctl stop NetworkManager
systemctl disable NetworkManager
tuned-adm profile virtual-host
# Enable mirror repos
cat << 'EOF' > update_mirror_repo
#!/bin/bash -x
repos="rhel-7-server-rpms
rhel-7-server-extras-rpms
rhel-7-server-optional-rpms
rhel-server-rhscl-7-rpms
rhel-7-server-rh-common-rpms
rhel-ha-for-rhel-7-server-rpms
rhel-7-server-openstack-13-devtools-rpms
rhel-7-server-openstack-13-rpms"
function sync_repo() {
local r=$1
reposync --gpgcheck -l --repoid=$r --download_path=/var/www/html --downloadcomps --download-metadata
cd /var/www/html/$r
createrepo --workers=2 -v /var/www/html/${r}/ -g comps.xml
}
for r in $repos; do
sync_repo $r
done
EOF
chmod +x update_mirror_repo
mv update_mirror_repo /etc/cron.weekly/
# create briges
virsh iface-bridge eno1 br-mgmt
virsh iface-bridge ens2f3 br-data
ovs-vsctl add-br br0
ovs-vsctl add-port br0 eno2
# ceate virtual net
cat << EOF > br0.xml
<network>
<name>br0</name>
<forward mode='bridge'/>
<bridge name='br0'/>
<virtualport type='openvswitch'/>
<portgroup name='overcloud'>
<vlan trunk='yes'>
<tag id='700' nativeMode='untagged'/>
<tag id='710'/>
<tag id='720'/>
<tag id='730'/>
<tag id='740'/>
<tag id='750'/>
</vlan>
</portgroup>
</network>
EOF
virsh net-define br0.xml
virsh net-start br0
virsh net-autostart br0
# Create undercloud vm
cat << EOF > $HOME/local.repo
[local-rhel-7-server-rpms]
name = Red Hat Enterprise Linux 7 Server (RPMs) local
baseurl = http://10.10.50.2/rhel-7-server-rpms
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[local-rhel-7-server-optional-rpms]
name = Red Hat Enterprise Linux 7 Server - Optional (RPMs) local
baseurl = http://10.10.50.2/rhel-7-server-optional-rpms
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[local-rhel-7-server-extras-rpms]
name = Red Hat Enterprise Linux 7 Server - Extras (RPMs) local
baseurl = http://10.10.50.2/rhel-7-server-extras-rpms
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[local-rhel-7-server-openstack-13-rpms]
name = Red Hat OpenStack Platform 13 for RHEL 7 (RPMs) local
baseurl = http://10.10.50.2/rhel-7-server-openstack-13-rpms
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[local-rhel-7-server-openstack-13-devtools-rpms]
name = Red Hat OpenStack Platform Dev Tools 13 for RHEL 7 (RPMs) local
baseurl = http://10.10.50.2/rhel-7-server-openstack-13-devtools-rpms
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[local-rhel-7-server-ansible-2.6-rpms]
name = Red Hat Ansible 2.6 for RHEL 7 (RPMs) local
baseurl = http://10.10.50.2/rhel-7-server-ansible-2.6-rpms
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[local-rhel-7-fast-datapath-rpms]
name = Red Hat Fast Datapath for RHEL 7 (RPMs) local
baseurl = http://10.10.50.2/rhel-7-fast-datapath-rpms
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[local-rhel-server-rhscl-7-rpms]
name = Red Hat Software collections 7 (RPMs) local
baseurl = http://10.10.50.2/rhel-server-rhscl-7-rpms
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[local-rhel-ha-for-rhel-7-server-rpms]
name = Red Hat HA for RHEL 7 (RPMs) local
baseurl = http://10.10.50.2/rhel-ha-for-rhel-7-server-rpms
enabled = 1
gpgcheck = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
EOF
export LIBGUESTFS_BACKEND=direct
qemu-img create -f qcow2 /var/lib/libvirt/images/${undercloud_name}.qcow2 100G
virt-resize --expand /dev/sda1 ${cloud_image} /var/lib/libvirt/images/${undercloud_name}.qcow2
virt-customize -a /var/lib/libvirt/images/${undercloud_name}.qcow2 \
--run-command 'xfs_growfs /' \
--root-password password:${root_password} \
--hostname ${undercloud_name}.${undercloud_suffix} \
--run-command 'useradd stack' \
--password stack:password:${stack_password} \
--ssh-inject stack:file:$HOME/.ssh/id_rsa.pub \
--run-command 'echo "stack ALL=(root) NOPASSWD:ALL" | tee -a /etc/sudoers.d/stack' \
--chmod 0440:/etc/sudoers.d/stack \
--run-command 'sed -i "s/dhcp/none/g" /etc/sysconfig/network-scripts/ifcfg-eth0' \
--run-command 'echo "IPADDR=10.10.50.10" >> /etc/sysconfig/network-scripts/ifcfg-eth0' \
--run-command 'echo "PREFIX=24" >> /etc/sysconfig/network-scripts/ifcfg-eth0' \
--run-command 'echo "GATEWAY=10.10.50.1" >> /etc/sysconfig/network-scripts/ifcfg-eth0' \
--run-command 'echo "DNS1=8.8.8.8" >> /etc/sysconfig/network-scripts/ifcfg-eth0' \
--run-command 'sed -i "s/PasswordAuthentication no/PasswordAuthentication yes/g" /etc/ssh/sshd_config' \
--run-command 'systemctl enable sshd' \
--run-command 'yum remove -y cloud-init' \
--upload $HOME/local.repo:/etc/yum.repos.d/local.repo \
--selinux-relabel
virt-install --name ${undercloud_name} \
--disk /var/lib/libvirt/images/${undercloud_name}.qcow2 \
--vcpus=${vcpus} \
--ram=${vram} \
--network bridge=br-mgmt,model=virtio \
--network network=br0,model=virtio,portgroup=overcloud \
--virt-type kvm \
--import \
--os-variant rhel7 \
--graphics vnc \
--serial pty \
--noautoconsole \
--console pty,target_type=virtio
virsh destroy ${undercloud_name}
#clone this vm for deploy undercloud