适用于 Linux 的 Nagios 3.0 快速入门指南 – 概述、安装和配置

网友投稿 688 2022-05-29

让我们了解 Nagios 的概述、安装和配置,这是一个强大的主机和服务开源监控解决方案

一、nagios 概述

二、在 Linux 上安装 nagios 的 8 个步骤:

下载 nagios 和插件

注意先决条件

为 nagios 创建用户和组

安装 nagios

配置网页界面

编译安装nagios插件

启动 Nagios

登录网页界面

三、配置文件概述

一、Nagios 概述

.

Nagios 是一个主机和服务监控工具。以下是 nagios 的一些功能。

监控服务器、交换机、路由器、防火墙、电源等设备。

监控磁盘空间、cpu使用率、内存使用率、设备温度、HTTP、Mail、SSH等服务。

Nagios 几乎可以监控任何东西。例如主机、服务、数据库、应用程序等。

Nagios 有一个可扩展的插件接口,用于监控用户定义的服务。Nagios 有很多插件可用。

当问题发生并得到解决时,它可以发送各种通知(电子邮件、寻呼机等)。

用于查看当前状态、通知、问题历史、日志文件等的 Web 界面。

以下是 nagios Web 仪表板的部分屏幕截图:

图: Nagios Web UI

二、在 Linux 上安装 nagios 的 8 个步骤:

1. 下载nagios和插件

从Nagios.org下载以下文件并移至 /home/downloads

nagios-3.0.1.tar.gz

nagios-plugins-1.4.11.tar.gz

2. 注意先决条件

通过从浏览器验证确保 apache 正在服务器上运行:http://localhost

验证是否安装了 gcc

[root@localhost]# rpm -qa | grep gcc gcc-3.4.6-8 compat-gcc-32-3.2.3-47.3 libgcc-3.4.6-8 compat-libgcc-296-2.96-132.7.2 compat-gcc-32-c++-3.2.3-47.3 gcc-c++-3.4.6-8

验证是否安装了GD

[root@localhost]# rpm -qa gd gd-2.0.28-5.4E

3.为nagios创建用户和组

[root@localhost]# useradd nagios [root@localhost]# passwd nagios [root@localhost]# groupadd nagcmd [root@localhost]# usermod -G nagcmd nagios [root@localhost]# usermod -G nagcmd apache

4.安装nagios

[root@localhost]# tar xvf nagios-3.0.1.tar.gz [root@localhost]# cd nagios-3.0.1 [root@localhost]# ./configure --with-command-group=nagcmd [root@localhost]# make all [root@localhost]# make install [root@localhost]# make install-config [root@localhost]# make install-commandmode

以下是您可以传递给 ./configure 以自定义安装的一些其他参数。我只使用了 --with-command-group,如上所示。

--prefix /opt/nagios Where to put the Nagios files --with-cgiurl /nagios/cgi-bin Web server url where the cgi's will be available --with-htmurl /nagios Web server url where nagios will be available --with-nagios-user nagios user account under which Nagios will run --with-nagios-group nagios group account under which Nagios will run --with-command-group nagcmd group account which will allow the apache user to submit commands to Nagios

在配置输出的末尾,它将显示如下所示的摘要:

*** Configuration summary for nagios 3.0.1 05-28-2012 ***: General Options: ------------------------- Nagios executable: nagios Nagios user/group: nagios,nagios Command user/group: nagios,nagcmd Embedded Perl: no Event Broker: yes Install ${prefix}: /usr/local/nagios Lock file: ${prefix}/var/nagios.lock Check result directory: ${prefix}/var/spool/checkresults Init directory: /etc/rc.d/init.d Apache conf.d directory: /etc/httpd/conf.d Mail program: /bin/mail Host OS: linux-gnu Web Interface Options: ------------------------ HTML URL: http://localhost/nagios/ CGI URL: http://localhost/nagios/cgi-bin/ Traceroute (used by WAP): /bin/traceroute

5. 配置网页界面。

[root@localhost]# make install-webconf [root@localhost# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin New password: Re-type new password: Adding password for user nagiosadmin

6.编译安装nagios插件

[root@localhost]# tar xvf nagios-plugins-1.4.11.tar.gz [root@localhost]# cd nagios-plugins-1.4.11 [root@localhost]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios [root@localhost]# make [root@localhost]# make install

注意:在 Red Hat 上,上面提到的 ./configure 命令不起作用并且在显示消息时挂起:检查 redhat spopen 问题...将 –enable-redhat-pthread-workaround 添 加到 ./configure 命令中作为解决上述问题的方法如下所示。

[root@localhost]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround

7. 启动 Nagios

将 nagios 添加到启动例程中:

[root@localhost]# chkconfig --add nagios [root@localhost]# chkconfig nagios on

验证以确保 nagios 配置文件中没有错误:

[root@localhost]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check

启动 nagios

[root@localhost]# service nagios start Starting nagios: done.

8. 登录网页界面

Nagios Web URL:http://localhost/nagios/

使用从上面的步骤#5 创建的用户 ID、密码。

三、配置文件概述

.

要修改的第一个配置是将 /usr/local/nagios/etc/objects/contacts.cfg 文件中的电子邮件地址的默认值更改为您的电子邮件地址。

以下是位于 /usr/local/nagios/etc 下的三个主要配置文件

nagios.cfg – 这是主要的 Nagios 配置文件,可以在其中定义许多控制 nagios 的全局参数。

cgi.cfg – 该文件包含 nagios Web 界面的配置信息。

resource.cfg – 如果您必须将一些敏感信息(用户名、密码等)传递给插件以监控特定服务,您可以在此处定义它们。此文件只能由 nagios 用户和组读取。

以下是/usr/local/nagios/etc/objects目录下的其他配置文件:

contacts.cfg:所有需要通知的联系人都应该在这里定义。您可以指定姓名、电子邮件地址、他们需要接收的通知类型以及此特定联系人应接收通知的时间段等。

commands.cfg – 所有检查服务的命令都在此处定义。您可以在命令执行时使用 $HOSTNAME$ 和 $HOSTADDRESS$ 宏,它们将自动替换相应的主机名或主机 IP 地址。

timeperiods.cfg – 定义时间段。例如,如果您希望仅在营业时间内监控服务,请定义一个称为营业时间的时间段并指定您想要监控的时间。

templates.cfg – 具有相似特征的多个主机或服务定义可以使用一个模板,其中可以定义所有共同特征。使用模板可以节省时间。

适用于 Linux 的 Nagios 3.0 快速入门指南 – 概述、安装和配置

localhost.cfg – 定义对本地主机的监控。这是 nagios 安装附带的示例配置文件,您可以将其用作基线来定义要监视的其他主机。

printer.cfg – 打印机的示例配置文件

switch.cfg –交换机的示例配置文件

windows.cfg – Windows 机器的示例配置文件

Linux web前端

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:JVM笔记六-堆区知识之对象生命周期和GC的关系
下一篇:(精华)2020年8月31日 计算机操作系统 IO概念和五种IO模型
相关文章