乐趣区

关于后端:挺带劲这款免费开源的监控系统真强大

大家好,我是民工哥。

一提到监控零碎,大家很快就能想到 Zabbix、Prometheus 等,明天,民工哥给大家举荐一款绝 不逊色 Zabbix 的监控软件 Librenms

LibreNMS 介绍

LibreNMS 是一个 全功能的开源网络监控零碎。它用于 SNMP 从不同设施获取数据。LibreNMS 反对各种设施,如 Cisco,Linux,FreeBSD,Juniper,Brocade,Foundry,HP 等。它反对多种认证机制并反对双因素认证。它有一个可定制的警报系统,能够通过电子邮件揭示网络管理员

github:https://github.com/librenms/l…

LibreNMS 特点

  • 主动发现
  • 警示
  • 多种环境传感器反对
  • 多种协定数据收集(STP,OSPF,BGP 等)
  • VLAN,ARP 和 FDB 表收集
  • 可定制的仪表板
  • 设施集成备份
  • 分布式轮询
  • 多种身份验证办法(MySQL,LDAP,Active Directory,HTTP)
  • NetFlow,sFlow,IPFIX(NfSen)
  • 服务监控(Nagios 插件)
  • Syslog(集成,Graylog)
  • 流量计费
  • 两因素认证
  • 弱小的 API
  • 自动更新

LibreNMS 装置

  • 环境
  • 请留神,最低反对的 PHP 版本是 7.3
  • 倡议应用 Nginx 作为 web 服务器
装置必须的软件包
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 用户

useradd librenms -d /opt/librenms -M -r
usermod -a -G librenms nginx

下载 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/
chgrp apache /var/lib/php/session/

装置 PHP 依赖项

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

数据库服务器

# 配置 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-FPM

确保在 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 界面

首页界面 增加设施

创立组

设施列表

启用发现模块

流量监控

磁盘监控

网络图

LibreNMS 图表

API 配置

报警规定

往期举荐:

零碎之眼!Linux 零碎性能监控工具 Glances

界面酷炫,功能强大!这款 Linux 性能实时监控工具超好用!

退出移动版