如何在 CentOS 8 / RHEL 8 上安装 Nagios

纳吉欧斯 是一款免费的开源监控工具,可帮助我们监控在 Windows、Linux、路由器和其他网络设备上运行的服务和应用程序。

借助 Nagios 图形界面,您可以监控基本服务(FTP、HTTP、SSH 等)和属性(系统负载、内存、CPU 使用率等)。

在这篇文章中,我们将看到如何在 CentOS 8 / RHEL 8 上安装 Nagios 以及如何使用 Nagios 插件.

本文档也适用于 CentOS 7 CentOS 6 Debian 10 Debian 9 Ubuntu 18.04 Ubuntu 16.04

先决条件

Nagios 需要 Web Server (httpd)、PHP、编译器和开发库。

在单个命令中安装所有软件包。

yum -y install httpd php gcc glibc glibc-common wget perl gd gd-devel unzip zip tar

创建一个用户和组,以允许通过 Web 界面执行外部命令。 将用户和 apache 用户添加到创建的组中。

useradd nagios groupadd nagcmd usermod -a -G nagcmd nagios usermod -a -G nagcmd apache

安装 Nagios

下载 Nagios 核心 从官方网站使用终端。

cd /tmp/ wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.5.tar.gz tar -zxvf nagios-4.4.5.tar.gz cd /tmp/nagios-4.4.5/

在您的系统上编译并安装 Nagios 核心。

./configure --with-nagios-group=nagios --with-command-group=nagcmd make all make install make install-init make install-config make install-commandmode

安装 Nagios Web 界面

使用以下命令安装 Nagios Web 界面。

make install-webconf

为 Nagios Web 界面创建一个用户帐户 (nagiosadmin)。 记住您为此用户设置的密码 – 您稍后将需要它。

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

重新开始 Apache 网络服务器。

systemctl restart httpd systemctl enable httpd

配置 Nagios

Nagios 将配置文件放在 /usr/local/nagios/etc 目录。 Nagios 的默认配置应该可以正常工作。

在继续之前,我们将只进行一项更改。

编辑 /usr/local/nagios/etc/objects/contacts.cfg 配置文件并将与 nagiosadmin 联系人定义关联的电子邮件地址更改为您的电子邮件地址以接收警报。

vi /usr/local/nagios/etc/objects/contacts.cfg

替换电子邮件地址字段以接收通知。

define contact {      contact_name            nagiosadmin             ; Short name of user     use                     generic-contact         ; Inherit default values from generic-contact template (defined above)     alias                   Nagios Admin            ; Full name of user     email                   [email protected] ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** } 

安装 Nagios 插件

下载 Nagios 插件/tmp 目录并解压。

cd /tmp wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz tar -zxvf nagios-plugins-2.2.1.tar.gz cd /tmp/nagios-plugins-2.2.1/

编译并安装 Nagios 插件。

./configure --with-nagios-user=nagios --with-nagios-group=nagios make make install

启动 Nagios

验证示例 Nagios 配置文件。

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

输出:

Nagios Core 4.4.5 Copyright (c) 2009-present Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 2019-08-20 License: GPL  Website: https://www.nagios.org Reading configuration data...    Read main config file okay...    Read object config files okay...  Running pre-flight check on configuration data...  Checking objects...         Checked 8 services.         Checked 1 hosts.         Checked 1 host groups.         Checked 0 service groups.         Checked 1 contacts.         Checked 1 contact groups.         Checked 24 commands.         Checked 5 time periods.         Checked 0 host escalations.         Checked 0 service escalations. Checking for circular paths...         Checked 1 hosts         Checked 0 service dependencies         Checked 0 host dependencies         Checked 5 timeperiods Checking global event handlers... Checking obsessive compulsive processor commands... Checking misc settings...  Total Warnings: 0 Total Errors:   0  Things look okay - No serious problems were detected during the pre-flight check 

如果没有错误,启动 Nagios 服务。

systemctl start nagios

在系统启动时启用 Nagios。

systemctl enable nagios

使用以下命令检查 Nagios 服务状态。

systemctl status nagios

SELinux

查看 SELinux 是否处于强制模式。

getenforce

将 SELinux 模式更改为 Permissive 或禁用。

setenforce 0

要使此 SELinux 模式永久化,请修改 /etc/selinux/config 并重新启动系统。

防火墙

创建防火墙规则以允许网络服务器通过防火墙访问。

firewall-cmd --permanent --add-service=http firewall-cmd --reload

访问 Nagios Web 界面

使用以下 URL 访问 Nagios Web 界面。

https://ip-add-re-ss/nagios/

您将需要使用您之前指定的用户名 (nagiosadmin) 和密码来访问 Nagios Web 界面。

Nagios 控制台将如下所示。

登录 Nagios Web 界面后,单击左侧窗格中的 Hosts 以查看 Nagios 监控的系统列表。

由于我们没有向 Nagios 添加任何主机,它只是监控本地主机本身。

单击左窗格中的“服务”以检查 Nagios 正在监视的任何服务的状态。

结论

在这篇文章中,您学习了如何在 CentOS 8 / RHEL 8 上安装 Nagios 并配置 Nagios 以在 Nagios 插件的帮助下监控服务。 此时,Nagios 监控服务器本身。 您还可以使用带有 NRPE 附加组件的 Nagios 监控远程 Linux 系统。