nagios学习笔记【3】-- nagios的快速配置
2012-07-10 21:47
519 查看
在安装完nagios之后,首先需要做的就是配置。配置工作主要包括两部分:
(1)监控服务器的配置;
(2)被监控服务器的配置。
在不准备对被监控服务器的内部属性进行监控时,其实只需要配置监控服务器就可以了。这里,我就主要对监控服务器的配置方法进行说明。
首先,假定nagios已经安装在了/usr/local/nagios目录中。在这个目录中有两个文件夹很重要:
(1)libexec:存放了nagios的所有插件;
(2)etc:存放了nagios的所有配置文件;
在对nagios监控服务器进行配置时,主要是在/usr/local/nagios/etc目录中进行操作。
在进行配置之前,大家需要对若干配置文件的作用有一定的了解,说明如下:
./etc/cgi.cfg:用于定义浏览器对nagios操作,比如权限控制等;
./etc/nagios.cfg:用于定义控制nagios行为;
./etc/resource.cfg:资源配置文件,用于定义插件路径,一般不需修改;
./etc/objects目录:存放监控对象配置文件,此目录下默认有下面几个文件:
commands.cfg
命令定义配置文件
contacts.cfg
定义联系人列表
timeperiods.cfg
定义时间监控模板
templates.cfg
定义各种模板,可以是主机模板、联系人模板、监控服务模板等
localhost.cfg
用于定义linux监控设备
windows.cfg
用于定义windows监控设备
switch.cfg 用于定义交换机,路由器等监控设备
printer.cfg
用于定义打印机监控设备
现在,我们开始对nagios进行快速配置。
(1)配置被监控服务的主机信息(在./etc/objects/localhost.cfg文件中进行操作)
下面是个比较全的主机模板,可以在/usr/local/nagios/etc/objects/templates.cfg中找到适合的模板
define
host{
use model_host //定义用的模板机
host_name host_name(*) //定义主机名,可起任意名字
alias alias(*) //定义主机别名
display_name display_name // 定义显示名字
address address(*) //主机名对应的ip 地址
parents host_names //定义父节点
hostgroups hostgroup_names //定义主机组名
check_command command_name //检查主机状态的命令
initial_state [o,d,u] //初始化状态
max_check_attempts #(*) //当检查命令返回值不是“OK”时最大重试次数
check_interval # //#分钟进行一次检查
retry_interval # //重试间隔时间
active_checks_enabled [0/1] //主动监控开关(1开0闭)
passive_checks_enabled [0/1] //被动监控开关
check_period timeperiod_name(*) //主机状态检查的时间段
obsess_over_host [0/1] //是否启用主机操作系统探测
check_freshness [0/1] //是否启用 freshness 检查。freshness 检查是对于启用被动检查模式的主机而言的,其作用是定期检查主机报告的状态信息,如果该状态信息已经过期,freshness 将会强制做主机检查。freshness_threshold
#
event_handler command_name
event_handler_enabled [0/1] //主机事件处理是否激活
low_flap_threshold #
high_flap_threshold #
flap_detection_enabled [0/1]
flap_detection_options [o,d,u]
process_perf_data [0/1]
retain_status_information [0/1]
retain_nonstatus_information [0/1]
contacts contacts(*) //发送报警通知给谁
contact_groups contact_groups(*) //发送通知给哪个报警组
notification_interval #(*) //主机状态通知功能激活
first_notification_delay #
notification_period timeperiod_name(*) //发送通知的时间段
notification_options [d,u,r,f,s] //定义那些情况下发送通知
notifications_enabled [0/1] //发送通告开关
stalking_options [o,d,u]
notes note_string
notes_url url
action_url url
icon_image image_file //定义主机图标
icon_image_alt alt_string
vrml_image image_file
statusmap_image image_file
2d_coords x_coord,y_coord //定义图标在网页中显示的二维坐标
3d_coords x_coord,y_coord,z_coord //定义图标在网页中显示的三维坐标
...
}
定义样例:
define host{
host_name web1
alias web1
address 192.168.1.254
parents router1
check_command check-host-alive
check_interval 5
retry_interval 1
max_check_attempts 5
check_period 24x7
process_perf_data 0
retain_nonstatus_information 0
contact_groups router-admins
notification_interval 30
notification_period 24x7
notification_options d,u,r
}
(2)配置主机组(还是在./etc/objects/localhost.cfg文件中进行操作)
样例:
define hostgroup{ //定义主机组
hostgroup_name tianway.net ; //定义主机组的名字
alias Linux Server ;//别名
members 192.168.0.2,192.168.0.3,192.168.0.4 ; //组成员,使用逗号分隔
}
(3)定义监控服务项(编辑./etc/objects/localhost.cfg文件)
哪台设备要监控什么服务就在那个服务定义里的host_name中添加在主机定义中的主机名就行,多台设备之间用逗号隔开,下面文件已经给出的部分常用的监控项的定义:
define service{ //定义监控ping
use local-service
host_name *
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{ //定义监控根分区
use local-service
host_name web1
service_description 根分区
check_command check_local_disk!20%!10%!/
}
注意:在check_command字段中,如果需要使用一些自定义的命令,那必须编辑./etc/objects/command.cfg文件,在下一章的nrpe插件配置中,我们就会对该文件进行操作。
好了,完成以上编辑操作后,你可以检验一下配置是否有误,命令如下:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果无误,那可以重启nagios服务,然后就可以看到新添加的配置服务了。
(1)监控服务器的配置;
(2)被监控服务器的配置。
在不准备对被监控服务器的内部属性进行监控时,其实只需要配置监控服务器就可以了。这里,我就主要对监控服务器的配置方法进行说明。
首先,假定nagios已经安装在了/usr/local/nagios目录中。在这个目录中有两个文件夹很重要:
(1)libexec:存放了nagios的所有插件;
(2)etc:存放了nagios的所有配置文件;
在对nagios监控服务器进行配置时,主要是在/usr/local/nagios/etc目录中进行操作。
在进行配置之前,大家需要对若干配置文件的作用有一定的了解,说明如下:
./etc/cgi.cfg:用于定义浏览器对nagios操作,比如权限控制等;
./etc/nagios.cfg:用于定义控制nagios行为;
./etc/resource.cfg:资源配置文件,用于定义插件路径,一般不需修改;
./etc/objects目录:存放监控对象配置文件,此目录下默认有下面几个文件:
commands.cfg
命令定义配置文件
contacts.cfg
定义联系人列表
timeperiods.cfg
定义时间监控模板
templates.cfg
定义各种模板,可以是主机模板、联系人模板、监控服务模板等
localhost.cfg
用于定义linux监控设备
windows.cfg
用于定义windows监控设备
switch.cfg 用于定义交换机,路由器等监控设备
printer.cfg
用于定义打印机监控设备
现在,我们开始对nagios进行快速配置。
(1)配置被监控服务的主机信息(在./etc/objects/localhost.cfg文件中进行操作)
下面是个比较全的主机模板,可以在/usr/local/nagios/etc/objects/templates.cfg中找到适合的模板
define
host{
use model_host //定义用的模板机
host_name host_name(*) //定义主机名,可起任意名字
alias alias(*) //定义主机别名
display_name display_name // 定义显示名字
address address(*) //主机名对应的ip 地址
parents host_names //定义父节点
hostgroups hostgroup_names //定义主机组名
check_command command_name //检查主机状态的命令
initial_state [o,d,u] //初始化状态
max_check_attempts #(*) //当检查命令返回值不是“OK”时最大重试次数
check_interval # //#分钟进行一次检查
retry_interval # //重试间隔时间
active_checks_enabled [0/1] //主动监控开关(1开0闭)
passive_checks_enabled [0/1] //被动监控开关
check_period timeperiod_name(*) //主机状态检查的时间段
obsess_over_host [0/1] //是否启用主机操作系统探测
check_freshness [0/1] //是否启用 freshness 检查。freshness 检查是对于启用被动检查模式的主机而言的,其作用是定期检查主机报告的状态信息,如果该状态信息已经过期,freshness 将会强制做主机检查。freshness_threshold
#
event_handler command_name
event_handler_enabled [0/1] //主机事件处理是否激活
low_flap_threshold #
high_flap_threshold #
flap_detection_enabled [0/1]
flap_detection_options [o,d,u]
process_perf_data [0/1]
retain_status_information [0/1]
retain_nonstatus_information [0/1]
contacts contacts(*) //发送报警通知给谁
contact_groups contact_groups(*) //发送通知给哪个报警组
notification_interval #(*) //主机状态通知功能激活
first_notification_delay #
notification_period timeperiod_name(*) //发送通知的时间段
notification_options [d,u,r,f,s] //定义那些情况下发送通知
notifications_enabled [0/1] //发送通告开关
stalking_options [o,d,u]
notes note_string
notes_url url
action_url url
icon_image image_file //定义主机图标
icon_image_alt alt_string
vrml_image image_file
statusmap_image image_file
2d_coords x_coord,y_coord //定义图标在网页中显示的二维坐标
3d_coords x_coord,y_coord,z_coord //定义图标在网页中显示的三维坐标
...
}
定义样例:
define host{
host_name web1
alias web1
address 192.168.1.254
parents router1
check_command check-host-alive
check_interval 5
retry_interval 1
max_check_attempts 5
check_period 24x7
process_perf_data 0
retain_nonstatus_information 0
contact_groups router-admins
notification_interval 30
notification_period 24x7
notification_options d,u,r
}
(2)配置主机组(还是在./etc/objects/localhost.cfg文件中进行操作)
样例:
define hostgroup{ //定义主机组
hostgroup_name tianway.net ; //定义主机组的名字
alias Linux Server ;//别名
members 192.168.0.2,192.168.0.3,192.168.0.4 ; //组成员,使用逗号分隔
}
(3)定义监控服务项(编辑./etc/objects/localhost.cfg文件)
哪台设备要监控什么服务就在那个服务定义里的host_name中添加在主机定义中的主机名就行,多台设备之间用逗号隔开,下面文件已经给出的部分常用的监控项的定义:
define service{ //定义监控ping
use local-service
host_name *
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{ //定义监控根分区
use local-service
host_name web1
service_description 根分区
check_command check_local_disk!20%!10%!/
}
注意:在check_command字段中,如果需要使用一些自定义的命令,那必须编辑./etc/objects/command.cfg文件,在下一章的nrpe插件配置中,我们就会对该文件进行操作。
好了,完成以上编辑操作后,你可以检验一下配置是否有误,命令如下:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果无误,那可以重启nagios服务,然后就可以看到新添加的配置服务了。
相关文章推荐
- linux学习笔记-nagios监控的简单配置
- Nagios学习笔记之(三)配置详解
- Linux学习笔记:Nagios的配置
- nagios学习笔记【2】--nagios在Fedora linux中的快速安装
- Log4j 学习笔记(二)Log4j快速入门配置文件log4j.properties
- bootstrap学习心得笔记--第一节【bootstrap配置】
- [Swift]:快速学习笔记
- Duwamish配置持久化学习笔记
- Spark1.5.1学习笔记(二)IDE开发环境配置
- struts2系列学习笔记(4)---------------Action的多样化配置之二
- zynq-7000学习笔记(十)——Linux下通过UIO配置FAST corner寄存器
- JAVA 学习笔记 - 【环境变量配置】
- 【linux学习笔记】samba在RHEL7上配置
- ElasticSearch学习笔记 安装 配置
- 01、刘媛媛《普通人快速崛起31节修炼课》 第一讲 个人学习笔记
- maven学习笔记2 依赖的配置和依赖的范围
- mongodb 学习笔记 06 -- mongod配置文件
- Spring Boot学习笔记:(二)常规属性配置
- Djang学习笔记3视图和URL配置
- yii 学习笔记七、数据库连接配置