LibreNMS

Bash
apk add \
  lsb-release ca-certificates wget acl curl fping git graphviz imagemagick \
  mariadb-client mariadb mariadb-openrc \
  mtr nginx \
  nmap \
  php83 php83-cli php83-curl php83-phar php83-fpm php83-gd php83-gmp php83-mbstring \
  php83-mysqli php83-snmp php83-xml php83-zip \
  py3-dotenv py3-pymysql py3-redis py3-setuptools py3-pip \
  rrdtool net-snmp net-snmp-tools \
  unzip whois
Bash
1
2
3
4
5
6
7
8
9
apk add \
  php83-pdo php83-pdo_mysql \
  php83-session \
  php83-simplexml php83-xml php83-dom \
  php83-sockets \
  php83-fileinfo \
  php83-tokenizer \
  php83-iconv \
  php83-posix
Bash
addgroup librenms
adduser -D -h /opt/librenms -G librenms -s /bin/ash librenms
Bash
cd /opt
git clone https://github.com/librenms/librenms.git
Bash
1
2
3
4
5
chown -R librenms:librenms /opt/librenms
chmod 771 /opt/librenms
apk add acl
setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache /opt/librenms/storage
setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache /opt/librenms/storage
Bash
1
2
3
4
5
apk add composer
apk add util-linux-misc
apk add --no-cache --virtual .py-build gcc musl-dev python3-dev linux-headers make
apk add py3-dotenv py3-pymysql py3-redis py3-psutil
apk add bash
Bash
su - librenms
Bash
1
2
3
4
python3 -m venv --system-site-packages ~/venv
. ~/venv/bin/activate
pip install --upgrade pip
pip3 install -r ./requirements.txt
Bash
./scripts/composer_wrapper.php install --no-dev
Bash
nano .env
Text Only
SESSION_SECURE_COOKIE=true
APP_URL=https://librenms.gridtelecom.fr
Bash
nano .profile
Text Only
1
2
3
4
5
6
7
8
9
# Active automatiquement l'environnement virtuel Python de LibreNMS

if [ -f /opt/librenms/venv/bin/activate ]; then
    . /opt/librenms/venv/bin/activate
fi

# Éditeur par défaut

export EDITOR=nano
Bash
1
2
3
exit
su - librenms
crontab -e

/! Changer 16 par nombre de coeurs x2 /!\

Text Only
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# min   hour    day     month   weekday command

# Scheduler (PHP) – chaque minute
*       *       *       *       *       php /opt/librenms/artisan schedule:run --no-ansi --no-interaction > /dev/null 2>&1

33      */6     *       *       *       /opt/librenms/cronic /opt/librenms/discovery-wrapper.py 1
*/5     *       *       *       *       /opt/librenms/discovery.php -h new >> /dev/null 2>&1

*       *       *       *       *       /opt/librenms/cronic /opt/librenms/poller-wrapper.py 16
*       *       *       *       *       /opt/librenms/alerts.php >> /dev/null 2>&1

*/5     *       *       *       *       /opt/librenms/poll-billing.php >> /dev/null 2>&1
01      *       *       *       *       /opt/librenms/billing-calculate.php >> /dev/null 2>&1
*/5     *       *       *       *       /opt/librenms/check-services.php >> /dev/null 2>&1

# Daily maintenance script. DO NOT DISABLE!
# If you want to modify updates:
#  Switch to monthly stable release: https://docs.librenms.org/General/Releases/
#  Disable updates: https://docs.librenms.org/General/Updating/
19      0       *       *       *       /opt/librenms/daily.sh >> /dev/null 2>&1

# Fast Ping
*       *       *       *       *       /opt/librenms/ping.php >> /dev/null 2>&1
*       *       *       *       *       sleep 30 && /opt/librenms/ping.php >> /dev/null 2>&1
*       *       *       *       *       sleep 15 && /opt/librenms/alerts.php >> /dev/null 2>&1
*       *       *       *       *       sleep 45 && /opt/librenms/alerts.php >> /dev/null 2>&1
Bash
exit
Bash
apk del .py-build
Bash
nano /etc/php83/php.ini

modifier date.timezone

Bash
curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
chmod +x /usr/bin/distro
Bash
nano /etc/my.cnf.d/mariadb-server.cnf

Sous la section [mysqld] ajouter :

Text Only
1
2
3
4
5
6
innodb_file_per_table=1
lower_case_table_names=0
bind-address=127.0.0.1
port=3306
skip-networking=0
innodb_flush_log_at_trx_commit = 0
Bash
1
2
3
4
rc-service mariadb setup
rc-service mariadb start
rc-update add mariadb default
mysql_secure_installation
Bash
mysql -u root -p
SQL
1
2
3
4
5
CREATE USER 'librenms'@'localhost' IDENTIFIED BY '';
CREATE DATABASE IF NOT EXISTS librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
FLUSH PRIVILEGES;
QUIT;
Bash
cp /etc/php83/php-fpm.d/www.conf /etc/php83/php-fpm.d/librenms.conf
nano /etc/php83/php-fpm.d/librenms.conf

Modifier :

Text Only
[librenms]

; --- ajout pour les modules Python LibreNMS ---
env[PATH] = /opt/librenms/venv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
env[VIRTUAL_ENV] = /opt/librenms/venv

user = librenms
group = librenms

listen = /run/php-fpm-librenms.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
Bash
rm /etc/php83/php-fpm.d/www.conf
rc-service php-fpm83 restart
Bash
1
2
3
apk add nginx
mv /etc/nginx/http.d/default.conf /etc/nginx/http.d/default.conf.old
nano /etc/nginx/http.d/librenms.conf
Text Only
server {
    listen      80;
    server_name librenms.gridtelecom.fr;
    root        /opt/librenms/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;
    }
}
Bash
1
2
3
4
ln -s /opt/librenms/lnms /usr/bin/lnms
cp /opt/librenms/config.php.default /opt/librenms/config.php
cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
nano /etc/snmp/snmpd.conf
Text Only
1
2
3
4
5
6
7
8
# Crée un utilisateur SNMPv3 (change les mots de passe)
createUser librenms SHA "authPassword" AES "privPassword"

# Autorise cet utilisateur en lecture (utilisé par LibreNMS)
rouser librenms authPriv

# Fait écouter le démon sur toutes les interfaces IPv4 et IPv6
agentAddress udp:161,udp6:161
Bash
nano /opt/librenms/config.php

Décommenter : $config['user'] = 'librenms';

Ajouter :

Text Only
#https://community.librenms.org/t/poller-not-running-from-cron/12236/4
$config['db_socket'] = '/var/run/mysqld/mysqld.sock';
Bash
cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
Bash
chown -R librenms:librenms /opt/librenms
Bash
1
2
3
4
rc-service mariadb restart
rc-service php-fpm83 restart
rc-service nginx start
rc-service snmpd start
Bash
1
2
3
4
rc-update add mariadb
rc-update add php-fpm83
rc-update add nginx
rc-update add snmpd

INSTALLATION WEB puis

Bash
1
2
3
4
5
6
7
8
su - librenms
lnms config:set base_url https://librenms.gridtelecom.fr
lnms config:set fping_options.timeout 200
lnms config:set fping_options.count 1
lnms config:set fping_options.interval 200
lnms config:set ping_rrd_step 30
./scripts/rrdstep.php -h all
exit

TUNING

Bash
apk add rrdtool-cached
Bash
1
2
3
4
5
6
# dossiers RRD LibreNMS & journal rrdcached
install -o librenms -g librenms -d /opt/librenms/rrd
install -o librenms -g librenms -d /var/lib/rrdcached/journal

# dossier runtime pour le PID + socket
install -o librenms -g librenms -m 0770 -d /run/rrdcached
Bash
rc-service rrdcached stop

# PID + socket sous /run/rrdcached/
sed -i 's#^pidfile=.*#pidfile=${pidfile:-/run/rrdcached/rrdcached.pid}#' /etc/init.d/rrdcached
sed -i 's#^socket=.*#socket=${socket:-unix:/run/rrdcached/rrdcached.sock}#' /etc/init.d/rrdcached

# Arguments: base LibreNMS + journal + droits + pidfile (on garde -F -B)
sed -i 's#^command_args=.*#command_args="-l $socket -j /var/lib/rrdcached/journal -F -b /opt/librenms/rrd -B -p $pidfile -s librenms -m 0660"#' /etc/init.d/rrdcached

# Lancer en librenms:librenms
grep -q '^command_user=' /etc/init.d/rrdcached || sed -i '/^command="\/usr\/sbin\/rrdcached"/a command_user="librenms:librenms"' /etc/init.d/rrdcached
Bash
nano /etc/init.d/rrdcached

Ajoute ceci dans pre start

Text Only
install -o librenms -g librenms -m 0770 -d /run/rrdcached
Bash
rc-service rrdcached start
rc-update add rrdcached
Bash
su - librenms
Bash
lnms config:get rrdtool_version
Bash
lnms config:set rrdtool_version 'X.X.X'
lnms config:set rrdcached "unix:/run/rrdcached/rrdcached.sock"
Bash
exit

TEST

Bash
1
2
3
wget https://raw.githubusercontent.com/librenms/librenms-agent/master/agent-local/rrdcached -O /etc/snmp/rrdcached
chmod +x /etc/snmp/rrdcached
nano /etc/snmp/snmpd.conf

Ajouter :

Text Only
extend rrdcached /etc/snmp/rrdcached
Bash
nano /etc/snmp/rrdcached

Modifier

Text Only
1
2
3
"/var/run/rrdcached.sock"
par
"/run/rrdcached/rrdcached.sock"
Bash
rc-service snmpd restart

Opcache

Bash
apk add php83-opcache
Bash
1
2
3
mkdir -p /var/cache/librenms/php-opcache
chown librenms:librenms /var/cache/librenms/php-opcache
chmod 775 /var/cache/librenms/php-opcache
Bash
nano /etc/php83/conf.d/90-librenms-opcache.ini
Text Only
; ---- OPcache (commun) ----
opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=20000
opcache.validate_timestamps=1
opcache.revalidate_freq=2
opcache.fast_shutdown=1

; ---- Pour le CLI (pollers) ----
opcache.enable_cli=1
opcache.file_cache=/var/cache/librenms/php-opcache
opcache.file_cache_only=0
opcache.file_cache_consistency_checks=1
Bash
rc-service php-fpm83 restart

Pour vérifier :

Bash
php -v | head -1
php -i | grep -iE 'opcache\.enable(_cli)?|file_cache'

GRID

Changer des boutons :

Bash
1
2
3
4
su - librenms
lnms config:set html.device.links.+ '{"url": "https://{{ $device->hostname }}:65443", "title": "Administration", "icon": "fa-external-link", "action": true}'
lnms config:set html.device.primary_link custom1
exit