LibreNMS Deployment for Network Monitoring - 夜莺博客

LibreNMS Deployment for Network Monitoring

LibreNMS is the pragmatic middle ground in network monitoring: it discovers devices automatically, understands vendor MIBs well enough to draw real interface graphs, and runs alert rules against the data it collects — all from a LAMP-style stack you can host on a single VM to start. The failure mode it avoids is the one that kills homegrown monitoring: polling that silently falls behind and leaves gaps in graphs exactly when you need them. This guide covers installation, discovery and polling architecture, alert rules worth having on day one, and the scaling steps that keep a large estate monitored without dropping samples.

Install and initialise

# validated on Ubuntu 22.04/24.04
sudo apt install -y mariadb-server nginx php-fpm php-mysql php-cli php-curl \
  php-gd php-mbstring php-xml php-zip php-snmp php-gmp php-bcmath snmp git curl

sudo mysql -e "CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  CREATE USER 'librenms'@'localhost' IDENTIFIED BY '<db-password>';
  GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost'; FLUSH PRIVILEGES;"

# recommended tuning for the DB
# innodb_file_per_table=1, innodb_buffer_pool_size = 50-70% of RAM

git clone https://github.com/librenms/librenms.git /opt/librenms
cd /opt/librenms && composer install --no-dev
./scripts/composer_wrapper.php install --no-dev
cp .env.example .env && php artisan key:generate
php lnms migrate
php lnms user:add admin -r admin -p '<web-password>'
./validate.php

Run validate.php until it reports no failures. It catches file permissions, PHP extensions and cron problems that otherwise show up as missing graphs days later.

Discovery, polling and the cron model

# discover a subnet range
php lnms device:add 10.20.0.1 --v2c=public

# bulk discovery from a file of addresses
seq 1 254 | sed 's/^/10.20.0./' > /tmp/hosts.txt
/opt/librenms/discovery.php -h all      # discovers everything already added
/opt/librenms/addhost.php /tmp/hosts.txt v2c public   # add a list

# poll manually to verify before cron takes over
/opt/librenms/poller.php -h 10.20.0.1 -m ports,processors,mem
# /etc/cron.d/librenms
*/5 * * * * librenms /opt/librenms/cronic /opt/librenms/discovery-wrapper.py 1
*/5 * * * * librenms /opt/librenms/cronic /opt/librenms/discovery-wrapper.py 16
*/1 * * * * librenms /opt/librenms/cronic /opt/librenms/poller-wrapper.py 16
*/5 * * * * librenms /opt/librenms/cronic /opt/librenms/check-services.php

The poller wrapper is the single most important scaling knob: poller-wrapper.py N runs N parallel worker processes. Too few and polling slips beyond five minutes; too many and the database becomes the bottleneck. Watch pollers in the web UI — the target is that a polling cycle finishes well within the 300-second interval with headroom for a slow device.

SNMP right the first time

# SNMPv3 on a Cisco switch
snmp-server group NMS v3 priv
snmp-server user librenms NMS v3 auth sha <auth-pass> priv aes 128 <priv-pass>
snmp-server host 10.20.0.50 version 3 priv librenms

# test with the same credentials LibreNMS will use
snmpget -v3 -l authPriv -u librenms -a SHA -A '<auth-pass>' -x AES -X '<priv-pass>' \
  10.20.0.1 1.3.6.1.2.1.1.5.0
snmpwalk -v3 -l authPriv -u librenms -a SHA -A '<auth-pass>' -x AES -X '<priv-pass>' \
  10.20.0.1 1.3.6.1.2.1.2.2.1.2 | head

Prefer SNMPv3 with authentication and privacy everywhere; v2c community strings leak through interface configuration dumps and monitoring itself. The variable-name walk before adding a device saves a wasted discovery cycle, and it confirms OID visibility that ACLs sometimes restrict. The security levels behind v3 are explained in the SNMPv3 security levels guide.

Alert rules with real operational value

# example: interface down on an uplink, ignoring admin-down ports
SELECT * FROM devices,ports
WHERE devices.device_id = ports.device_id
  AND ports.ifOperStatus = 'down'
  AND ports.ifAdminStatus = 'up'
  AND ports.ifAlias LIKE '%UPLINK%'
  AND (devices.status = 1 AND devices.disabled = 0);

# example: interface utilisation above 80% for 15 minutes
SELECT * FROM ports
WHERE ports.ifOperStatus = 'up'
  AND (ports.ifInOctets_rate * 8) / ports.ifSpeed > 0.8;

# example: device unreachable
SELECT * FROM devices WHERE status = 0 AND disabled = 0;

Start with four rule families and add nothing else until they are tuned: device down, uplink down, interface utilisation, and CPU or memory sustained above threshold. Use interface ifAlias descriptions as the contract for what matters — a rule that fires on every access port trains the team to ignore alerts, which is worse than no alerting at all. Alerts can be delivered by email, webhook, Slack or as SNMP traps; the same notification design considerations as the Prometheus Alertmanager routing apply, including quiet hours and grouping.

Scaling and performance

# check poller health and queue
php lnms poller:list
mysql -e "SELECT * FROM pollers ORDER BY poller_time DESC LIMIT 10" librenms
mysql -e "SELECT COUNT(*) FROM ports WHERE deleted = 0" librenms
mysql -e "SELECT device_id, COUNT(*) FROM ports GROUP BY device_id ORDER BY 2 DESC LIMIT 10" librenms

# redis for distributed polling and caching
sudo apt install redis-server
# .env: REDIS_HOST=127.0.0.1, CACHE_DRIVER=redis, SESSION_DRIVER=redis
  • Add a distributed poller when one host's CPU is saturated; LibreNMS supports multiple pollers with Redis coordinating device allocation.
  • Reduce per-device overhead by polling only the modules you use: disable unused module sets per device or per OS group to cut SNMP walks dramatically.
  • Keep the database on local NVMe with enough buffer pool; interface rate data writes are the dominant load.
  • Set sensible retention on the RRD or timescale backend — two years of per-minute interface data is rarely necessary for every access port, but it is essential for uplinks.
  • Alert on the monitoring system itself: if poller cycles lengthen past four minutes, that is a page-worthy event, because gaps begin immediately.

Verification

./validate.php
php lnms device:list | head
mysql -e "SELECT hostname,status,last_polled FROM devices ORDER BY last_polled DESC LIMIT 5" librenms
ls -la /opt/librenms/rrd/ | head
curl -s http://librenms.example.com/api/v0/devices -H "X-Auth-Token: <api-token>" | jq '.devices | length'

A healthy install shows every device polled within the last five minutes, RRD files growing per port, and the API returning the full device list. For switches that LibreNMS cannot fully identify, confirm the OS definition and MIB support match the platform — the same device-level checks described for Zabbix SNMP monitoring resolve most of those cases, and if you want interface graphs inside an existing Prometheus stack, the SNMP exporter approach is an alternative to adding a second NMS.

原文链接:https://docs.librenms.org/Installation/Install-LibreNMS/