Adaptions after frist install test
This commit is contained in:
197
seqs/librenms.sh
197
seqs/librenms.sh
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
#
|
#
|
||||||
## Installation and maintenance for LibreNMS
|
## Installation and maintenance for LibreNMS
|
||||||
## Using buster repositories for php 7.3 installation
|
|
||||||
|
|
||||||
toolName="librenms"
|
toolName="librenms"
|
||||||
|
toolUser="librenms"
|
||||||
phpVersion=
|
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'
|
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 " Install: $LNMS_DIR"
|
||||||
echo " Backup: $LNMS_BU_DIR"
|
echo " Backup: $LNMS_BU_DIR"
|
||||||
else
|
else
|
||||||
exit 1
|
[ $DRY -eq 0 ] && exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ step_2_info() {
|
|||||||
echoinfo "$libreDeps"
|
echoinfo "$libreDeps"
|
||||||
}
|
}
|
||||||
step_2() {
|
step_2() {
|
||||||
exe apt install $librePackages
|
exe apt install $libreDeps
|
||||||
endReturn -o $? "Failed to install $toolName dependencies"
|
endReturn -o $? "Failed to install $toolName dependencies"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,63 +60,151 @@ step_3() {
|
|||||||
endReturn -o $? "Failed to install $toolName php dependencies"
|
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() {
|
step_4() {
|
||||||
exe useradd librenms -d /opt/librenms -M -r
|
exe useradd $toolUser -d "$LNMS_DIR" -M -r -s "$(which bash)"
|
||||||
saveReturn $?
|
saveReturn $?
|
||||||
exe usermod -a -G librenms www-data
|
#exe usermod -a -G librenms www-data
|
||||||
saveReturn $?
|
#saveReturn $?
|
||||||
endReturn "Failed to create $toolName user"
|
endReturn "Failed to create user $toolUser"
|
||||||
}
|
}
|
||||||
|
|
||||||
step_5_info() { echo "Installing $toolName using composer"; }
|
step_5_info() { echo "Clone $toolName git repository"; }
|
||||||
step_5() {
|
step_5() {
|
||||||
cd /opt
|
exe git clone https://github.com/librenms/librenms.git "$LNMS_DIR"
|
||||||
exe composer create-project --no-dev --keep-vcs librenms/librenms librenms dev-master
|
# 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"
|
endReturn -o $? "Failed to install php dependencies"
|
||||||
}
|
}
|
||||||
|
|
||||||
step_10_info() { echo "Create mysql database for $toolName"; }
|
step_10_info() { echo "Create mysql database for $toolName"; }
|
||||||
step_10() {
|
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"
|
endReturn -o $? "Failed to create mysql database $LNMS_DB_NAME"
|
||||||
}
|
}
|
||||||
|
|
||||||
step_11_info() { echo "MariaDB configuration"; }
|
step_11_info() { echo "MariaDB configuration"; }
|
||||||
step_11() {
|
step_11() {
|
||||||
echo
|
cat << SQLCONF_END
|
||||||
echo "Edit or create /etc/mysql/mariadb.conf.d/90-myconfig.cnf and add:"
|
|
||||||
echo
|
Edit or create /etc/mysql/mariadb.conf.d/90-myconfig.cnf and add:
|
||||||
echo "------------------------"
|
|
||||||
echo "[mysqld]"
|
------------------------
|
||||||
echo "innodb_file_per_table=1"
|
[mysqld]
|
||||||
echo "lower_case_table_names=0"
|
innodb_file_per_table=1
|
||||||
echo "------------------------"
|
lower_case_table_names=0
|
||||||
echo
|
------------------------
|
||||||
echo "Restart mysql afterwards:"
|
|
||||||
echo "service mysql restart"
|
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() {
|
step_12() {
|
||||||
echo
|
cat << PHPCONF_END
|
||||||
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
|
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 "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"
|
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 "date.timezone = Europe/Berlin"
|
-------------------------------------------
|
||||||
echo "-------------------------------------------"
|
date.timezone = Europe/Berlin
|
||||||
echo
|
-------------------------------------------
|
||||||
echo "Restart php-fpm afterwards:"
|
|
||||||
echo "service php7.3-fpm restart"
|
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_info() { echo "Backup ${toolName} web direcotry"; }
|
||||||
step_30_alias() { ALIAS="backup"; }
|
step_30_alias() { ALIAS="backup"; }
|
||||||
step_30() {
|
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")\""
|
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() {
|
step_31() {
|
||||||
case "$2" in
|
case "$2" in
|
||||||
daily|Daily|DAILY)
|
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\""
|
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\""
|
exep "mysqldump --single-transaction -u root ${LNMS_DB_NAME} | bzip2 -c > \"${LNMS_BU_DIR}/monthly/\`date +%Y%m%d\`_${toolName}.sql.bz2\""
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -137,23 +225,26 @@ step_31() {
|
|||||||
|
|
||||||
step_40_info() { echo "Switch $toolName installation to monthly stable"; }
|
step_40_info() { echo "Switch $toolName installation to monthly stable"; }
|
||||||
step_40() {
|
step_40() {
|
||||||
echo
|
cat << STABLE_EOF
|
||||||
echo "Add following to /opt/librenms/config.php"
|
|
||||||
echo
|
Add following to ${LNMS_DIR}/config.php
|
||||||
echo "--------------------------------------"
|
|
||||||
echo "\$config['update_channel'] = 'release';"
|
--------------------------------------
|
||||||
echo "--------------------------------------"
|
\$config['update_channel'] = 'release';
|
||||||
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))"
|
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_info() { echo "Fix librenms permission"; }
|
||||||
step_42_alias() { ALIAS="repair"; }
|
step_42_alias() { ALIAS="fix"; }
|
||||||
step_42() {
|
step_42() {
|
||||||
exe chown -R librenms:librenms /opt/librenms
|
exe chown -R ${toolUser}: "$LNMS_DIR"
|
||||||
exe setfacl -d -m g::rwx /opt/librenms/bootstrap/cache /opt/librenms/storage /opt/librenms/logs /opt/librenms/rrd
|
exe chmod 771 "${LNMS_DIR}"
|
||||||
exe chmod -R ug=rwX /opt/librenms/bootstrap/cache /opt/librenms/storage /opt/librenms/logs /opt/librenms/rrd
|
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() {
|
fetchPhpVersion() {
|
||||||
|
Reference in New Issue
Block a user