B i M A P

LibreNMS|Quick install in 5 minutes (NGINX) 最新版

LibreNMS 是一套開源的網路與服務監控系統,在安裝過程中,常常一個不注意就安裝失敗,就讓 ELK 達人帶領各位一起簡單安裝不踩雷!

ELK 達人是使用 VMware 架設 Ubuntu 20.04 LTS,準備好,就跟著 ELK 達人一起安裝 Let's GO~!


Install Required Packages

$ sudo apt install acl curl fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nginx-full nmap php-cli php-curl php-fpm php-gd php-gmp php-json php-mbstring php-mysql php-snmp php-xml php-zip rrdtool snmp snmpd whois unzip python3-pymysql python3-dotenv python3-redis python3-setuptools python3-systemd python3-pip

Add Librenms User

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

Download LibreNMS

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

Set Permissions

$ sudo chown -R librenms:librenms /opt/librenms
$ sudo chmod 771 /opt/librenms
$ sudo setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/
$ sudo setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/

Install PHP dependencies

注意 須分開 單行執行!

$ sudo su - librenms
> ./scripts/composer_wrapper.php install --no-dev
> exit
$ sudo wget https://getcomposer.org/composer-stable.phar
$ sudo mv composer-stable.phar /usr/bin/composer
$ sudo chmod +x /usr/bin/composer

Set Timezone

$ sudo vim /etc/php/8.1/fpm/php.ini
$ sudo vim /etc/php/8.1/cli/php.ini

尋找關鍵字 date.timezone = "Asia/Taipei" 註解要記得拿掉!

$ sudo timedatectl set-timezone Asia/Taipei

Configure MariaDB

$ sudo vim /etc/mysql/mariadb.conf.d/50-server.cnf
Within the [mysqld] section add:

innodb_file_per_table=1
lower_case_table_names=0
$ sudo systemctl enable mariadb
$ sudo systemctl restart mariadb
$ sudo mysql -u root

> CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
> CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'password';
> GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
> FLUSH PRIVILEGES;
> exit

Configure PHP-FPM

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

$ sudo vim /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_pass unix:/run/php-fpm-librenms.sock;
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  include fastcgi.conf;
 }
 location ~ /\.(?!well-known).* {
  deny all;
 }
}
$ sudo rm -rf /etc/nginx/sites-enabled/default
$ sudo systemctl restart nginx
$ sudo systemctl restart php8.1-fpm

Enable lnms command completion

$ sudo ln -s /opt/librenms/lnms /usr/bin/lnms
$ sudo cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/

Configure snmpd

$ sudo cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
$ sudo vim /etc/snmp/snmpd.conf

RANDOMSTRINGGOESHERE 修改成 SNMP community

$ sudo curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro
$ sudo chmod +x /usr/bin/distro
$ sudo systemctl enable snmpd
$ sudo systemctl restart snmpd

Cron job

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

Copy logrotate config

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

Web installer

http://IP/install

librenms

librenms

Password 是建立 mysql 時的密碼。

librenms

librenms

可以自行設置登入時的帳號密碼。


Troubleshooting

sudo su - librenms
./validate.php

Tell LibreNMS to add duplicate devices

$ sudo vim /opt/librenms/config.php

Add

$config['allow_duplicate_sysName'] = true;
延伸閱讀
ginachen的大頭照
ELK小幫手

使用 ELK 協助企業維運、建置相關服務! 同時提供 ELK 教育訓練,提供私人或企業報名受訓,歡迎加入 Bimap 官方 Line,或來信諮詢 ELK 相關課程,更多 ELK 客製化方案, ELK 小幫手期待與您面對面的機會。