74 lines
2.5 KiB
Bash
Executable File
74 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# base settings
|
|
set -e
|
|
|
|
[ -e /firstboot ] || exit 0
|
|
|
|
echo 'Setting defaults...'
|
|
localectl --no-convert set-keymap de-latin1-nodeadkeys
|
|
|
|
echo 'Activate services...'
|
|
timedatectl set-ntp true
|
|
|
|
# variables
|
|
LABEL="DATA"
|
|
DATABASE_PASS="Di1sgMySQLPwd."
|
|
|
|
# Data partition
|
|
echo 'Mount data partition...'
|
|
mkdir -p /$LABEL
|
|
if [ ! -L "/dev/disk/by-label/$LABEL" ]; then
|
|
echo 'ERROR: Data partition not found!'
|
|
echo "Please create a data partition with ext4 filesystem and label \"$LABEL\":"
|
|
echo "# cfdisk /dev/<disk> (use GPT label, create linux partition)"
|
|
echo "# mkfs.ext4 -L $LABEL /dev/<partition>"
|
|
exit 1
|
|
fi
|
|
if ! grep -Fq "LABEL=$LABEL" /etc/fstab; then
|
|
echo "LABEL=$LABEL /$LABEL ext4 noatime 0 1" >> /etc/fstab
|
|
fi
|
|
mount -a
|
|
if ! mount | grep /$LABEL > /dev/null; then
|
|
echo "ERROR: Could not mount data partition!"
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -d "/$LABEL/var/lib/mysql/zabbix" ]; then
|
|
echo 'Initialize MariaDB...'
|
|
systemctl stop mariadb
|
|
mkdir -p /$LABEL/var/lib/mysql
|
|
rm -rf /$LABEL/var/lib/mysql/*
|
|
cp -a /var/lib/mysql/. /$LABEL/var/lib/mysql
|
|
sed -i "s:^datadir.*:datadir = /$LABEL/var/lib/mysql:" /etc/mysql/mariadb.d/50-distro-server.cnf
|
|
systemctl start mariadb
|
|
sleep 5
|
|
|
|
echo 'Create Zabbix database...'
|
|
mysql -u root -e "CREATE USER 'zabbix'@'localhost' IDENTIFIED BY '$DATABASE_PASS'"
|
|
mysql -u root -e "CREATE DATABASE zabbix DEFAULT CHARACTER SET utf8 COLLATE utf8_bin;"
|
|
mysql -u root -e "GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED by '$DATABASE_PASS';"
|
|
mysql -u root -e "FLUSH PRIVILEGES;"
|
|
|
|
echo 'Import Zabbix MySQL data'
|
|
mysql -u root zabbix < /usr/share/zabbix/database/mysql/schema.sql
|
|
mysql -u root zabbix < /usr/share/zabbix/database/mysql/images.sql
|
|
mysql -u root zabbix < /usr/share/zabbix/database/mysql/data.sql
|
|
else
|
|
echo 'Start MariaDB...'
|
|
sed -i "s:^datadir.*:datadir = /$LABEL/var/lib/mysql:" /etc/mysql/mariadb.d/50-distro-server.cnf
|
|
systemctl start mariadb
|
|
fi
|
|
echo 'Enable database...'
|
|
systemctl enable mariadb
|
|
|
|
echo 'Start Zabbix...'
|
|
sed -i "s:# DBPassword=:DBPassword=${DATABASE_PASS}:" /etc/zabbix/zabbix_server.conf
|
|
sed -i "s:\$DB\['PASSWORD'\].*:\$DB\['PASSWORD'\] = '${DATABASE_PASS}';:" /var/www/localhost/htdocs/zabbix/conf/zabbix.conf.php
|
|
systemctl start zabbix-server
|
|
systemctl enable zabbix-server
|
|
systemctl start zabbix-agentd
|
|
systemctl enable zabbix-agentd
|
|
|
|
rm /firstboot
|