一、LibreNMS简单介绍
LibreNMS是一款开源的,功能强大且功能丰富的自动发现的网络监控系统,基于PHP,使用SNMP协议。它支持广泛的操作系统,包括Linux,FreeBSD以及思科,Juniper,Brocade,Foundry,HP等网络设备。
二、CentOS7下部署LibreNMS
参考官方配置文档完成
https://docs.librenms.org/Installation/Installation-CentOS-7-Nginx/
1、关闭SELINUX,配置yum源
setenforce 0 sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
2、配置remi-php73源,安装LibreNMS所需的组件
yum install -y 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 python3-devel
3.git下载lirenms最新版本
cd /opt git clone https://github.com/librenms/librenms.git
useradd librenms -d /opt/librenms -M -r usermod -a -G librenms nginx chown -R librenms:librenms /opt/librenms chmod 770 /opt/librenms chgrp apache /var/lib/php/session/
4、切换到librenms用户,配置php环境
su - librenms ./scripts/composer_wrapper.php install --no-dev exit
5、配置数据库
systemctl start mariadb mysqladmin -u root password 'MySQL@2021' mysql -u root -pMySQL@2021 登录数据库并创建如下数据库表 CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci; CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'librenms@2021'; GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost'; FLUSH PRIVILEGES; exit
vi /etc/my.cnf [mysqld]下加入如下两行 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock systemctl enable mariadb systemctl restart mariadb
6、配置php环境
vi /etc/php.ini 修改时区配置如下 date.timezone = Asia/Shanghai
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
7、配置nginx
vi /etc/nginx/conf.d/librenms.conf 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; } } 并删掉/etc/nginx/nginx.conf中server段默认配置 systemctl enable nginx systemctl restart nginx
8、snmpd配置
cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf vi /etc/snmp/snmpd.conf中团体名,例如librenms com2sec readonly default librenms 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
9、crond配置与logrotated配置
cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms
10、登录web界面,添加监控设备,功能界面体验
监控设备的snmpd可以参考之前文章