你们好,我是民工哥。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 配置
报警规则
往期推荐: