Skip to content

Commit 8baf7ac

Browse files
committed
install.sh: finish script that install cloudstack, mysql, nfs and kvm
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent e15e973 commit 8baf7ac

1 file changed

Lines changed: 168 additions & 16 deletions

File tree

install.sh

Lines changed: 168 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
set -e
2626
set -o noglob
2727

28+
CS_VERSION=4.18
29+
INTERFACE=
30+
BRIDGE=cloudbr0
31+
HOST_IP=
32+
2833
# --- helper functions for logs ---
2934
info()
3035
{
@@ -41,6 +46,7 @@ fatal()
4146
}
4247

4348
### Intro ###
49+
4450
echo "
4551
░█████╗░░█████╗░██╗░░██╗░░░██╗███╗░░██╗
4652
██╔══██╗██╔══██╗██║░██╔╝░░░██║████╗░██║
@@ -51,7 +57,7 @@ echo "
5157
CloudStack Installer By 🅁🄾🄷🄸🅃 🅈🄰🄳🄰🅅
5258
"
5359
info "Installing Apache CloudStack All-In-One-Box"
54-
info "NOTE: this works only on Ubuntu, and run as 'root' user!"
60+
info "NOTE: this works only on Ubuntu 22.04 (tested), and run as 'root' user!"
5561

5662
if [[ $EUID -ne 0 ]]; then
5763
fatal "This script must be run as root"
@@ -67,16 +73,18 @@ apt-get install -y openssh-server sudo vim htop tar bridge-utils
6773

6874
### Setup Bridge ###
6975

70-
#FIXME: we want to avoid virtual nics
71-
# ls -l /sys/class/net/ | grep -v virtual
72-
73-
interface=$(ls /sys/class/net/ | grep -v 'lo' | head -1)
74-
gateway=$(ip route show 0.0.0.0/0 dev ens3 | cut -d\ -f3)
75-
hostip=$(ip -f inet addr show $interface | sed -En -e 's/.*inet ([0-9.]+).*/\1/p')
76+
setup_bridge() {
77+
if brctl show $BRIDGE > /dev/null; then
78+
return
79+
fi
7680

77-
info "Setting up bridge on $interface which has IP $hostip and gateway $gateway"
78-
79-
echo "network:
81+
#FIXME: we want to avoid virtual nics
82+
# ls -l /sys/class/net/ | grep -v virtual
83+
interface=$(ls /sys/class/net/ | grep -v 'lo' | head -1)
84+
gateway=$(ip route show 0.0.0.0/0 dev ens3 | cut -d\ -f3)
85+
hostip=$(ip -f inet addr show $interface | sed -En -e 's/.*inet ([0-9.]+).*/\1/p')
86+
info "Setting up bridge on $interface which has IP $hostip and gateway $gateway"
87+
echo "network:
8088
version: 2
8189
renderer: networkd
8290
ethernets:
@@ -85,7 +93,7 @@ echo "network:
8593
dhcp6: false
8694
optional: true
8795
bridges:
88-
cloudbr0:
96+
$BRIDGE:
8997
addresses: [$hostip/24]
9098
routes:
9199
- to: default
@@ -99,9 +107,153 @@ echo "network:
99107
stp: false
100108
forward-delay: 0" > /etc/netplan/01-netcfg.yaml
101109

102-
info "Disabling cloud-init netplan config"
103-
rm -f /etc/netplan/50-cloud-init.yaml
104-
echo "network: {config: disabled}" > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
110+
info "Disabling cloud-init netplan config"
111+
rm -f /etc/netplan/50-cloud-init.yaml
112+
echo "network: {config: disabled}" > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
113+
114+
netplan generate
115+
netplan apply
116+
117+
export INTERFACE=$interface
118+
}
119+
120+
### Setup CloudStack Packages ###
121+
122+
configure_repo() {
123+
info "Configuring CloudStack $CS_VERSION repo"
124+
mkdir -p /etc/apt/keyrings
125+
wget -O- http://packages.shapeblue.com/release.asc 2>/dev/null | gpg --dearmor | sudo tee /etc/apt/keyrings/cloudstack.gpg > /dev/null
126+
echo deb [signed-by=/etc/apt/keyrings/cloudstack.gpg] http://packages.shapeblue.com/cloudstack/upstream/debian/$CS_VERSION / > /etc/apt/sources.list.d/cloudstack.list
127+
apt-get update
128+
}
129+
130+
install_packages() {
131+
info "Installing CloudStack $CS_VERSION, MySQL and NFS server"
132+
if dpkg -l | grep cloudstack-management > /dev/null; then
133+
warn "CloudStack packages seem to be already installed, skipping CloudStack packages installation"
134+
apt-get install -y mysql-server nfs-kernel-server quota qemu-kvm
135+
else
136+
apt-get install -y cloudstack-management cloudstack-usage mysql-server nfs-kernel-server quota qemu-kvm cloudstack-agent
137+
systemctl daemon-reload
138+
systemctl stop cloudstack-management cloudstack-usage cloudstack-agent
139+
fi
140+
}
141+
142+
### Configure Methods ###
143+
144+
configure_mysql() {
145+
info "Configuring MySQL Server: $(mysql -V)"
146+
if grep 'sql-mode' /etc/mysql/mysql.conf.d/mysqld.cnf > /dev/null; then
147+
info "Skipping MySQL configuration setup, already done"
148+
return
149+
fi
150+
echo "server_id = 1
151+
sql-mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ERROR_FOR_DIVISION_BY_ZERO,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_ENGINE_SUBSTITUTION"
152+
innodb_rollback_on_timeout=1
153+
innodb_lock_wait_timeout=600
154+
max_connections=1000
155+
log-bin=mysql-bin
156+
binlog-format = 'ROW'" >> /etc/mysql/mysql.conf.d/mysqld.cnf
157+
systemctl restart mysql
158+
}
159+
160+
configure_storage() {
161+
info "Configuring NFS Storage"
162+
echo "/export *(rw,async,no_root_squash,no_subtree_check)" > /etc/exports
163+
mkdir -p /export/primary /export/secondary
164+
exportfs -a
165+
166+
sed -i -e 's/^RPCMOUNTDOPTS="--manage-gids"$/RPCMOUNTDOPTS="-p 892 --manage-gids"/g' /etc/default/nfs-kernel-server
167+
sed -i -e 's/^STATDOPTS=$/STATDOPTS="--port 662 --outgoing-port 2020"/g' /etc/default/nfs-common
168+
if ! grep 'NEED_STATD=yes' /etc/default/nfs-common > /dev/null; then
169+
echo "NEED_STATD=yes" >> /etc/default/nfs-common
170+
fi
171+
sed -i -e 's/^RPCRQUOTADOPTS=$/RPCRQUOTADOPTS="-p 875"/g' /etc/default/quota
172+
173+
service nfs-kernel-server restart
174+
info "NFS exports created: $(exportfs)"
175+
}
176+
177+
configure_host() {
178+
info "Configuring KVM on this host"
179+
sed -i -e 's/\#vnc_listen.*$/vnc_listen = "0.0.0.0"/g' /etc/libvirt/qemu.conf
180+
if ! grep 'LIBVIRTD_ARGS="--listen"' /etc/default/libvirtd > /dev/null; then
181+
echo LIBVIRTD_ARGS=\"--listen\" >> /etc/default/libvirtd
182+
fi
183+
if ! grep 'listen_tcp=1' /etc/libvirt/libvirtd.conf > /dev/null; then
184+
echo 'listen_tcp=1' >> /etc/libvirt/libvirtd.conf
185+
echo 'listen_tls=0' >> /etc/libvirt/libvirtd.conf
186+
echo 'tcp_port = "16509"' >> /etc/libvirt/libvirtd.conf
187+
echo 'mdns_adv = 0' >> /etc/libvirt/libvirtd.conf
188+
echo 'auth_tcp = "none"' >> /etc/libvirt/libvirtd.conf
189+
systemctl mask libvirtd.socket libvirtd-ro.socket libvirtd-admin.socket libvirtd-tls.socket libvirtd-tcp.socket
190+
systemctl restart libvirtd
191+
192+
# Ubuntu: disable apparmor
193+
ln -s /etc/apparmor.d/usr.sbin.libvirtd /etc/apparmor.d/disable/
194+
ln -s /etc/apparmor.d/usr.lib.libvirt.virt-aa-helper /etc/apparmor.d/disable/
195+
apparmor_parser -R /etc/apparmor.d/usr.sbin.libvirtd
196+
apparmor_parser -R /etc/apparmor.d/usr.lib.libvirt.virt-aa-helper
197+
fi
198+
199+
if ! kvm-ok; then
200+
warn "KVM may not work on your host"
201+
else
202+
info "KVM host configured"
203+
virsh nodeinfo
204+
fi
205+
}
206+
207+
deploy_cloudstack() {
208+
if systemctl is-active cloudstack-management > /dev/null; then
209+
info "CloudStack Management Server is already running, skipping DB deployment"
210+
return
211+
fi
212+
info "Deploying CloudStack Database"
213+
cloudstack-setup-databases cloud:cloud@localhost --deploy-as=root: #-i <cloudbr0 IP here>
214+
info "Deploying CloudStack Management Server"
215+
cloudstack-setup-management
216+
}
217+
218+
setup_completed() {
219+
info "CloudStack installation completed!"
220+
info "Access CloudStack UI at: http://$HOST_IP:8080/client (username: admin, password: password)"
221+
echo
222+
}
223+
224+
deploy_zone() {
225+
info "Deploying CloudStack Zone"
226+
}
227+
228+
display_url() {
229+
echo "
230+
█████████████████████████████████████████████████████████████
231+
█─▄▄▄─█▄─▄███─▄▄─█▄─██─▄█▄─▄▄▀█─▄▄▄▄█─▄─▄─██▀▄─██─▄▄▄─█▄─█─▄█
232+
█─███▀██─██▀█─██─██─██─███─██─█▄▄▄▄─███─████─▀─██─███▀██─▄▀██
233+
▀▄▄▄▄▄▀▄▄▄▄▄▀▄▄▄▄▀▀▄▄▄▄▀▀▄▄▄▄▀▀▄▄▄▄▄▀▀▄▄▄▀▀▄▄▀▄▄▀▄▄▄▄▄▀▄▄▀▄▄▀
234+
235+
URL: http://$HOST_IP:8080/client
236+
User: admin
237+
Password: password
238+
"
239+
}
240+
241+
### Installer: Setup ###
242+
243+
setup_bridge
244+
HOST_IP=$(ip -f inet addr show $BRIDGE | sed -En -e 's/.*inet ([0-9.]+).*/\1/p')
245+
info "Bridge $BRIDGE is setup with IP $HOST_IP"
246+
247+
configure_repo
248+
install_packages
249+
configure_mysql
250+
configure_storage
251+
configure_host
252+
deploy_cloudstack
253+
setup_completed
254+
255+
### Installer: Deploy Zone ###
256+
257+
deploy_zone
105258

106-
netplan generate
107-
netplan apply
259+
display_url

0 commit comments

Comments
 (0)