CentOS7下部署开源网络监控系统LibreNMS
一、LibreNMS简单介绍
二、CentOS7下部署LibreNMS
1、关闭SELINUX,配置yum源
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 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最新版本
git clone https://github.com/librenms/librenms.git
usermod -a -G librenms nginx
chown -R librenms:librenms /opt/librenms
chmod 770 /opt/librenms
chgrp apache /var/lib/php/session/
4、切换到librenms用户,配置php环境
./scripts/composer_wrapper.php install --no-dev
exit
5、配置数据库
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
[mysqld]下加入如下两行
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
systemctl enable mariadb
systemctl restart mariadb
6、配置php环境
修改时区配置如下
date.timezone = Asia/Shanghai
修改成如下行
;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
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配置
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/misc/librenms.logrotate /etc/logrotate.d/librenms