LibreNMS
前置要求
- 推荐系统:Ubuntu 22.04 / Debian 12;Rocky 9
- 最低配置(≤10 台设备):2 核 4G SSD;50 台以上建议 4 核 8G,SSD 必选(RRD 频繁读写)
- 端口:UDP 161(SNMP 采集,重点)、TCP 80/443(Web)
- 被监控设备:开启 SNMP v2c(社区字串)或 SNMPv3(推荐,加密安全),放通 LibreNMS 服务器 IP 访问 UDP161
方式 1:Docker Compose(推荐,测试、生产都方便)
version: '3.8'
services:
db:
image: mariadb:10.11
container_name: librenms-db
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: Librenms@2026
MYSQL_DATABASE: librenms
MYSQL_USER: librenms
MYSQL_PASSWORD: Librenms@2026
volumes:
- librenms-db:/var/lib/mysql
command: --innodb-file-per-table=1 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
redis:
image: redis:7-alpine
container_name: librenms-redis
restart: unless-stopped
volumes:
- librenms-redis:/data
librenms:
image: librenms/librenms:latest
container_name: librenms
restart: unless-stopped
depends_on:
- db
- redis
environment:
TZ: Asia/Shanghai
DB_HOST: db
DB_NAME: librenms
DB_USER: librenms
DB_PASSWORD: Librenms@2026
REDIS_HOST: redis
ports:
- "8000:8000"
volumes:
- librenms-data:/data
cap_add:
- NET_RAW
- NET_ADMIN
volumes:
librenms-db:
librenms-redis:
librenms-data:
# 启动
docker compose up -d
# 访问
http://IP:8000
首次打开网页安装向导,创建管理员账号。
方式 2:原生脚本安装(Ubuntu/Debian 生产)
# 安装依赖
apt update && apt install -y acl curl git composer snmp snmpd rrdtool nginx php8.2-fpm mariadb-server redis-server
# 创建librenms用户
useradd -r -M -d /opt/librenms -s /bin/bash librenms
usermod -aG librenms www-data
# 拉取源码
cd /opt
git clone https://github.com/librenms/librenms.git librenms
chown -R librenms:librenms /opt/librenms
chmod 771 /opt/librenms
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
然后配置 Nginx、PHP、数据库,访问 /install 向导完成初始化。
Nginx 配置模板
server {
listen 80;
server_name librenms.example.com;
root /opt/librenms/html;
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /api/v0 {
try_files $uri $uri/ /api_v0.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}
方式 3:Nginx 反向代理 HTTPS
server {
listen 443 ssl;
server_name librenms.example.com;
ssl_certificate cert/librenms.example.com.crt;
ssl_certificate_key cert/librenms.example.com.key;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
}