Skip to content

Commit 136c89f

Browse files
authored
Networking and MySQL handling improvements and fixes (#1)
* Networking and MySQL handling improvements and fixes Co-authored-by: Bojan Vitnik <bvitnik@mainstream.eu>
1 parent e39bc11 commit 136c89f

1 file changed

Lines changed: 66 additions & 39 deletions

File tree

install.sh

Lines changed: 66 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ INTERFACE=
3030
BRIDGE=cloudbr0
3131
HOST_IP=
3232
GATEWAY=
33+
DNS="8.8.8.8, 1.1.1.1"
3334

3435
# --- helper functions for logs ---
3536
info()
@@ -77,47 +78,59 @@ apt-get install -y openssh-server sudo wget jq htop tar nmap bridge-utils
7778
### Setup Bridge ###
7879

7980
setup_bridge() {
80-
if brctl show $BRIDGE > /dev/null; then
81+
if brctl show $BRIDGE > /dev/null 2>&1; then
82+
info "Bridge $BRIDGE already exists, skipping create..."
8183
return
8284
fi
8385

84-
#FIXME: we want to avoid virtual nics
85-
# ls -l /sys/class/net/ | grep -v virtual
86-
interface=$(ls /sys/class/net/ | grep -v 'lo' | head -1)
87-
gateway=$(ip route show 0.0.0.0/0 dev ens3 | cut -d\ -f3)
88-
hostip=$(ip -f inet addr show $interface | sed -En -e 's/.*inet ([0-9.]+).*/\1/p')
86+
interface=$(find /sys/class/net -type l -not -lname '*virtual*' -printf '%f\n' | sort | head -1)
87+
gateway=$(ip route show 0.0.0.0/0 dev $interface | cut -d ' ' -f 3)
88+
hostipandsub=$(ip -4 -br addr show ens192 | awk '{ print $3; }' )
8989
info "Setting up bridge on $interface which has IP $hostip and gateway $gateway"
90-
echo "network:
91-
version: 2
92-
renderer: networkd
93-
ethernets:
94-
$interface:
95-
dhcp4: false
96-
dhcp6: false
97-
optional: true
98-
bridges:
99-
$BRIDGE:
100-
addresses: [$hostip/24]
101-
routes:
90+
91+
cat << EOF > /etc/netplan/01-netcfg.yaml
92+
network:
93+
version: 2
94+
renderer: networkd
95+
ethernets:
96+
$interface:
97+
dhcp4: false
98+
dhcp6: false
99+
optional: true
100+
bridges:
101+
$BRIDGE:
102+
addresses: [$hostipandsub]
103+
routes:
102104
- to: default
103105
via: $gateway
104-
nameservers:
105-
addresses: [8.8.8.8, 1.1.1.1]
106-
interfaces: [$interface]
107-
dhcp4: false
108-
dhcp6: false
109-
parameters:
110-
stp: false
111-
forward-delay: 0" > /etc/netplan/01-netcfg.yaml
106+
nameservers:
107+
addresses: [$DNS]
108+
interfaces: [$interface]
109+
dhcp4: false
110+
dhcp6: false
111+
parameters:
112+
stp: false
113+
forward-delay: 0
114+
EOF
115+
116+
# FIX netplan complaining about permissions
117+
chmod 600 /etc/netplan/01-netcfg.yaml
112118

113119
info "Disabling cloud-init netplan config"
114120
rm -f /etc/netplan/50-cloud-init.yaml
115-
echo "network: {config: disabled}" > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
121+
if [[ ! -f "/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg" && ! -f "/etc/cloud/cloud.cfg.d/99_disable-network-config.cfg" ]]; then
122+
echo "network: {config: disabled}" > /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
123+
fi
124+
125+
# FIXME workaround for VMware tools generated network config
126+
if [[ -f "/etc/netplan/99-netcfg-vmware.yaml" ]]; then
127+
mv /etc/netplan/99-netcfg-vmware.yaml /etc/netplan/99-netcfg-vmware.yaml.bak
128+
fi
116129

117130
netplan generate
118131
netplan apply
119132

120-
export INTERFACE=$interface
133+
export INTERFACE="$interface"
121134
}
122135

123136
### Setup CloudStack Packages ###
@@ -146,23 +159,35 @@ install_packages() {
146159

147160
configure_mysql() {
148161
info "Configuring MySQL Server: $(mysql -V)"
149-
if grep 'sql-mode' /etc/mysql/mysql.conf.d/mysqld.cnf > /dev/null; then
162+
if [[ -f "/etc/mysql/mysql.conf.d/cloudstack.cnf" ]]; then
150163
info "Skipping MySQL configuration setup, already done"
151164
return
152165
fi
153-
echo "server_id = 1
154-
sql-mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,ERROR_FOR_DIVISION_BY_ZERO,NO_ZERO_DATE,NO_ZERO_IN_DATE,NO_ENGINE_SUBSTITUTION"
155-
innodb_rollback_on_timeout=1
156-
innodb_lock_wait_timeout=600
157-
max_connections=1000
158-
log-bin=mysql-bin
159-
binlog-format = 'ROW'" >> /etc/mysql/mysql.conf.d/mysqld.cnf
166+
167+
sqlmode="$(mysql -B -e "show global variables like 'sql_mode'" | grep sql_mode | awk '{ print $2; }' | sed -e 's/ONLY_FULL_GROUP_BY,//')"
168+
169+
cat > /etc/mysql/mysql.conf.d/cloudstack.cnf <<EOF
170+
[mysqld]
171+
server_id = 1
172+
sql_mode = "$sqlmode"
173+
innodb_rollback_on_timeout = 1
174+
innodb_lock_wait_timeout = 600
175+
max_connections = 1000
176+
log_bin = mysql-bin
177+
binlog_format = "ROW"
178+
EOF
179+
160180
systemctl restart mysql
161181
}
162182

163183
configure_storage() {
164184
info "Configuring NFS Storage"
165-
echo "/export *(rw,async,no_root_squash,no_subtree_check)" > /etc/exports
185+
if grep "^/export " /etc/exports > /dev/null; then
186+
info "Skipping NFS Storage configuration setup, already done"
187+
return
188+
fi
189+
190+
echo "/export *(rw,async,no_root_squash,no_subtree_check)" >> /etc/exports
166191
mkdir -p /export/primary /export/secondary
167192
exportfs -a
168193

@@ -234,6 +259,8 @@ deploy_zone() {
234259
cmk set asyncblock true
235260
cmk sync
236261

262+
info "Starting Zone deployment"
263+
237264
zone_id=$(cmk create zone dns1=8.8.8.8 internaldns1=$GATEWAY name=AdvZone1 networktype=Advanced | jq '.zone.id')
238265
info "Created CloudStack Zone with ID $zone_id"
239266

@@ -311,8 +338,8 @@ Password: password
311338
### Installer: Setup ###
312339

313340
setup_bridge
314-
export HOST_IP=$(ip -f inet addr show $BRIDGE | sed -En -e 's/.*inet ([0-9.]+).*/\1/p')
315-
export GATEWAY=$(ip route show 0.0.0.0/0 dev $BRIDGE | cut -d\ -f3)
341+
export HOST_IP=$(ip -4 -br addr show $BRIDGE | awk '{ print $3; }' | sed -e 's/\/[0-9]\+//')
342+
export GATEWAY=$(ip route show 0.0.0.0/0 dev $BRIDGE | cut -d ' ' -f 3)
316343
info "Bridge $BRIDGE is setup with IP $HOST_IP"
317344

318345
configure_repo

0 commit comments

Comments
 (0)