你們好,我是民工哥。javascript
一提到監控系統,你們很快就能想到Zabbix、Prometheus等,今天,民工哥給你們推薦一款絕不遜色 Zabbix 的監控軟件 Librenms。php
LibreNMS是一個全功能的開源網絡監控系統。它用於SNMP從不一樣設備獲取數據。LibreNMS支持各類設備,如Cisco,Linux,FreeBSD,Juniper,Brocade,Foundry,HP等。它支持多種認證機制並支持雙因素認證。它有一個可定製的警報系統,能夠經過電子郵件提醒網絡管理員css
github:https://github.com/librenms/l...html
yum install epel-release yum-utils yum localinstall http://rpms.remirepo.net/enterprise/remi-release-7.rpm yum-config-manager --enable remi-php73 yum install composer cronie fping git ImageMagick jwhois mariadb mariadb-server mtr MySQL-python net-snmp net-snmp-utils nginx nmap php-fpm php-cli php-common php-curl php-gd php-mbstring php-process php-snmp php-xml php-zip php-memcached php-mysqlnd python-memcached rrdtool python3 python3-pip
添加librenms用戶java
useradd librenms -d /opt/librenms -M -r usermod -a -G librenms nginx
下載LibreNMSpython
cd /opt git clone https://github.com/librenms/librenms.git
設定權限mysql
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/ chgrp apache /var/lib/php/session/
安裝PHP依賴項ios
su - librenms ./scripts/composer_wrapper.php install --no-dev exit
數據庫服務器nginx
#配置MySQL systemctl start mariadb 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 vi /etc/my.cnf 在此[mysqld]部分中,請添加: innodb_file_per_table=1 lower_case_table_names=0 systemctl enable mariadb systemctl restart mariadb
配置並啓動PHP-FPMgit
確保在php.ini中將date.timezone設置爲您首選的時區,具體時區請參考:https://php.net/manual/en/tim...
vi /etc/php.ini date.timezone = Asia/Shanghai
在進行/etc/php-fpm.d/www.conf如下更改
vi /etc/php-fpm.d/www.conf ;user = apache user = nginx group = apache ; keep group as apache ;listen = 127.0.0.1:9000 listen = /run/php-fpm/php-fpm.sock listen.owner = nginx listen.group = nginx listen.mode = 0660 systemctl enable php-fpm systemctl restart php-fpm
配置NGINX
vi /etc/nginx/conf.d/librenms.conf 添加如下配置,server_name根據須要進行編輯: 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 /api/v0 { try_files $uri $uri/ /api_v0.php?$query_string; } location ~ \.php { include fastcgi.conf; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/run/php-fpm/php-fpm.sock; } location ~ /\.ht { deny all; } } systemctl enable nginx systemctl restart nginx
配置LibreNMS所需的上下文
semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/logs(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/logs(/.*)?' restorecon -RFvv /opt/librenms/logs/ semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/rrd(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/rrd(/.*)?' restorecon -RFvv /opt/librenms/rrd/ semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/storage(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/storage(/.*)?' restorecon -RFvv /opt/librenms/storage/ semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/bootstrap/cache(/.*)?' semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/bootstrap/cache(/.*)?' restorecon -RFvv /opt/librenms/bootstrap/cache/ setsebool -P httpd_can_sendmail=1 setsebool -P httpd_execmem 1
容許fping
使用如下內容建立文件http_fping.tt。您能夠在任何地方建立此文件,由於它是一次性文件。此安裝過程的最後一步將把模塊安裝在正確的位置。
module http_fping 1.0; require { type httpd_t; class capability net_raw; class rawip_socket { getopt create setopt write read }; } #============= httpd_t ============== allow httpd_t self:capability net_raw; allow httpd_t self:rawip_socket { getopt create setopt write read };
而後運行這些命令
checkmodule -M -m -o http_fping.mod http_fping.tt semodule_package -o http_fping.pp -m http_fping.mod semodule -i http_fping.pp
配置snmpd
cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf vi /etc/snmp/snmpd.conf 編輯顯示的文字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
Cron job
cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
logrotate 配置
LibreNMS保留日誌/opt/librenms/logs。隨着時間的流逝,它們可能會變大並向外旋轉。要輪換出舊日誌,能夠使用提供的logrotate配置文件。
cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
Web安裝
瀏覽器輸入 http://librenms.example.com/i... 進行安裝
Web安裝程序可能會提示config.php在librenms安裝位置須要手動建立文件,這時將Web上顯示的內容複製到該文件。而後設置權限。
chown librenms:librenms /opt/librenms/config.php
首頁界面添加設備
建立組
設備列表
啓用發現模塊
流量監控
磁盤監控
網絡圖
LibreNMS圖表
API 配置
報警規則
往期推薦: