Adaptions after frist install test

This commit is contained in:
2021-02-18 21:42:26 +01:00
parent 5539c6b78e
commit 9f9f684dd5

View File

@@ -2,12 +2,12 @@
#
## Installation and maintenance for LibreNMS
## Using buster repositories for php 7.3 installation
toolName="librenms"
toolUser="librenms"
phpVersion=
libreDeps="acl curl composer fping git graphviz imagemagick mtr-tiny nmap rrdtool snmp snmpd whois python3-dotenv python3-pymysql python3-redis python3-setuptools"
libreDeps='acl curl composer fping git graphviz imagemagick mtr-tiny nmap rrdtool snmp snmpd whois python3-dotenv python3-pymysql python3-redis python3-setuptools'
librePhpDeps='php${phpVersion}-cli php${phpVersion}-curl php${phpVersion}-fpm php${phpVersion}-gd php${phpVersion}-json php${phpVersion}-mbstring php${phpVersion}-mysql php${phpVersion}-snmp php${phpVersion}-xml php${phpVersion}-zip'
@@ -30,7 +30,7 @@ step_config() {
echo " Install: $LNMS_DIR"
echo " Backup: $LNMS_BU_DIR"
else
exit 1
[ $DRY -eq 0 ] && exit 1
fi
}
@@ -45,7 +45,7 @@ step_2_info() {
echoinfo "$libreDeps"
}
step_2() {
exe apt install $librePackages
exe apt install $libreDeps
endReturn -o $? "Failed to install $toolName dependencies"
}
@@ -60,63 +60,151 @@ step_3() {
endReturn -o $? "Failed to install $toolName php dependencies"
}
step_4_info() { echo "Adding $toolName user (librenms:librenms)"; }
step_4_info() { echo "Adding $toolName user ($toolUser)"; }
step_4() {
exe useradd librenms -d /opt/librenms -M -r
exe useradd $toolUser -d "$LNMS_DIR" -M -r -s "$(which bash)"
saveReturn $?
exe usermod -a -G librenms www-data
saveReturn $?
endReturn "Failed to create $toolName user"
#exe usermod -a -G librenms www-data
#saveReturn $?
endReturn "Failed to create user $toolUser"
}
step_5_info() { echo "Installing $toolName using composer"; }
step_5_info() { echo "Clone $toolName git repository"; }
step_5() {
cd /opt
exe composer create-project --no-dev --keep-vcs librenms/librenms librenms dev-master
exe git clone https://github.com/librenms/librenms.git "$LNMS_DIR"
# set permissions
step fix
}
step_6_info() { echo "Installing $toolName using composer"; }
step_6() {
exe sudo -u librenms "${LNMS_DIR}/scripts/composer_wrapper.php" install --no-dev
endReturn -o $? "Failed to install php dependencies"
}
step_10_info() { echo "Create mysql database for $toolName"; }
step_10() {
${WDIR}/mysql.sh -q createdb
local libreDbOpt=
if [ ! -z "$LNMS_DB_NAME" ] ; then
libreDbOpt="-d $LNMS_DB_NAME"
fi
exe ${WDIR}/mysql.sh -q createdb --charset utf8 $libreDbOpt
endReturn -o $? "Failed to create mysql database $LNMS_DB_NAME"
}
step_11_info() { echo "MariaDB configuration"; }
step_11() {
echo
echo "Edit or create /etc/mysql/mariadb.conf.d/90-myconfig.cnf and add:"
echo
echo "------------------------"
echo "[mysqld]"
echo "innodb_file_per_table=1"
echo "lower_case_table_names=0"
echo "------------------------"
echo
echo "Restart mysql afterwards:"
echo "service mysql restart"
cat << SQLCONF_END
Edit or create /etc/mysql/mariadb.conf.d/90-myconfig.cnf and add:
------------------------
[mysqld]
innodb_file_per_table=1
lower_case_table_names=0
------------------------
Restart mysql afterwards:
service mysql restart
SQLCONF_END
}
step_12_info() { echo "PHP fpm/cli configuration"; }
step_12_info() { echo "PHP fpm/cli timezone configuration"; }
step_12() {
echo
echo "Ensure date.timezone is set in php.ini to your preferred time zone. See http://php.net/manual/en/timezones.php for a list of supported timezones. Valid examples are: \"America/New_York\", \"Europe/Berlin\", \"Etc/UTC\"."
echo
echo "vi /etc/php/7.3/fpm/conf.d/90-custom_pi.ini"
echo "vi /etc/php/7.3/cli/conf.d/90-custom_pi.ini"
echo
echo "-------------------------------------------"
echo "date.timezone = Europe/Berlin"
echo "-------------------------------------------"
echo
echo "Restart php-fpm afterwards:"
echo "service php7.3-fpm restart"
cat << PHPCONF_END
Ensure date.timezone is set in php.ini to your preferred time zone. See http://php.net/manual/en/timezones.php for a list of supported timezones. Valid examples are: "America/New_York", "Europe/Berlin", "Etc/UTC".
vi /etc/php/7.3/fpm/conf.d/90-custom_pi.ini
vi /etc/php/7.3/cli/conf.d/90-custom_pi.ini
-------------------------------------------
date.timezone = Europe/Berlin
-------------------------------------------
Restart php-fpm afterwards:
service php7.3-fpm restart
PHPCONF_END
}
step_13_info() { echo "PHP fpm configuration"; }
step_13() {
cat << FPMCONF_END
cp /etc/php/7.3/fpm/pool.d/www.conf /etc/php/7.3/fpm/pool.d/librenms.conf
vi /etc/php/7.3/fpm/pool.d/librenms.conf
# Change [www] to [librenms]:
[librenms]
# Change user and group to "librenms":
user = librenms
group = librenms
# Change listen to a unique name:
listen = /run/php-fpm-librenms.sock
FPMCONF_END
}
step_14_info() { echo "Nginx configuration"; }
step_14() {
cat << NGINXCONF_END
server {
listen 80;
server_name librenms.example.com;
root $LNMS_DIR/html;
index index.php;
charset utf-8;
gzip on;
gzip_types text/css application/javascript text/javascript application/x-javascript image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
location / {
try_files \$uri \$uri/ /index.php?\$query_string;
}
location ~ [^/]\\.php(/|$) {
fastcgi_pass unix:/run/php-fpm-librenms.sock;
fastcgi_split_path_info ^(.+\\.php)(/.+)$;
include fastcgi.conf;
}
location ~ /\\.(?!well-known).* {
deny all;
}
}
NGINXCONF_END
}
step_20_info() { echo "Create $toolName cron job"; }
step_20_alias() { ALIAS="cron"; }
step_20() {
echoseq -n " [I] Creating $lnmsCronLoc ... "
exe cp "${LNMS_DIR}/librenms.nonroot.cron" "$lnmsCronLoc" && echoseq "Ok" || echoseq "Nok"
}
lnmsCronLoc="/etc/cron.d/librenms"
step_22_info() { echo "Enable lnms command completion"; }
step_22_alias() { ALIAS="cmdcompletion"; }
step_22() {
exep 'echo -e "#!/bin/bash\nsudo -u '$toolUser' \"'$LNMS_DIR'/lnms\" \"\$@\"" > '"$lnmsLocalBin"
exe chmod 744 "$lnmsLocalBin"
exe cp "${LNMS_DIR}/misc/lnms-completion.bash" /etc/bash_completion.d/
}
lnmsLocalBin="/usr/local/bin/lnms"
step_24_info() { echo "Copy logrotate config"; }
step_24_alias() { ALIAS="logrotate"; }
step_24() {
echoseq -n " [I] Creating $lnmsLogrotLoc ... "
exe cp "${LNMS_DIR}/misc/librenms.logrotate" "$lnmsLogrotLoc" && echoseq "Ok" || echoseq "Nok"
}
lnmsLogrotLoc="/etc/logrotate.d/librenms"
step_30_info() { echo "Backup ${toolName} web direcotry"; }
step_30_alias() { ALIAS="backup"; }
step_30() {
[ $QUIET -ne 2 ] && echo " [I] Backup install directory ${LNMS_DIR}..."
echoseq " [I] Backup install directory ${LNMS_DIR}"
exep "cd \"${LNMS_DIR}\"/.. && tar czf \"${LNMS_BU_DIR}/\`date +%Y%m%d\`_${toolName}_web.tar.gz\" \"$(basename "$LNMS_DIR")\""
}
@@ -125,11 +213,11 @@ step_31_alias() { ALIAS="backupdb"; }
step_31() {
case "$2" in
daily|Daily|DAILY)
[ $QUIET -ne 2 ] && echo " [I] Daily backup..."
echoseq " [I] Daily backup..."
exep "mysqldump --single-transaction -u root ${LNMS_DB_NAME} | bzip2 -c > \"${LNMS_BU_DIR}/${toolName}_daily.sql.bz2\""
;;
*)
[ $QUIET -ne 2 ] && echo " [I] Monthly backup..."
echoseq " [I] Monthly backup..."
exep "mysqldump --single-transaction -u root ${LNMS_DB_NAME} | bzip2 -c > \"${LNMS_BU_DIR}/monthly/\`date +%Y%m%d\`_${toolName}.sql.bz2\""
;;
esac
@@ -137,23 +225,26 @@ step_31() {
step_40_info() { echo "Switch $toolName installation to monthly stable"; }
step_40() {
echo
echo "Add following to /opt/librenms/config.php"
echo
echo "--------------------------------------"
echo "\$config['update_channel'] = 'release';"
echo "--------------------------------------"
echo
echo "Execute following command afterwards:"
echo "cd /opt/librenms && git fetch --tags && git checkout \$(git describe --tags \$(git rev-list --tags --max-count=1))"
cat << STABLE_EOF
Add following to ${LNMS_DIR}/config.php
--------------------------------------
\$config['update_channel'] = 'release';
--------------------------------------
Execute following command afterwards:
cd $LNMS_DIR && git fetch --tags && git checkout \$(git describe --tags \$(git rev-list --tags --max-count=1))
STABLE_EOF
}
step_42_info() { echo "Fix librenms permission"; }
step_42_alias() { ALIAS="repair"; }
step_42_alias() { ALIAS="fix"; }
step_42() {
exe chown -R librenms:librenms /opt/librenms
exe setfacl -d -m g::rwx /opt/librenms/bootstrap/cache /opt/librenms/storage /opt/librenms/logs /opt/librenms/rrd
exe chmod -R ug=rwX /opt/librenms/bootstrap/cache /opt/librenms/storage /opt/librenms/logs /opt/librenms/rrd
exe chown -R ${toolUser}: "$LNMS_DIR"
exe chmod 771 "${LNMS_DIR}"
exe setfacl -d -m g::rwx "${LNMS_DIR}/rrd" "${LNMS_DIR}/logs" "${LNMS_DIR}/bootstrap/cache/" "${LNMS_DIR}/storage/"
exe setfacl -R -m g::rwx "${LNMS_DIR}/rrd" "${LNMS_DIR}/logs" "${LNMS_DIR}/bootstrap/cache/" "${LNMS_DIR}/storage/"
}
fetchPhpVersion() {