如何在AlmaLinux 9上安装Nagios核心监控
Nagios 是一个用于服务器、网络和应用程序的开源监控系统。它还通过实时跟踪 IT 基础设施提供主动的问题解决。 Nagios 监控服务器和网络应用程序的运行状况和性能。
在本指南中,我们将向您展示如何在Almalinux 9服务器上安装Nagios监控工具。您将通过 EPEL 安装 Nagios,这使得 Nagios 软件包易于安装。
先决条件
在开始之前,请确保您具备以下条件:
- AlmaLinxu 9 服务器。
- 具有 sudo 权限的非 root 用户。
- 具有许可状态的 SELinux。
启用存储库 EPEL 和 CRB(CodeReady 构建)
在安装Nagios之前,您必须添加EPEL存储库并在AlmaLinux服务器上启用Code Ready Build(CRB)。这是因为 Nagios 软件包仅在 EPEL 中可用,并且 Nagios 的一些 Perl 软件包依赖项在 CRB 存储库中可用。
首先,执行以下命令在 AlamaLinux 服务器上启用 CRB 存储库。
sudo dnf config-manager --set-enabled crb
其次,执行以下命令将 EPEL 存储库添加到您的系统中。
sudo dnf install epel-release
最后,使用以下命令刷新AlmaLinux上的可用存储库。
sudo dnf makecache
在AlmaLinux上安装Nagios
添加EPEL和CRB存储库后,您现在可以在AlmaLinux服务器上安装Nagios。您可以手动编译它,但为了更快地部署,您将通过 EPEL 安装 Nagios。
执行下面的dnf命令将Nagios、Nagios插件和Nagios NRPE插件安装到您的AlmaLinux。输入 y 继续安装。
sudo dnf install nagios nagios-common nagios-plugins nagios-plugins-all nrpe
安装完成后,使用以下命令启动并启用 Nagios 服务。
sudo systemctl start nagios
sudo systemctl enable nagios
然后,验证Nagios服务以确保该服务正在运行。
sudo systemctl status nagios
下面您可以看到AlmaLinux服务器上运行的nagios服务。
接下来,通过执行以下命令启动并启用 httpd 服务。
sudo systemctl start httpd
sudo systemctl enable httpd
启动后,使用以下命令验证 httpd 服务。
sudo systemctl status httpd
确保 httpd 服务状态正在运行,如下所示:
配置Nagios监控
现在您已经安装了 Nagis,下一步是通过设置身份验证、更改 nagiosadmin 的默认密码以及验证 httpd 配置来配置 Nagios 安装。
在此之前,您必须了解以下一些Nagios相关的配置文件和目录:
- /etc/nagios:Nagios的主要配置目录。
- /etc/httpd/conf.d/nagios.conf:Nagios 和 httpd Web 服务器之间集成的主要配置。
- /etc/nagios/nagios.conf:Nagios 配置文件。
- /etc/nagios/cgi.cfg:Nagios Web应用程序的主要配置,在CGI下运行。
- /etc/nagios/passwd:Nagios 身份验证的默认密码文件。基于 Apache/httpd basic_auth 模块。
执行以下 nano 编辑器命令并打开 Nagios CGI 配置 /etc/nagios/cgi.cfg。
sudo nano /etc/nagios/cgi.cfg
找到 use_authentication 选项并确保其已启用且值为 1。
# AUTHENTICATION USAGE
# This option controls whether or not the CGIs will use any
# Authentication when displaying host and service information, as
# well as committing commands to Nagios for processing.
#
# Read the HTML documentation to learn how the authorization works!
#
# NOTE: It is a really *bad* idea to disable authorization, unless
# You plan on removing the command CGI (cmd. cgi)! Failure to do
# so will leave you wide open to kiddies messing with Nagios and
# possibly hitting you with a denial of service attack by filling up
# your drive by continuously writing to your command file!
#
# Setting this value to 0 will cause the CGIs to *not* use
# authentication (bad idea), while any other value will make them
# use the authentication functions (the default).
use_authentication=1
保存文件并退出编辑器。
运行以下命令以重新启动 nagios 服务并应用更改。
sudo systemctl restart nagios
接下来,执行以下命令以确保 httpd 上的 cgi 和 rewrite 模块已启用。
sudo httpd -M | grep 'cgi\|rewrite'
如果启用,您将看到如下输出:
最后,您现在可以使用下面的 htpasswd 命令更新 nagiosadmin 的默认密码。输入您的新密码并重复。使用-B参数,您将使用bcrypt,而不是MD5。
htpasswd -B /etc/nagios/passwd nagiosadmin
设置 Firewalld
现在您已经配置了 Nagios,在下一部分中您必须在 firewalld 中打开 HTTP 端口。
执行以下命令在firewalld中启用http服务。
sudo firewall-cmd --add-service=http --permanent
现在重新加载firewalld以使您的修改生效。
sudo firewall-cmd --reload
最后,执行以下命令来验证firewalld中启用列表的规则。确保您在防火墙规则中启用了 http 服务。
sudo firewall-cmd --list-all
登录Nagios监控
至此,您已完成并配置 Nagios 安装。在下一步中,您将通过从 Web 浏览器访问它来验证您的安装。
在本地计算机上,打开 Web 浏览器并访问服务器 IP 地址,后跟 /nagios 路径 (http://192.168.5.50/nagios)。当提示进行身份验证时,输入默认用户 Nagios admin 并输入您的密码,然后单击登录进行确认。
如果您拥有正确的 nagiosadmin 用户密码,您将看到 Nagios 管理仪表板,如下所示:
接下来,单击主机菜单以获取 Nagios 系统中的主机/机器列表。您应该看到您的 AlmaLinux 本地主机受到 Nagios 的监控。
现在单击服务菜单即可获取监控系统上的服务列表。在此示例中,您应该看到 Nagios 服务器的默认监控以及一些服务,例如 HTTP、SSH、进程监控、负载系统、登录用户以及分区详细信息。
现在你已经完成了nagios的安装。
结论
恭喜!您已完成Almalinux 9服务器上Nagios监控工具的安装。您已经安装了带有 httpd Web 服务器和 PHP 的 Nagios,还启用了 Nagios 身份验证并更改了 nagiosadmin 的默认密码。从这里,您现在可以通过 Nagios 插件和 Nagios NRPE 插件添加要监控的主机。