如何在 CentOS 7 上安装 Nagios 4.0.8

Nagios 是最流行的开源监控系统。 Nagios 将监控服务器、交换机、应用程序和服务。 它会在出现问题时向系统管理员发出警报,并在问题得到纠正时发出警报。
在本教程中,我们将学习如何在 CentOS 7/RHEL 7 上安装和配置 Nagios 4.0.8。要安装 Nagios,我们将使用其稳定的源代码,该源代码可在 Nagios 站点上获得。

安装所需的包和依赖项

首先,安装 Apache 和 PHP:

# yum install httpd php php-cli gcc glibc glibc-common gd gd-devel net-snmp wget -y

现在,启动 httpd 服务:

# systemctl start httpd

创建 Nagios 用户和组

创建一个新的 Nagios 用户帐户并为此帐户设置密码:

# useradd nagios # passwd nagios

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

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

安装 Nagios 服务和 Nagios 插件

安装所需的依赖项并添加用户帐户后。 让我们从 Nagios 核心安装开始。 首先从官网下载Nagios源代码:

# cd /opt/ # wget https://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz # tar xzf nagios-4.0.8.tar.gz # cd nagios-4.0.8 # ./configure --with-command-group=nagcmd # make all # make install # make install-init # make install-config # make install-commandmode # make install-webconf

安装 Nagios 服务后,从 Nagios 官方页面下载 Nagios 插件:

# cd /opt # wget https://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz # tar xzf nagios-plugins-2.0.3.tar.gz # cd nagios-plugins-2.0.3 # ./configure --with-nagios-user=nagios --with-nagios-group=nagios # make # make install

配置 Apache 验证

现在,需要为用户 nagios 设置 apache 身份验证 admin:

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

这次重启后 Apache 服务:

# systemctl restart httpd

启动 Nagios 服务

首先,验证 Nagios 安装是否正确:

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

示例输出:

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg  Nagios Core 4.0.8 Copyright (c) 2009-present Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 08-12-2014 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 # chkconfig --add nagios # chkconfig nagios on

从网络浏览器访问 Nagios

使用 URL https://nagios-server-ip/nagios 打开 Nagios 管理员控制台并输入用户名作为 nagiosadmin 和我们在前面步骤中创建的密码。

就是这样。 干杯!