Try   HackMD
tags: Network Librenms

LibreNMS@Ubuntu 20.2 安裝筆記

安裝環境

OS: Ubuntu20.02 64bit
VMWare ESXi 6.0
1 CPU
1024MB RAM

環境初始化及LibreNMS安裝

LibreNMS官方安裝文件

環境套件安裝

安裝及更新套件庫

apt install software-properties-common
add-apt-repository universe
apt update

安裝執行環境所以套件
(因為Ubuntu 20.2的PHP已經升級到PHP7.4的版本,所以如果按照官網的方式安裝會跳錯喔~)

apt install curl apache2 composer fping git graphviz imagemagick libapache2-mod-php7.4 mariadb-client mariadb-server mtr-tiny nmap php7.4-cli php7.4-curl 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 python3-pip python3-memcache python3-mysqldb acl

開始安裝LibreNMS

新增使用者librenms

useradd librenms -d /opt/librenms -M -r
usermod -a -G librenms www-data

自github下載LibreNMS

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

調整資料夾權限

chown -R librenms:librenms /opt/librenms
chmod 770 /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

資料庫初始化及設定

資料庫啟動
這邊會提示輸入mariaDB的管理者密碼,就是你登入Linux的密碼,登入後會進入MySQL命令列

systemctl restart mysql
mysql -uroot -p

在MySQL的命令列貼上以下指令,會執行以下動作

  1. 建立資料庫
  2. 建立使用者
  3. 賦予librenms使用者有存取資料庫的權限
    !!注意密碼的部分要改成自己想要的,範例中預設是password
CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';
FLUSH PRIVILEGES;
exit

編輯並在[mysqld]新增以下兩行設定,存檔後重啟MySQL

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

innodb_file_per_table=1
lower_case_table_names=0

# systemctl restart mysql

設定Apache網頁伺服器

apache利用php來呈現動態網頁,所以一開始先來把php的時區定義為台灣的+08:00,避免後續問題

依序編輯這兩個檔案將時區設定為 date.timezone = Asia/Taipei

#編輯以下兩個檔案

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

#更時區參數date.timezone

date.timezone = Asia/Taipei

執行指令啟用apache相關模組

a2enmod php7.4
a2dismod mpm_event
a2enmod mpm_prefork

新增Apache虛擬站台設定檔

# vi /etc/apache2/sites-available/librenms.conf

# 貼上以下內容並存檔

<VirtualHost *:80>
  DocumentRoot /opt/librenms/html/
  ServerName  librenms.lab.com

  AllowEncodedSlashes NoDecode
  <Directory "/opt/librenms/html/">
    Require all granted
    AllowOverride All
    Options FollowSymLinks MultiViews
  </Directory>
</VirtualHost>

啟用站台並重啟apache服務

a2ensite librenms
a2enmod rewrite
systemctl restart apache2

設定本機snmpd服務

執行以下指令,複製設定範本,並從github上下載snmp指令稿

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

編輯snmpd.conf,並且把"RANDOMSTRINGGOESHERE"改成你要的snmp community連線字串

vi /etc/snmp/snmpd.conf

# Change RANDOMSTRINGGOESHERE to your preferred SNMP community string
com2sec readonly  default         cmustring

重新啟動snmpd

systemctl restart snmpd

把LibreNMS的輪詢工作排進CronJob

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

排程Logrotate

避免log file爆滿

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

進入LibreNMS站台做最後的設定

之前的動作都是為了LibreNMS執行環境,安裝相關套件、資料庫安裝初始化、網頁站台設定,等基本環境建置

接下來要用瀏覽器連線到LibreNMS站台 http://librenms.lab.com


Stage 2

設定資料庫連線密碼,先前建立的資料庫使用者librenms,這邊把他的密碼敲進去就可以下一步了

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

建立資料表及欄位

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →


Stage 3

新增管理者帳號


Stage 4

產生設定檔


Stage 5

完成設定


Stage 6

基本上到這邊就完成安裝了,但是還有些錯誤要修正,後續到系統中見招拆招就好了

附錄

將python指定為python3

apt install python-is-python3

修改MySQL時區

[mysqld]
default-time-zone = '+8:00'