目錄表

Ubuntu 20.04 / CentOS7 安裝 LibreNMS 程序

如果要以 Docker 方式進行安裝, 可參考 安裝 LibreNMS (Docker)

  • Ubuntu 20.04 安裝程序
  • CentOS7 安裝程序
載入中 ...

Ubuntu 20.04 安裝程序

  • 安裝必要的套件

    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:~$ 

設定自動找尋區域網路內可納管設備

  1. 先安裝 python-ipaddress 模組 yum install python-ipaddress
  2. 先手動加入一個設備進行監管 Exp. 192.168.1.1
  3. vi /opt/librenms/config.php
    :
    # Auto-Discovery
    // v1 or v2c
    $config['snmp']['community'][] = "public";
    $config['snmp']['community'][] = "ichiayi_snmp";
    
    $config['nets'][] = '192.168.1.0/24';
    
    $config['autodiscovery']['nets-exclude'][] = '192.168.1.1/32';
    
    $config['discovery_by_ip'] = true;
    
  4. 第一次可以手動執行一次

    cd /opt/librenms
    ./snmp-scan.py

    結果:

    [root@ct-librenms librenms]# ./snmp-scan.py
    Scanning IPs:
    ..............................................................................................................................................................................................................................................++++++++++-----
    
    Scanned 253 IPs: 0 known devices, added 10 devices, failed to add 5 devices, 1 ips excluded by config
    Runtime: 104.31 seconds

  5. 設定 default_poller_group = 1

    lnms config:set default_poller_group 1

  6. 之後在區域網路內的新設備如果有啟用 snmp v1 / v2c communty 符合設定的值, 可以在五分鐘內被自動加入
  • 前一陣子發現設定都正確, 使用 snmp-scan.py 確實可以自動加入, 但卻無法如預期由該機制將新設備自動加入, 找了一些文章後還是無法真正解決問題, 目前我的 workaround 方法是將 snmp-scan.py 直接加入 cron 來處理

設定告警通知

設定 Device Dependencies 設備依存關係

安裝 Agent 監看應用程式

  • LibreNMS Agent 的安裝方式
  • 安裝 Apache Agent 的方式
  • 加裝 Nagios Plugin 增加監控能力
  • 安裝 BIND(Named) Agent 的方式
  • 加裝 Check_MK 增加監控能力
  • nagios plugins - check_mssql_health
  • 安裝 PVE (Proxmox Virtual Environment) Agent 的方式
  • 安裝 fail2ban Agent 的方式
  • 安裝 MySQL Agent 的方式
  • 安裝 Nginx Agent 的方式
  • 安裝 PHP-FPM Agent 的方式
  • 安裝 postfix Agent 的方式
  • 安裝 Redis Agent 的方式
  • 安裝 SMART Agent 的方式
  • 安裝 ZFS Agent 的方式
載入中 ...

LibreNMS Agent 的安裝方式

  • CentOS 7 + systemd
  • 這 Agent Listen TCP-Port 6556
  • 需要驗證 LibreNMS 可以正確 TCP-Port 6556 連上 Agent 主機
  • 複製 librenms-agent 儲存庫
    cd /opt/
    git clone https://github.com/librenms/librenms-agent.git
    cd librenms-agent
    cp check_mk_agent /usr/bin/check_mk_agent
    chmod +x /usr/bin/check_mk_agent
    cp [email protected] check_mk.socket /etc/systemd/system
    mkdir -p /usr/lib/check_mk_agent/plugins /usr/lib/check_mk_agent/local
    cp agent-local/* /usr/lib/check_mk_agent/local/
    chmod a+x /usr/lib/check_mk_agent/local/*
    systemctl enable check_mk.socket && systemctl start check_mk.socket

參考網址

常見 LibreNMS 異常問題排除

每日自動更版失敗處理

  • 自動更新失敗, 出現很多套件依存議題, Exp,. Carbon 1 is deprecated, see how to migrate to Carbon 2
  • 可重新完整安裝的程序如下:

    su - librenms
    ./scripts/github-remove -d -v
    git pull
    ./daily.sh
    ./validate.php

更新 python3

PHP 7.1 and Python 2 no longer supported 
LibreNMS will soon require Python 3.5+ and PHP 7.2.5+. For more details check https://t.libren.ms/uo84c

2020-05-11 00:00:00 | Source: http://www.librenms.org/notifications.rss

修改連線 DB

CentOS 7 升級 php 至 7.4

  • 因為這方式是重新安裝 php 與相關套件, 所以 php.ini 與 nginx 的一些設定必須再次執行

CentOS 7 升級 MariaDB 10

./lnms migrate 出現 SQLSTATE[42S01] 異常

由 CentOS 7 移轉至 Ubuntu 20.04

  1. 依照正常程序安裝 LibreNMS 在 Ubuntu 20.04
  2. 修改 CentOs 7 與 Ubuntu 20.04 新舊主機內的 /etc/cron.d/librenms 停止 cron 執行

    vi /etc/cron.d/librenms

    :
    #33   */6  * * *   librenms    /opt/librenms/cronic /opt/librenms/discovery-wrapper.py 1
    #*/5  *    * * *   librenms    /opt/librenms/discovery.php -h new >> /dev/null 2>&1
    #*/5  *    * * *   librenms    /opt/librenms/cronic /opt/librenms/poller-wrapper.py 16
    #*    *    * * *   librenms    /opt/librenms/alerts.php >> /dev/null 2>&1
    #*/5  *    * * *   librenms    /opt/librenms/poll-billing.php >> /dev/null 2>&1
    #01   *    * * *   librenms    /opt/librenms/billing-calculate.php >> /dev/null 2>&1
    #*/5  *    * * *   librenms    /opt/librenms/check-services.php >> /dev/null 2>&1
    #*    *    * * *   librenms    cd /opt/librenms/ && php artisan schedule:run >> /dev/null 2>&1
    :
    #15   0    * * *   librenms    /opt/librenms/daily.sh >> /dev/null 2>&1
  3. 在 CentOS 7 舊主機內將 MySQL 資料匯出

    mysqldump librenms -u root -p > librenms.sql

  4. 在 Ubuntu 20.04 新主機將 librenms.sql 匯入

    scp [email protected]:/root/librenms.sql .
    mysql -u root -p librenms < librenms.sql

  5. 將 CentOS 7 舊主機內的 rrd 目錄內的檔案複製到 Ubuntu 20.04 新主機內, @CentOs 7

    cd /opt/librenms/
    tar cvf rrd.tar rrd

    @Ubuntu 20.04

    cd /opt/librenms/
    scp [email protected]:/opt/librenms/rrd.tar .
    tar xvf rrd.tar

  6. 將 CentOS 7 舊主機內的 .env 和 config.php 檔案複製到 Ubuntu 20.04 新主機內, @Ubunutu 20.04

    cd /opt/librenms/
    scp [email protected]:/opt/librenms/.env .
    scp [email protected]:/opt/librenms/config.php .
    chown -R librenms:librenms /opt/librenms

  7. 檢查 Ubuntu 20.04 新主機內的安裝狀態

    su - librenms
    ./validate.php

  8. 修改 Ubuntu 20.04 新主機內的 /etc/cron.d/librenms 啟動 cron 執行

    vi /etc/cron.d/librenms

    :
    33   */6  * * *   librenms    /opt/librenms/cronic /opt/librenms/discovery-wrapper.py 1
    */5  *    * * *   librenms    /opt/librenms/discovery.php -h new >> /dev/null 2>&1
    */5  *    * * *   librenms    /opt/librenms/cronic /opt/librenms/poller-wrapper.py 16
    *    *    * * *   librenms    /opt/librenms/alerts.php >> /dev/null 2>&1
    */5  *    * * *   librenms    /opt/librenms/poll-billing.php >> /dev/null 2>&1
    01   *    * * *   librenms    /opt/librenms/billing-calculate.php >> /dev/null 2>&1
    */5  *    * * *   librenms    /opt/librenms/check-services.php >> /dev/null 2>&1
    *    *    * * *   librenms    cd /opt/librenms/ && php artisan schedule:run >> /dev/null 2>&1
    :
    15   0    * * *   librenms    /opt/librenms/daily.sh >> /dev/null 2>&1

升級 php 至 8.1 以上版本

Error: PHP version too low PHP version 8.1 is the minimum supported version as of September, 2022. We recommend you update to PHP a supported version of PHP (8.1 suggested) to continue to receive updates. If you do not update PHP, LibreNMS will continue to function but stop receiving bug fixes and updates.

2022-09-27 00:00:00 | Source: daily.sh

參考網址