|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright (c) 2021-2025 community-scripts ORG |
| 4 | +# Author: michelroegl-brunner |
| 5 | +# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE |
| 6 | +# Source: https://www.librenms.org/ |
| 7 | + |
| 8 | +source /dev/stdin <<<"$FUNCTIONS_FILE_PATH" |
| 9 | +color |
| 10 | +verb_ip6 |
| 11 | +catch_errors |
| 12 | +setting_up_container |
| 13 | +network_check |
| 14 | +update_os |
| 15 | + |
| 16 | +msg_info "Installing Dependencies" |
| 17 | +$STD apt install -y \ |
| 18 | + acl \ |
| 19 | + fping \ |
| 20 | + graphviz \ |
| 21 | + imagemagick \ |
| 22 | + mtr-tiny \ |
| 23 | + nginx \ |
| 24 | + nmap \ |
| 25 | + rrdtool \ |
| 26 | + snmp \ |
| 27 | + snmpd \ |
| 28 | + whois |
| 29 | +msg_ok "Installed Dependencies" |
| 30 | + |
| 31 | +msg_info "Installing Python Dependencies" |
| 32 | +$STD apt install -y \ |
| 33 | + python3-dotenv \ |
| 34 | + python3-pymysql \ |
| 35 | + python3-redis \ |
| 36 | + python3-setuptools \ |
| 37 | + python3-systemd \ |
| 38 | + python3-pip |
| 39 | +msg_ok "Installed Python Dependencies" |
| 40 | + |
| 41 | +PHP_VERSION="8.4" PHP_FPM="YES" PHP_MODULE="gmp,mysql,snmp" setup_php |
| 42 | +setup_mariadb |
| 43 | +setup_composer |
| 44 | +PYTHON_VERSION="3.13" setup_uv |
| 45 | +MARIADB_DB_NAME="librenms" MARIADB_DB_USER="librenms" MARIADB_DB_PASS="$(openssl rand -base64 18 | tr -dc 'a-zA-Z0-9' | head -c13)" setup_mariadb_db |
| 46 | +fetch_and_deploy_gh_release "librenms" "librenms/librenms" |
| 47 | + |
| 48 | +msg_info "Configuring LibreNMS" |
| 49 | +$STD useradd librenms -d /opt/librenms -M -r -s "$(which bash)" |
| 50 | +mkdir -p /opt/librenms/{rrd,logs,bootstrap/cache,storage,html} |
| 51 | +cd /opt/librenms |
| 52 | +APP_KEY=$(openssl rand -base64 40 | tr -dc 'a-zA-Z0-9') |
| 53 | +$STD uv venv .venv |
| 54 | +$STD source .venv/bin/activate |
| 55 | +$STD uv pip install -r requirements.txt |
| 56 | +cat <<EOF >/opt/librenms/.env |
| 57 | +DB_DATABASE=${MARIADB_DB_NAME} |
| 58 | +DB_USERNAME=${MARIADB_DB_USER} |
| 59 | +DB_PASSWORD=${MARIADB_DB_PASS} |
| 60 | +APP_KEY=${APP_KEY} |
| 61 | +EOF |
| 62 | +chown -R librenms:librenms /opt/librenms |
| 63 | +chmod 771 /opt/librenms |
| 64 | +chmod -R ug=rwX /opt/librenms/bootstrap/cache /opt/librenms/storage /opt/librenms/logs /opt/librenms/rrd |
| 65 | +msg_ok "Configured LibreNMS" |
| 66 | + |
| 67 | +msg_info "Configure MariaDB" |
| 68 | +sed -i "/\[mysqld\]/a innodb_file_per_table=1\nlower_case_table_names=0" /etc/mysql/mariadb.conf.d/50-server.cnf |
| 69 | +systemctl enable -q --now mariadb |
| 70 | +msg_ok "Configured MariaDB" |
| 71 | + |
| 72 | +msg_info "Configure PHP-FPM" |
| 73 | +cp /etc/php/8.4/fpm/pool.d/www.conf /etc/php/8.4/fpm/pool.d/librenms.conf |
| 74 | +sed -i "s/\[www\]/\[librenms\]/g" /etc/php/8.4/fpm/pool.d/librenms.conf |
| 75 | +sed -i "s/user = www-data/user = librenms/g" /etc/php/8.4/fpm/pool.d/librenms.conf |
| 76 | +sed -i "s/group = www-data/group = librenms/g" /etc/php/8.4/fpm/pool.d/librenms.conf |
| 77 | +sed -i "s/listen = \/run\/php\/php8.4-fpm.sock/listen = \/run\/php-fpm-librenms.sock/g" /etc/php/8.4/fpm/pool.d/librenms.conf |
| 78 | +msg_ok "Configured PHP-FPM" |
| 79 | + |
| 80 | +msg_info "Configure Nginx" |
| 81 | +IP_ADDR=$(hostname -I | awk '{print $1}') |
| 82 | +cat >/etc/nginx/sites-enabled/librenms <<'EOF' |
| 83 | +server { |
| 84 | + listen 80; |
| 85 | + server_name ${IP_ADDR}; |
| 86 | + root /opt/librenms/html; |
| 87 | + index index.php; |
| 88 | +
|
| 89 | + charset utf-8; |
| 90 | + gzip on; |
| 91 | + 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; |
| 92 | + location / { |
| 93 | + try_files $uri $uri/ /index.php?$query_string; |
| 94 | + } |
| 95 | + location ~ [^/]\.php(/|$) { |
| 96 | + fastcgi_pass unix:/run/php-fpm-librenms.sock; |
| 97 | + fastcgi_split_path_info ^(.+\.php)(/.+)$; |
| 98 | + include fastcgi.conf; |
| 99 | + } |
| 100 | + location ~ /\.(?!well-known).* { |
| 101 | + deny all; |
| 102 | + } |
| 103 | +} |
| 104 | +EOF |
| 105 | +rm /etc/nginx/sites-enabled/default |
| 106 | +$STD systemctl reload nginx |
| 107 | +systemctl restart php8.4-fpm |
| 108 | +msg_ok "Configured Nginx" |
| 109 | + |
| 110 | +msg_info "Configure Services" |
| 111 | +ln -s /opt/librenms/lnms /usr/bin/lnms |
| 112 | +mkdir -p /etc/bash_completion.d/ |
| 113 | +cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/ |
| 114 | +cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf |
| 115 | + |
| 116 | +$STD su - librenms -s /bin/bash -c "cd /opt/librenms && COMPOSER_ALLOW_SUPERUSER=1 composer install --no-dev" |
| 117 | +$STD su - librenms -s /bin/bash -c "cd /opt/librenms && php8.4 artisan migrate --force" |
| 118 | +$STD su - librenms -s /bin/bash -c "cd /opt/librenms && php8.4 artisan key:generate --force" |
| 119 | +$STD su - librenms -s /bin/bash -c "cd /opt/librenms && lnms db:seed --force" |
| 120 | +$STD su - librenms -s /bin/bash -c "cd /opt/librenms && lnms user:add -p admin -r admin admin" |
| 121 | + |
| 122 | +RANDOM_STRING=$(openssl rand -base64 16 | tr -dc 'a-zA-Z0-9') |
| 123 | +sed -i "s/RANDOMSTRINGHERE/$RANDOM_STRING/g" /etc/snmp/snmpd.conf |
| 124 | +echo "SNMP Community String: $RANDOM_STRING" >>~/librenms.creds |
| 125 | +curl -qso /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro |
| 126 | +chmod +x /usr/bin/distro |
| 127 | +systemctl enable -q --now snmpd |
| 128 | + |
| 129 | +cp /opt/librenms/dist/librenms.cron /etc/cron.d/librenms |
| 130 | +cp /opt/librenms/dist/librenms-scheduler.service /opt/librenms/dist/librenms-scheduler.timer /etc/systemd/system/ |
| 131 | + |
| 132 | +systemctl enable -q --now librenms-scheduler.timer |
| 133 | +cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms |
| 134 | +msg_ok "Configured Services" |
| 135 | + |
| 136 | +motd_ssh |
| 137 | +customize |
| 138 | +cleanup_lxc |
0 commit comments