Detailed explanation of Nagios server-side configuration files
For details on Nagios server-side installation and deployment, see: http://www.cnblogs.com/ginvip/p/6505948.html
Nagios is mainly used to monitor one or more local hosts and various remote information, including local resources and external services. The default Nagios configuration does not have any monitoring content, just some template files. If you want Nagios to provide services, you must modify the configuration file and add hosts and services to be monitored, which will be described in detail below.
Introduction to the default configuration file
After Nagios is installed, the default configuration file is in the /usr/local/nagios/etc directory.
1 2 3 4 5 6 7 |
|
The meaning of each file or directory is as shown in the following table:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Relationships between configuration files
Several definitions involved in the nagios configuration process include: host, host group, service, service group, contact, contact group, monitoring time, monitoring command, etc. From these definitions, it can be seen that among the various configuration files of nagios They are related to each other and refer to each other.
To successfully configure a nagios monitoring system, you must understand the dependencies and dependent relationships between each configuration file. The most important are four points:
First: Define which hosts, host groups, services and service groups are monitored;
Second: Define what command should be used to implement this monitoring;
Third: Define the monitoring time period;
Fourth: Define the contacts and contact groups to be notified when there is a problem with the host or service.
Configure Nagios
In order to explain the problem more clearly and to facilitate maintenance, it is recommended to create independent configuration files for each nagios definition object:
- Create hosts.cfg file to define hosts and host groups
- Create services.cfg file to define services
- Use the default contacts.cfg file to define contacts and contact groups
- Use the default commands.cfg file to define commands
- Use the default timeperiods.cfg to define the monitoring time period
- Use the default templates.cfg file as the resource reference file
timeperiods.cfg file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
resource.cfg文件
resource.cfg是nagios的变量定义文件,文件内容只有一行:
1 |
|
其中,变量$USER1$指定了安装nagios插件的路径,如果把插件安装在了其它路径,只需在这里进行修改即可。需要注意的是,变量必须先定义,然后才能在其它配置文件中进行引用。
commands.cfg文件
此文件默认是存在的,无需修改即可使用,当然如果有新的命令需要加入时,在此文件进行添加即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
hosts.cfg文件
此文件默认不存在,需要手动创建,hosts.cfg主要用来指定被监控的主机地址以及相关属性信息,根据实验目标配置如下:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
注意:在/usr/local/nagios/etc/objects 下默认有localhost.cfg和windows.cfg 这两个配置文件,localhost.cfg 文件是定义监控主机本身的,windows.cfg文件是定义windows 主机的,其中包括了对host 和相关services 的定义。所以在本次实验中,将直接在localhost.cfg 中定义监控主机(Nagios-Server),在windows.cfg中定义windows 主机(Nagios-Windows)。根据自己的需要修改其中的相关配置,详细如下:
localhost.cfg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
services.cfg文件
此文件默认也不存在,需要手动创建,services.cfg文件主要用于定义监控的服务和主机资源,例如监控http服务、ftp服务、主机磁盘空间、主机系统负载等等。Nagios-Server和Nagios-Windows相关服务已在相应的配置文件中定义,所以这里只需要定义Nagios-Linux相关服务即可,这里只定义一个检测是否存活的服务来验证配置文件的正确性,其他服务的定义将在后面讲到。
1 2 3 4 5 6 |
|
contacts.cfg文件
contacts.cfg是一个定义联系人和联系人组的配置文件,当监控的主机或者服务出现故障,nagios会通过指定的通知方式(邮件或者短信)将信息发给这里指定的联系人或者使用者。
1 2 3 4 5 6 7 8 9 10 11 |
|
timeperiods.cfg文件
此文件只要用于定义监控的时间段,下面是一个配置好的实例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
cgi.cfg文件
此文件用来控制相关cgi脚本,如果想在nagios的web监控界面执行cgi脚本,例如重启nagios进程、关闭nagios通知、停止nagios主机检测等,这时就需要配置cgi.cfg文件了。
由于nagios的web监控界面验证用户为david,所以只需在cgi.cfg文件中添加此用户的执行权限就可以了,需要修改的配置信息如下:
1 2 3 4 5 6 7 8 |
|
nagios.cfg文件
nagios.cfg默认的路径为/usr/local/nagios/etc/nagios.cfg,是nagios的核心配置文件,所有的对象配置文件都必须在这个文件中进行定义才能发挥其作用,这里只需将对象配置文件在Nagios.cfg文件中进行引用即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
验证Nagios配置文件的正确性
Nagios 在验证配置文件方面做的非常到位,只需通过一个命令即可完成:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
|
Nagios提供的这个验证功能非常有用,在错误信息中通常会打印出错误的配置文件以及文件中的哪一行,这使得nagios的配置变得非常容易,报警信息通常是可以忽略的,因为一般那些只是建议性的。
看到上面这些信息就说明没问题了,然后启动Nagios 服务。
参考文章:http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html