如何在 Debian 10 上安装 LibreNMS

在本教程中,我们将向您展示如何在 Debian 10 上安装 LibreNMS。对于那些不知道的人,LibreNMS 是一个自动发现的基于 PHP/MySQL/SNMP 的网络监控,包括对各种网络硬件的支持和操作系统,包括 Cisco、Linux、FreeBSD、Juniper、HP 等等。 LibreNMS 是一个社区支持的 Observium 分支。

本文假设您至少具有 Linux 的基本知识,知道如何使用 shell,并且最重要的是,您在自己的 VPS 上托管您的站点。 安装非常简单,假设您在 root 帐户中运行,否则您可能需要添加 ‘sudo‘ 到获得 root 权限的命令。 我将向您展示在 Debian 10 (Buster) 上逐步安装 LibreNMS。

在 Debian 10 Buster 上安装 LibreNMS

步骤 1. 在运行下面的教程之前,通过运行以下命令确保您的系统是最新的很重要 apt 终端中的命令:

sudo apt update

步骤 2. 安装所需的软件包。

运行以下命令以安装依赖项所需的包:

sudo apt install acl curl composer fping git graphviz imagemagick mariadb-client mariadb-server mtr-tiny nmap python-memcache python-mysqldb rrdtool snmp snmpd whois python3-pymysql python3-dotenv python3-redis python3-setuptools

步骤 3. 安装 LEMP 堆栈。

需要 Debian 10 LEMP 服务器。 如果您没有安装 LEMP,您可以在此处按照我们的指南进行操作。

步骤 4. 在 Debian 10 上安装 LibreNMS。

在安装之前,我们为 LibreNMS 创建一个用户:

useradd librenms -d /opt/librenms -M -r usermod -a -G librenms www-data

现在我们从官网下载LibreNMS:

cd /opt git clone https://github.com/librenms/librenms.git

接下来,更改文件夹所有权权限:

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/

步骤 4. 为 LibreNMS 配置 MariaDB。

默认情况下,MariaDB 未加固。 您可以使用以下方法保护 MariaDB mysql_secure_installation 脚本。 您应该仔细阅读以下每个步骤,这些步骤将设置 root 密码、删除匿名用户、禁止远程 root 登录以及删除测试数据库和访问安全 MariaDB 的权限:

mysql_secure_installation

像这样配置它:

- Set root password? [Y/n] y - Remove anonymous users? [Y/n] y - Disallow root login remotely? [Y/n] y - Remove test database and access to it? [Y/n] y - Reload privilege tables now? [Y/n] y

接下来,我们需要登录 MariaDB 控制台并为 LibreNMS 创建一个数据库。 运行以下命令:

mysql -u root -p

这将提示您输入密码,因此请输入您的 MariaDB 根密码并点击 Enter. 登录到数据库服务器后,您需要为 LibreNMS 安装创建一个数据库:

MariaDB [(none)]> CREATE DATABASE librenms CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; MariaDB [(none)]> CREATE USER 'librenms'@'localhost' IDENTIFIED BY 'password'; MariaDB [(none)]> GRANT ALL PRIVILEGES ON librenms.* TO 'librenms'@'localhost'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> exit

成功创建数据库后,现在打开 MariaDB 配置文件并在下面添加以下几行 [mysqld] 部分:

nano /etc/mysql/mariadb.conf.d/50-server.cnf

[mysqld] 部分请补充:

innodb_file_per_table=1 lower_case_table_names=0

然后,重新启动 MariaDB 以使更改生效:

sudo systemctl restart mariadb

步骤 5. 配置 Nginx。

现在我们为 LibreNMS 使用的 Nginx 创建 VirtualHost 定义:

rm /etc/nginx/sites-enabled/default nano /etc/nginx/sites-available/librenms.vhost

添加以下配置,编辑 server_name 按要求:

server {listen80;server_name librenms.idroot.us;root/opt/librenms/html;indexindex.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;proxy_read_timeout 300;proxy_connect_timeout 300;proxy_send_timeout 300;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:/var/run/php/php7.3-fpm.sock;}location ~ /.ht {deny all;}}

Save 和 close 还要重新启动 Nginx Web 服务器,以便进行更改:

ln -s /etc/nginx/sites-available/librenms.vhost /etc/nginx/sites-enabled/librenms.vhost sudo systemctl restart nginx

步骤 6. 配置 snmpd。

现在使用 nano 文本编辑器编辑新配置 snmpd:

cp /opt/librenms/snmpd.conf.example /etc/snmp/snmpd.conf chmod 600 /etc/snmp/snmpd.conf nano /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 service snmpd restart

步骤 7. 配置 UFW 防火墙。

向防火墙添加新端口。 向ufw防火墙添加新的ssh、HTTP、HTTPS和snmpd 161 udp类型使用的端口:

sudo ufw allow ssh sudo ufw allow http sudo ufw allow https sudo ufw allow 161/udp sudo ufw enable

步骤 8. 访问 LibreNMS Web 界面。

成功安装后,LibreNMS 将默认在 HTTP 端口 80 上可用。 打开您最喜欢的浏览器并导航到 https://librenms.idroot.us/ 并完成所需的步骤以完成安装。

恭喜! 您已成功安装 LibreNMS。 感谢您使用本教程在 Debian 系统上安装最新版本的 LibreNMS。 如需更多帮助或有用信息,我们建议您查看 LibreNMS 官方网站.