一、LibreNMS簡單介紹
LibreNMS是一款開源的,功能強大且功能豐富的自動發(fā)現(xiàn)的網(wǎng)絡監(jiān)控系統(tǒng),基于PHP,使用SNMP協(xié)議。它支持廣泛的操作系統(tǒng),包括Linux,F(xiàn)reeBSD以及思科,Juniper,Brocade,F(xiàn)oundry,HP等網(wǎng)絡設備。二、CentOS7下部署LibreNMS
https://docs.librenms.org/Installation/Installation-CentOS-7-Nginx/
1、關(guān)閉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環(huán)境
su - librenms
./scripts/composer_wrapper.php install --no-dev
exit
5、配置數(shù)據(jù)庫
systemctl start mariadb
mysqladmin -u root password 'MySQL@2021'
mysql -u root -pMySQL@2021
登錄數(shù)據(jù)庫并創(chuàng)建如下數(shù)據(jù)庫表
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環(huán)境
vi /etc/php.ini
修改時區(qū)配置如下
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界面,添加監(jiān)控設備,功能界面體驗