在当今快节奏的数字世界中,网络监控是必不可少的。密切关注网络的运行状况和性能可以防止潜在问题并确保无缝运行。LibreNMS 是一个开源网络监控系统,是一个强大的工具,可以帮助您实现这一目标。
在 Fedora 38 上安装 LibreNMS
第 1 步。在我们可以在 Fedora 38 上安装 LibreNMS 之前,重要的是要确保我们的系统是最新的软件包。这将确保我们能够访问最新功能和错误修复,并且我们可以毫无问题地安装 LibreNMS:
<span class="pln">sudo dnf update sudo dnf install git fping cronie composer cronie</span><span class="pun">-</span><span class="pln">anacron ipmitool</span>
第 2 步。安装Nginx。
Nginx是一个高性能的Web服务器,将作为LibreNMS的Web界面。通过运行以下命令安装它:
<span class="pln">sudo dnf install nginx</span>
现在,启动 Nginx 并使用它来启动:
<span class="pln">sudo systemctl start nginx sudo systemctl enable nginx</span>
第 3 步。安装 MariaDB。
LibreNMS依靠数据库来存储网络数据。为此,我们将使用 MariaDB。安装 MariaDB 并保护它:
<span class="pln">sudo dnf install mariadb</span><span class="pun">-</span><span class="pln">server sudo systemctl start mariadb sudo systemctl enable mariadb sudo mysql_secure_installation</span>
在 MariaDB 安全安装期间,设置一个强 root 密码,并对其他提示回答“Y”(是)。
接下来,为 LibreNMS 创建一个 MariaDB 数据库:
<span class="pln">mysql </span><span class="pun">-</span><span class="pln">u root </span><span class="pun">-</span><span class="pln">p</span>
出现提示时,输入 MariaDB 根密码。现在,为 LibreNMS 创建一个数据库:
<span class="pln">CREATE DATABASE librenms CHARACTER SET utf8 COLLATE utf8_unicode_ci</span><span class="pun">;</span><span class="pln"> CREATE USER </span><span class="str">'librenms'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pln"> IDENTIFIED BY </span><span class="str">'your_password'</span><span class="pun">;</span> <span class="com"># Replace 'your_password' with a secure password</span><span class="pln"> GRANT ALL PRIVILEGES ON librenms</span><span class="pun">.*</span><span class="pln"> TO </span><span class="str">'librenms'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pun">;</span><span class="pln"> FLUSH PRIVILEGES</span><span class="pun">;</span><span class="pln"> EXIT</span><span class="pun">;</span>
第 4 步。安装 PHP。
PHP 对于处理基于 Web 的请求和呈现网页至关重要。安装 PHP 和所需的扩展:
<span class="pln">sudo dnf install php php</span><span class="pun">-</span><span class="pln">cli php</span><span class="pun">-</span><span class="pln">fpm php</span><span class="pun">-</span><span class="pln">mysqlnd php</span><span class="pun">-</span><span class="pln">zip php</span><span class="pun">-</span><span class="pln">gd php</span><span class="pun">-</span><span class="pln">mbstring php</span><span class="pun">-</span><span class="pln">curl php</span><span class="pun">-</span><span class="pln">xml php</span><span class="pun">-</span><span class="pln">json php</span><span class="pun">-</span><span class="pln">snmp php</span><span class="pun">-</span><span class="pln">intl php</span><span class="pun">-</span><span class="pln">ldap php</span><span class="pun">-</span><span class="pln">common php</span><span class="pun">-</span><span class="pln">opcache php</span><span class="pun">-</span><span class="pln">memcached</span>
接下来,我们需要调整 PHP 配置。打开 PHP-FPM 配置文件:
<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">php</span><span class="pun">-</span><span class="pln">fpm</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">librenms</span><span class="pun">.</span><span class="pln">conf</span>
将以下行添加到文件中:
<span class="pln">user </span><span class="pun">=</span><span class="pln"> nginx </span><span class="kwd">group</span> <span class="pun">=</span><span class="pln"> nginx</span>
保存文件,然后重新启动 PHP-FPM:
<span class="pln">sudo systemctl restart php</span><span class="pun">-</span><span class="pln">fpm</span>
第5步。安装编辑器和所需软件包
Composer 是一个 PHP 包管理器,我们将用它来管理 LibreNMS 依赖项。安装编辑器:
<span class="pln">sudo php </span><span class="pun">-</span><span class="pln">r </span><span class="str">"copy('https://getcomposer.org/installer', 'composer-setup.php');"</span><span class="pln"> sudo php composer</span><span class="pun">-</span><span class="pln">setup</span><span class="pun">.</span><span class="pln">php </span><span class="pun">--</span><span class="pln">install</span><span class="pun">-</span><span class="pln">dir</span><span class="pun">=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">bin </span><span class="pun">--</span><span class="pln">filename</span><span class="pun">=</span><span class="pln">composer</span>
为 LibreNMS 安装所需的 Composer 软件包:
<span class="pln">cd </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">librenms sudo composer install </span><span class="pun">--</span><span class="kwd">no</span><span class="pun">-</span><span class="pln">dev</span>
第 6 步。在 Fedora 38 上安装 LibreNMS。
现在,我们已经准备好下载和配置 LibreNMS。切换到目录并克隆 LibreNMS 存储库:/opt
<span class="pln">cd </span><span class="pun">/</span><span class="pln">opt sudo git clone https</span><span class="pun">:</span><span class="com">//github.com/librenms/librenms.git</span>
设置正确的权限:
<span class="pln">sudo chown </span><span class="pun">-</span><span class="pln">R nginx</span><span class="pun">:</span><span class="pln">nginx </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">librenms</span>
创建配置文件:
<span class="pln">sudo cp </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">librenms</span><span class="pun">/.</span><span class="pln">env</span><span class="pun">.</span><span class="pln">example </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">librenms</span><span class="pun">/.</span><span class="pln">env</span>
编辑配置文件:
<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">librenms</span><span class="pun">/.</span><span class="pln">env</span>
根据您的 MySQL 设置调整数据库设置:
<span class="pln">DB_HOST</span><span class="pun">=</span><span class="pln">localhost DB_NAME</span><span class="pun">=</span><span class="pln">librenms DB_USER</span><span class="pun">=</span><span class="pln">librenms DB_PASS</span><span class="pun">=</span><span class="pln">your_password</span>
运行 LibreNMS 安装脚本,该脚本将设置必要的数据库表并配置 LibreNMS:
<span class="pln">sudo </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">librenms</span><span class="pun">/</span><span class="pln">scripts</span><span class="pun">/</span><span class="pln">install</span><span class="pun">.</span><span class="pln">sh</span>
按照屏幕上的说明操作。出现提示时,选择“是”以创建初始管理员用户。
步骤 7.为 nginx 创建虚拟主机配置。
创建一个新的 Nginx 服务器块配置文件:
<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">librenms</span><span class="pun">.</span><span class="pln">conf</span>
添加以下配置,并替换为您的实际域名:your_domain.com
<span class="pln">server </span><span class="pun">{</span><span class="pln"> listen </span><span class="lit">80</span><span class="pun">;</span><span class="pln"> server_name your_domain</span><span class="pun">.</span><span class="pln">com</span><span class="pun">;</span> <span class="com"># Replace with your domain</span><span class="pln"> root </span><span class="pun">/</span><span class="pln">opt</span><span class="pun">/</span><span class="pln">librenms</span><span class="pun">/</span><span class="pln">html</span><span class="pun">;</span><span class="pln"> index index</span><span class="pun">.</span><span class="pln">php</span><span class="pun">;</span><span class="pln"> access_log </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">access</span><span class="pun">.</span><span class="pln">log</span><span class="pun">;</span><span class="pln"> error_log </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">error</span><span class="pun">.</span><span class="pln">log</span><span class="pun">;</span><span class="pln"> location </span><span class="pun">/</span> <span class="pun">{</span><span class="pln"> try_files $uri $uri</span><span class="pun">/</span> <span class="pun">=</span><span class="lit">404</span><span class="pun">;</span> <span class="pun">}</span><span class="pln"> location </span><span class="pun">~</span><span class="pln"> \.php$ </span><span class="pun">{</span><span class="pln"> include fastcgi_params</span><span class="pun">;</span><span class="pln"> fastcgi_pass unix</span><span class="pun">:</span><span class="str">/var/</span><span class="pln">run</span><span class="pun">/</span><span class="pln">php</span><span class="pun">-</span><span class="pln">fpm</span><span class="pun">/</span><span class="pln">php</span><span class="pun">-</span><span class="pln">fpm</span><span class="pun">.</span><span class="pln">sock</span><span class="pun">;</span><span class="pln"> fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name</span><span class="pun">;</span> <span class="pun">}</span><span class="pln"> location </span><span class="pun">~</span> <span class="pun">/</span><span class="pln">\.ht </span><span class="pun">{</span><span class="pln"> deny all</span><span class="pun">;</span> <span class="pun">}</span> <span class="pun">}</span>
保存文件,然后启用 Nginx 虚拟主机配置并创建指向服务器 IP 地址的 DNS 记录
<span class="pln">sudo ln </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">sites</span><span class="pun">-</span><span class="pln">available</span><span class="pun">/</span><span class="pln">librenms</span><span class="pun">.</span><span class="pln">conf </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">sites</span><span class="pun">-</span><span class="pln">enabled</span><span class="pun">/</span><span class="pln"> sudo systemctl restart nginx</span>
第8步。设置防火墙
启用防火墙并允许 HTTP 和 HTTPS 流量:
<span class="pln">sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">zone</span><span class="pun">=</span><span class="kwd">public</span> <span class="pun">--</span><span class="kwd">add</span><span class="pun">-</span><span class="pln">service</span><span class="pun">=</span><span class="pln">http </span><span class="pun">--</span><span class="pln">permanent sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">zone</span><span class="pun">=</span><span class="kwd">public</span> <span class="pun">--</span><span class="kwd">add</span><span class="pun">-</span><span class="pln">service</span><span class="pun">=</span><span class="pln">https </span><span class="pun">--</span><span class="pln">permanent sudo firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">reload</span>
第9步。访问 LibreNMS Web UI。
通过导航到 来访问您的 LibreNMS Web 界面。按照屏幕上的说明创建初始管理员用户并配置基本设置。http://your_domain.com
感谢您使用本教程在您的 Fedora 38 系统上安装 LibreNMS。如需更多帮助或有用信息,我们建议您查看 LibreNMS 官方网站。