LibreNMS架設 - Debian 12
運行環境
- PVE
- LXC
- Debian 12
安裝nginx mariadb php
apt update
apt install php-mbstring php-cli php-common php-curl php-fpm php-gd php-mbstring php-mysql php-opcache php-readline php-snmp php-xml php-zip acl curl fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap rrdtool snmp snmpd whois unzip python3-pymysql python3-dotenv python3-redis python3-setuptools python3-systemd python3-pip -y
安裝 Composer
cd /usr/local/bin
curl -sS https://getcomposer.org/installer | php
mv composer.phar composer
新增使用者
useradd librenms -d /opt/librenms -M -r -s "$(which bash)"
下載LibreNMS
cd /opt && \
git clone https://github.com/librenms/librenms.git
設定權限
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/
安裝 LibreNMS和套件
su librenms
cd /opt/librenms/
./scripts/composer_wrapper.php install --no-dev
exit
pip3 install --user --break-system-packages -r /opt/librenms/requirements.txt
修改PHP時區
sed -i "s|^;date.timezone =.*$|date.timezone = Asia/Taipei|" /etc/php/8.2/fpm/php.ini
sed -i "s|^;date.timezone =.*$|date.timezone = Asia/Taipei|" /etc/php/8.2/cli/php.ini
系統設定時區
timedatectl set-timezone Asia/Taipei
設定 PHP-FPM
cp /etc/php/8.2/fpm/pool.d/www.conf /etc/php/8.2/fpm/pool.d/librenms.conf
nano /etc/php/8.2/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
systemctl enable php8.2-fpm
systemctl restart php8.2-fpm
設定MariaDB
編輯/etc/mysql/mariadb.conf.d/50-server.cnf
[mysqld]底下新增
innodb_file_per_table=1
lower_case_table_names=0
systemctl enable mariadb
systemctl restart mariadb
MariaDB新增使用者
mysql -u root
CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'librenmsuser'@'localhost' IDENTIFIED BY 'librenmspswd';
GRANT ALL PRIVILEGES ON librenms.* TO 'librenmsuser'@'localhost';
FLUSH PRIVILEGES;
exit
設定Nginx
建立/etc/nginx/conf.d/librenms.conf
server {
listen 80;
server_name librenms.example.com;
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_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/run/php-fpm-librenms.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
rm /etc/nginx/sites-enabled/default
rm /etc/nginx/sites-available/default
systemctl enable nginx
systemctl restart nginx
Enable lnms command completion
ln -s /opt/librenms/lnms /usr/bin/lnms
cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/
Configure snmpd
cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
chmod +x /usr/bin/distro
systemctl enable snmpd
systemctl restart snmpd
設定排成
cp /opt/librenms/dist/librenms.cron /etc/cron.d/librenms
啟用調度程式
cp /opt/librenms/dist/librenms-scheduler.service /opt/librenms/dist/librenms-scheduler.timer /etc/systemd/system/
systemctl enable librenms-scheduler.timer
systemctl start librenms-scheduler.timer
Copy logrotate config
cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
瀏覽器http://ip,依序安裝後進行組態驗證
cd /opt/librenms
su librenms
./validate.php
更新PHP8.5
Debian 12官方套件只有到PHP8.2,加入第三方 PPA 來源來升級PHP
apt update
apt-get -y install lsb-release ca-certificates curl apt-transport-https
curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
dpkg -i /tmp/debsuryorg-archive-keyring.deb
sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
apt update
自動查詢PHP 8.2套件並安裝對應的 PHP 8.5 套件,php8.5-opcache 已經被直接內建在 php8.5-common 核心套件中故排除即可
apt install -y $(dpkg -l | grep php8.2- | grep -v 'opcache' | awk '{print $2}' | sed 's/php8.2/php8.5/g')
切換系統預設 CLI 版本到 8.5,輸入8.5對應編號1
update-alternatives --config php
root@librenms:~# update-alternatives --config php
There is 1 choice for the alternative php (providing /usr/bin/php).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/php8.5 85 auto mode
* 1 /usr/bin/php8.5 85 manual mode
確認版本
root@librenms:~# php -v
PHP 8.5.12 (cli) (built: Oct 21 2026 08:08:59) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.5.12, Copyright (c) Zend Technologies
with Zend OPcache v8.5.12, Copyright (c), by Zend Technologies
修改時區
sed -i "s|^;date.timezone =.*$|date.timezone = Asia/Taipei|" /etc/php/8.5/fpm/php.ini
sed -i "s|^;date.timezone =.*$|date.timezone = Asia/Taipei|" /etc/php/8.5/cli/php.ini
系統設定時區
timedatectl set-timezone Asia/Taipei
修改PHP-FPM
cp /etc/php/8.5/fpm/pool.d/www.conf /etc/php/8.5/fpm/pool.d/librenms.conf
nano /etc/php/8.5/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
systemctl enable php8.5-fpm
systemctl restart php8.5-fpm
systemctl restart nginx
確認PHP為8.5
完整移除舊版本
apt purge php8.2 php8.2-*
apt autoremove --purge
