Nagios 简明教程

Nagios - Configuration

在上一章中,我们已经了解了 Nagios 的安装。在本章中,让我们详细了解其配置。

In the previous chapter, we have seen the installation of Nagios. In this chapter, let us understand its configuration in detail.

Nagios 的配置文件位于 /usr/local/nagios/etc 中。这些文件如下图所示 −

The configuration files of Nagios are located in /usr/local/nagios/etc. These files are shown in the screenshot given below −

nagios configuration

让我们现在了解每个文件的用途 −

Let us understand the importance of each file now −

nagios.cfg

这是 Nagios 核心配置文件。此文件包含 Nagios 日志文件、主机和服务状态更新间隔、锁定文件和 status.dat 文件的位置。在此文件中定义了运行实例的 Nagios 用户和组。它包含所有单个对象配置文件的路径,如命令、联系人、模板等。

This is the main configuration file of Nagios core. This file contains the location of log file of Nagios, hosts and services state update interval, lock file and status.dat file. Nagios users and groups on which the instances are running are defined in this file. It has path of all the individual object config files like commands, contacts, templates etc.

cgi.cfg

默认情况下,Nagios 的 CGI 配置文件名为 cgi.cfg。它告诉 CGI 在哪里找到主配置文件。CGI 将读取主配置和主机配置文件来获取它们可能需要的任何其他数据。它包含所有用户和组信息以及它们的权限。它还包含 Nagios 所有前端文件的路径。

By default, the CGI configuration file of Nagios is named cgi.cfg. It tells the CGIs where to find the main configuration file. The CGIs will read the main and host config files for any other data they might need. It contains all the user and group information and their rights and permissions. It also has the path for all frontend files of Nagios.

resource.cfg

你可以在此文件中定义 $USERx$ 宏,然后可以在主机配置文件中的命令定义中使用它们。$USERx$ 宏对于存储敏感信息(如用户名、密码等)很有用。

You can define $USERx$ macros in this file, which can in turn be used in command definitions in your host config file(s). $USERx$ macros are useful for storing sensitive information such as usernames, passwords, etc.

它们在指定插件和事件处理程序路径时也很方便 - 如果你决定将来将插件或事件处理程序移动到其他目录,你只需更新一两个 $USERx$ 宏,而无需修改许多命令定义。资源文件还可以用来存储外部数据源(如 MySQL)的配置指令。

They are also handy for specifying the path to plugins and event handlers - if you decide to move the plugins or event handlers to a different directory in the future, you can just update one or two $USERx$ macros, instead of modifying a lot of command definitions. Resource files may also be used to store configuration directives for external data sources like MySQL.

resource
external data sources

objects 目录中的配置文件用于定义命令、联系人、主机、服务等。

The configuration files inside objects directory have are used to define commands, contacts, hosts, services etc.

commands.cfg

这个配置文件为您提供了一些示例命令定义,您可以在主机、服务和联系人定义中引用它们。这些命令用于检查和监视主机和服务。您可以在 Linux 控制台上本地运行这些命令,您还可以获取所运行命令的输出。

This config file provides you with some example command definitions that you can refer in host, service, and contact definitions. These commands are used to check and monitor hosts and services. You can run these commands locally on a Linux console where you will also get the output of the command you run.

Example

define command {
   command_name check_local_disk
   command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
}

define command {
   command_name check_local_load
   command_line $USER1$/check_load -w $ARG1$ -c $ARG2$
}

define command {
   command_name check_local_procs
   command_line $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
}

contacts.cfg

此文件包含 Nagios 的联系人信息和组信息。默认情况下,已存在一个联系人 Nagios admin。

This file contains contacts and groups information of Nagios. By default, one contact is already present Nagios admin.

Example

define contact {
   contact_name nagiosadmin
   use generic-contact
   alias Nagios Admin
   email avi.dunken1991@gmail.com
}

define contactgroup {
   contactgroup_name admins
   alias Nagios Administrators
   members nagiosadmin
}

templates.cfg

此配置文件为您提供了一些示例对象定义模板,其他配置文件中的其他主机、服务、联系人等定义引用了这些模板。

This config file provides you with some example object definition templates that are referred by other host, service, contact, etc. definitions in other config files.

timeperiods.cfg

此配置文件为您提供了一些示例时间段定义,您可以在主机、服务、联系人以及依赖项定义中引用它们。

This config file provides you with some example timeperiod definitions that you can refer in host, service, contact, and dependency definitions.