云网牛站
所在位置:首页 > Linux云服务器 > 在RHEL/CentOS 8系统上安装和配置LibreNMS的方法

在RHEL/CentOS 8系统上安装和配置LibreNMS的方法

2019-03-20 09:37:56作者:曾秀珠稿源:云网牛站

本文介绍在RHEL/CentOS 8操作系统上安装和配置LibreNMS的方法,在开始此安装之前,请确保在RHEL/CentOS 8上安装了EPEL存储库。

 

一、安装所需的依赖项

我们总是使用应用程序所需的依赖项启动安装,参考在RHEL 8/CentOS 8上安装EPEL存储库(EPEL Repository)的方法

打开终端并运行下面的命令以安装所需的依赖项:

sudo dnf -y install yum-utils

sudo dnf -y install zip unzip git cronie wget fping net-snmp net-snmp-utils  jwhois mtr rrdtool  nmap

 

二、安装PHP和Apache

安装LibreNMS所需的Apache Web服务器,PHP和扩展:

sudo yum install @httpd @php php-{cli,common,curl,gd,mbstring,mysqlnd,process,snmp,xml,zip}

启动Apache和PHP FPM服务:

sudo systemctl enable --now php-fpm httpd

检查服务状态,运行sudo systemctl status php-fpm httpd命令:

在RHEL/CentOS 8系统上安装和配置LibreNMS的方法

验证PHP版本和加载的模块:

$ php -v

PHP 7.2.11

$ php -m

在/etc/php.ini文件中设置PHP时区:

$ grep date.timezone /etc/php.ini 

; http://php.net/date.timezone

date.timezone = Asia/Shanghai

允许防火墙上的http和https端口:

sudo firewall-cmd --add-service={http,https} --permanent

sudo firewall-cmd --reload

参考:在RHEL 8上安装配置Apache、mod_ssl、mod_http2的方法

 

三、安装和配置数据库服务器

参考:在RHEL 8系统上安装MariaDB数据库的步骤

你可以选择使用MySQL或MariaDB数据库服务器,参考在RHEL 8系统上安装MySQL 8.0的步骤

安装数据库服务器后,为LibreNMS Monitoring工具创建数据库和用户:

$ mysql -u root -p

CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci;

CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'StrongDBPassword';

GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost';

FLUSH PRIVILEGES;

exit

编辑my.cnf文件并在[mysqld]部分中添加以下行:

$ sudo vim /etc/my.cnf.d/mariadb-server.cnf

在[mysqld]部分中,请添加:

innodb_file_per_table=1

lower_case_table_names=0

重启mariadb服务:

sudo systemctl enable mariadb

sudo systemctl restart mariadb

服务状态应显示正在运行,运行systemctl status mariadb命令:

在RHEL/CentOS 8系统上安装和配置LibreNMS的方法

 

四、在RHEL/CentOS 8上安装和配置LibreNMS

添加librenms用户:

sudo useradd librenms -d /opt/librenms -M -r

sudo usermod -a -G librenms apache

从Github克隆LibreNMS项目:

cd /opt

sudo git clone https://github.com/librenms/librenms.git

sudo chown librenms:librenms -R /opt/librenms

安装PHP依赖项:

cd /opt/librenms

./scripts/composer_wrapper.php install --no-dev

成功安装应具有类似于以下的输出:

在RHEL/CentOS 8系统上安装和配置LibreNMS的方法

复制并配置SNMP配置模板:

sudo cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf

sudo vim /etc/snmp/snmpd.conf

通过替换RANDOMSTRINGGOESHERE来设置社区字符串:

com2sec readonly  default  MyInternalNetwork

下载分发版本标识符脚本:

sudo curl -o /usr/bin/distro https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/distro

sudo chmod +x /usr/bin/distro

然后启动并启用snmpd服务:

$ sudo systemctl enable snmpd

$ sudo systemctl restart snmpd

$ sudo systemctl status snmpd

在RHEL/CentOS 8系统上安装和配置LibreNMS的方法

配置Apache,为LibreNMS创建新的Apache配置文件:

sudo vi /etc/httpd/conf.d/librenms.conf

添加以下配置,根据需要编辑ServerName:

<VirtualHost *:80>

DocumentRoot /opt/librenms/html/

ServerName  librenms.example.com

AllowEncodedSlashes NoDecode

<Directory "/opt/librenms/html/">

Require all granted

AllowOverride All

Options FollowSymLinks MultiViews

</Directory>

</VirtualHost>

配置SELinux策略,允许Apache在/opt/librenms/html/上提供文件:

sudo semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/logs(/.*)?'

sudo semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/logs(/.*)?'

sudo restorecon -RFvv /opt/librenms/logs/

sudo semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/rrd(/.*)?'

sudo semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/rrd(/.*)?'

sudo restorecon -RFvv /opt/librenms/rrd/

sudo semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/storage(/.*)?'

sudo semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/storage(/.*)?'

sudo restorecon -RFvv /opt/librenms/storage/

sudo semanage fcontext -a -t httpd_sys_content_t '/opt/librenms/bootstrap/cache(/.*)?'

sudo semanage fcontext -a -t httpd_sys_rw_content_t '/opt/librenms/bootstrap/cache(/.*)?'

sudo restorecon -RFvv /opt/librenms/bootstrap/cache/

sudo setsebool -P httpd_can_sendmail=1

允许Ping,使用以下内容创建文件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 };

然后运行这些命令:

sudo checkmodule -M -m -o http_fping.mod http_fping.tt

sudo semodule_package -o http_fping.pp -m http_fping.mod

sudo semodule -i http_fping.pp

如果一切正常,请重新启动httpd服务:

sudo systemctl restart httpd

配置cron jobs:

sudo cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms

复制logrotate配置,LibreNMS将日志保存在/opt/librenms/logs中,随着时间的推移,这些可能会变大并被旋转出来。

要旋出旧日志,你可以使用提供的logrotate配置文件:

sudo cp /opt/librenms/misc/librenms.logrotate /etc/logrotate.d/librenms

设置适当的权限:

sudo chown -R librenms:librenms /opt/librenms

setfacl -d -m g::rwx /opt/librenms/logs

sudo setfacl -d -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/

sudo setfacl -R -m g::rwx /opt/librenms/rrd /opt/librenms/logs /opt/librenms/bootstrap/cache/ /opt/librenms/storage/

 

五、启动LibreNMS Web安装程序

1.在Web浏览器上打开地址如:http://librenms.example.com/install.php以完成安装。

在RHEL/CentOS 8系统上安装和配置LibreNMS的方法

确认所有预安装检查(Pre-Install Checks)通过并单击“Next Stage”。

2.配置先前创建的数据库凭据,它将开始导入数据库模式并填写数据:

在RHEL/CentOS 8系统上安装和配置LibreNMS的方法

如果导入成功,应该收到如下消息:

在RHEL/CentOS 8系统上安装和配置LibreNMS的方法

3.在下一页上,系统会要求你配置管理员用户帐户:

在RHEL/CentOS 8系统上安装和配置LibreNMS的方法

4.接下来是生成配置文件,如果无法创建,你可能必须使用给定的内容手动创建文件,文件路径应为/opt/librenms/config.php:

<?php

## Have a look in defaults.inc.php for examples of settings you can set here. DO NOT EDIT defaults.inc.php!

### Database config

$config['db_host'] = 'localhost';

$config['db_port'] = '3306';

$config['db_user'] = 'librenms';

$config['db_pass'] = 'StrongDBPassword';

$config['db_name'] = 'librenms';

$config['db_socket'] = '';

// This is the user LibreNMS will run as

//Please ensure this user is created and has the correct permissions to your install

$config['user'] = 'librenms';

### Locations - it is recommended to keep the default

#$config['install_dir']  = "/opt/librenms";

### This should *only* be set if you want to *force* a particular hostname/port

### It will prevent the web interface being usable form any other hostname

#$config['base_url']        = "http://librenms.company.com";

### Enable this to use rrdcached. Be sure rrd_dir is within the rrdcached dir

### and that your web server has permission to talk to rrdcached.

#$config['rrdcached']    = "unix:/var/run/rrdcached.sock";

### Default community

$config['snmp']['community'] = array("public");

### Authentication Model

$config['auth_mechanism'] = "mysql"; # default, other options: ldap, http-auth

#$config['http_auth_guest'] = "guest"; # remember to configure this user if you use http-auth

### List of RFC1918 networks to allow scanning-based discovery

#$config['nets'][] = "10.0.0.0/8";

#$config['nets'][] = "172.16.0.0/12";

#$config['nets'][] = "192.168.0.0/16";

# Update configuration

#$config['update_channel'] = 'release';  # uncomment to follow the monthly release channel

#$config['update'] = 0;  # uncomment to completely disable updates

将文件的所有权更改为librenms用户:

sudo chown librenms:librenms /opt/librenms/config.php

5.单击“Finish Install”按钮以完成LibreNMS安装,你应该看到管理员登录页面,请用配置的帐户登录:

在RHEL/CentOS 8系统上安装和配置LibreNMS的方法

LibreNMS管理面板应类似于下面的图片:

在RHEL/CentOS 8系统上安装和配置LibreNMS的方法

至此,安装配置LibreNMS完成。

 

相关主题

使用Nginx在Ubuntu 18.04上安装和配置LibreNMS的方法

使用Letsencrypt和Nginx在CentOS下安装LibreNMS监视工具

精选文章
热门文章