• 安裝必要的套件

    apt install software-properties-common
    add-apt-repository universe
    apt update
    apt install acl curl composer fping git graphviz imagemagick mailutils mariadb-client mariadb-server mtr-tiny nginx-full nmap php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-json php7.4-mbstring php7.4-mysql php7.4-snmp php7.4-xml php7.4-zip rrdtool snmp snmpd whois unzip python3-pip python3-pymysql python3-dotenv python3-redis python3-setuptools python3-systemd

  • 新增 librenms 帳號

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

  • 下載 LibreNMS 系統

    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/

  • 安裝 PHP 相關套件

    su - librenms
    ./scripts/composer_wrapper.php install --no-dev
    exit

  • 安裝 php composer

    wget https://getcomposer.org/composer-stable.phar
    mv composer-stable.phar /usr/bin/composer
    chmod +x /usr/bin/composer

  • 設定時區資料

    vi /etc/php/7.4/fpm/php.ini
    vi /etc/php/7.4/cli/php.ini

    :
    date.timezone = "Asia/Taipei"
    :
    timedatectl set-timezone Asia/Taipei
  • 設定 MariaDB

    vi /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

  • 修改 DB 密碼 Password

    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

  • 設定 PHP-FPM

    cp /etc/php/7.4/fpm/pool.d/www.conf /etc/php/7.4/fpm/pool.d/librenms.conf
    vi /etc/php/7.4/fpm/pool.d/librenms.conf

    1. 將 [www] 改成 [librenms]
    2. 將 user 和 group 改成 “librenms”

      user = librenms
      group = librenms

    3. 將 listen 改成 /run/php-fpm-librenms.sock

      listen = /run/php-fpm-librenms.sock

  • 設定 Nginx 改 server_name 為實際的網址或 IP Exp. 10.20.0.34

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

    server {
     listen      80;
     server_name 10.20.0.34;
     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;
     }
    }
    • 重新啟動 nginx

      rm /etc/nginx/sites-enabled/default
      systemctl restart nginx
      systemctl restart php7.4-fpm

  • 啟動 lnms

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

  • 設定 snmpd

    cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf
    vi /etc/snmp/snmpd.conf
    ---
    將 RANDOMSTRINGGOESHERE 改成自己的 snmp 密碼
    com2sec readonly  default         RANDOMSTRINGGOESHERE
    :
    --
    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

  • 設定 crontab

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

  • 設定 logrotate

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

  • 開啟網頁進行設定 Exp. http://10.20.0.34
    1. 檢查設定
    2. 設定資料庫與匯入基本資料
    3. 建立管理者帳號密碼
  • 如果有遇到問題可以執行以下語法進行檢測

    sudo su - librenms
    ./validate.php

    如果沒問題會顯示類似如下結果:

    root@ct-librenms:/opt# sudo su - librenms
    librenms@ct-librenms:~$ ./validate.php
    ====================================
    Component | Version
    --------- | -------
    LibreNMS  | 21.4.0-3-gcea6f13bf
    DB Schema | 2021_04_08_151101_add_foreign_keys_to_port_group_port_table (208)
    PHP       | 7.4.3
    Python    | 3.8.5
    MySQL     | 10.3.25-MariaDB-0ubuntu0.20.04.1
    RRDTool   | 1.7.2
    SNMP      | NET-SNMP 5.8
    ====================================
    
    [OK]    Composer Version: 2.0.12
    [OK]    Dependencies up-to-date.
    [WARN]  You have no devices.
            [FIX]: 
            Consider adding a device such as localhost: /addhost
    [OK]    Database connection successful
    [OK]    Database schema correct
    librenms@ct-librenms:~$ 

  • tech/librenms/ubuntu20_04.txt
  • 上一次變更: 2022/01/13 23:36
  • jonathan