2024年1月23日 星期二

librenms on Ubuntu 22.04 安裝手冊

ubuntu22.04 with php8.1 with nginx 安裝過程

參考文件

https://docs.librenms.org/Installation/Install-LibreNMS/

安裝package

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 unzip python3-pymysql python3-dotenv python3-redis python3-setuptools python3-systemd python3-pip whois traceroute

新增 librenms user

sudo useradd librenms -d /home/librenms -M -r -s “$(which bash)”

下載 librenms from git

cd /home

sudo git clone https://github.com/librenms/librenms.git

設定權限

sudo chown -R librenms:librenms /home/librenms

sudo chmod 771 /home/librenms

sudo setfacl -d -m g::rwx /home/librenms/rrd /home/librenms/logs /home/librenms/bootstrap/cache/ /home/librenms/storage/

sudo setfacl -R -m g::rwx /home/librenms/rrd /home/librenms/logs /home/librenms/bootstrap/cache/ /home/librenms/storage/

安裝 php 相依

sudo su - librenms

./scripts/composer_wrapper.php install —no-dev

exit

設定時區

sudo vi /etc/php/8.1/fpm/php.ini
sudo vi /etc/php/8.1/cli/php.ini

date.timezone = Asia/Taipei

sudo timedatectl set-timezone Asia/Taipei

設定MariaDB

sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf

在[mysqld]下一行加入以下兩行

innodb_file_per_table=1
lower_case_table_names=0

sudo systemctl enable mariadb

sudo systemctl restart mariadb

sudo mysql_secure_installation

sudo mysql -u root

輸入以下SQL Command

CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'librenms'@'localhost' IDENTIFIED BY '[yourpassword]';
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
exit

設定 php-fpm

sudo cp /etc/php/8.1/fpm/pool.d/www.conf /etc/php/8.1/fpm/pool.d/librenms.conf

sudo vi /etc/php/8.1/fpm/pool.d/librenms.conf

[www]改成[librenms]

[librenms]
user = librenms
group = librenms
listen = /run/php-fpm-librenms.sock

設定 web server

sudo vi /etc/nginx/conf.d/librenms.conf

server {
 listen      80;
 server_name [yourdomain or ip];
 root        /home/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 /etc/nginx/sites-enabled/default

sudo systemctl restart nginx

sudo systemctl restart php8.1-fpm

設定lnms

sudo ln -s /home/librenms/lnms /usr/bin/lnms

sudo cp /home/librenms/misc/lnms-completion.bash /etc/bash_completion.d/

設定 snmpd

sudo cp /home/librenms/snmpd.conf.example /etc/snmp/snmpd.conf

sudo vi /etc/snmp/snmpd.conf

找到 RANDOMSTRINGGOESHERE 改成 public(或自已想要的)

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

設定 cronjob

sudo cp /home/librenms/dist/librenms.cron /etc/cron.d/librenms

sudo vi /etc/cron.d/librenms

將所有的路徑裡的資料夾opt改成home

設定scheduler

sudo cp /home/librenms/dist/librenms-scheduler.service /home/librenms/dist/librenms-scheduler.timer /etc/systemd/system/

sudo systemctl enable librenms-scheduler.timer

sudo systemctl start librenms-scheduler.timer

sudo vi /etc/systemd/system/librenms-scheduler.service

將所有的路徑裡的資料夾opt改成home

設定logrotate

sudo cp /home/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms

匯入資料庫

sudo vi /home/librenms/.env

DB_HOST= localhost
DB_DATABASE= librenms
DB_USERNAME= librenms
DB_PASSWORD= [yourpassword]

sudo su - librenms

lnms migrate

php artisan key:generate

php artisan config:clear

php artisan config:cache

exit

web config

http://[yourdomain_or_ip]/

  • 建立管理員帳號

修改config.php權限

sudo chown librenms:librenms /home/librenms/config.php

驗證設定(或問題排除)

sudo su - librenms

cd /home/librenms

./validate.php