Skip to main content

LibreNMS架設 - Ubuntu 20

安裝環境

  • pvePVE
  • lxcLXC
  • ubuntuUbuntu 20

設定時區

timedatectl set-timezone Asia/Taipei

最新LibreNMS已強制要求>php8.1

apt update
apt install software-properties-common
add-apt-repository universe
apt install php-mbstring php8.1-cli php8.1-common php8.1-curl php8.1-fpm php8.1-gd php8.1-mbstring php8.1-mysql php8.1-opcache php8.1-readline php8.1-snmp php8.1-xml php8.1-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

php-mbstring未安裝會造成500 ERROR

Add librenms user

useradd librenms -d /opt/librenms -M -r -s "$(which bash)"

 

Download LibreNMS

cd /opt
git clone https://github.com/librenms/librenms.git

 

Set permissions

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/

 

更改時區

nano /etc/php/8.1/fpm/php.ini
nano /etc/php/8.1/cli/php.ini

搜尋[Date] 把時區改為 Asia/Taipei

修改MariaDB

nano /etc/mysql/mariadb.conf.d/50-server.cnf

Within the [mysqld] section add:
innodb_file_per_table=1
lower_case_table_names=0
systemctl enable mariadb
systemctl restart mariadb
mysql -u root

CREATE USER 'librenmsuser'@'localhost' IDENTIFIED BY 'librenmsuserpswd';
GRANT ALL PRIVILEGES ON librenms.* TO 'librenmsuser'@'localhost';
FLUSH PRIVILEGES;
exit

修改PHP-FPM

cp /etc/php/8.1/fpm/pool.d/www.conf /etc/php/8.1/fpm/pool.d/librenms.conf
nano /etc/php/8.1/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

Configure Web Server

建立librenms.conf

nano /etc/nginx/conf.d/librenms.conf

server {
 listen      80;
 server_name 127.0.0.1;
 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;
 }
}
rm /etc/nginx/sites-enabled/default
rm /etc/nginx/sites-available/default

systemctl restart nginx
systemctl restart php8.1-fpm

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

Cron job

cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms

Copy logrotate config

cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms