Nagios 安装完毕后,默认的配置文件在/usr/local/nagios/etc目录下:
1,cgi.cfg:用于定义cgi认证属性的配置文件
[root@Conan_ etc]# grep ^[^#[:space:]] cgi.cfg main_config_file=/usr/local/nagios/etc/nagios.cfg #告诉CGI主配置文件位置 physical_html_path=/usr/local/nagios/share #This is the physical path where the HTML files for Nagios are kept on your workstation or server url_html_path=/nagios #访问的uri show_context_help=0 use_pending_states=1 use_authentication=1 #是否启用认证授权功能 use_ssl_authentication=0 # authorized_for_system_information=nagiosadmin authorized_for_configuration_information=nagiosadmin authorized_for_system_commands=nagiosadmin authorized_for_all_services=nagiosadmin authorized_for_all_hosts=nagiosadmin authorized_for_all_service_commands=nagiosadmin authorized_for_all_host_commands=nagiosadmin default_statusmap_layout=5 default_statuswrl_layout=4 ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$ refresh_rate=90 result_limit=100 escape_html_tags=1 action_url_target=_blank notes_url_target=_blank lock_author_names=1
2,htpasswd.users:认证用户密码存储文件
3,resource.cfg:变量定义文件,在此文件中定义变量,由其他配置文件引用,如默认的$USER1$
4,nagios.cfg:nagios主配置文件
log_file=/usr/local/nagios/var/nagios.log:定义日志文件路径
cfg_file=。。。:引用对象配置文件需要在此处添加路径(This directive is used to specify a directory which contains object configuration files )
object_cache_file=/usr/local/nagios/var/objects.cache:(This directive is used to specify a file in which a cached copy of object definitions should be stored:所有对象的缓存备份文件)
status_file=/usr/local/nagios/var/status.dat:状态文件(This is the file that Nagios uses to store the current status, comment, and downtime information)
5,objects/commands.cfg :文件默认存在,不需要修改,新的命令在此文件中添加
define command{
command_name check-host-alive
command_line $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
}
check-host-alive:命令名字
$USER1$:在resource.cfg中定义
check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5:启用libexec/check_ping脚本,并定义后面带的参数。(注:3000默认单位是ms)
# “-w 3000.0,80%”中“-w”说明后面的一对值对应的是“WARNING”状态,“80%”是其临界值。
# “-c 5000.0,100%”中“-c”说明后面的一对值对应的是“CRITICAL”,“100%”是其临界值。
# “-p 5”说明每次探测发送5个包。
此处此文件中新增check_nrpe
# 'check_nrpe' command definition
define command{
command_name check_nrpe # 定义命令名称为check_nrpe,在新建的services.cfg文件中要使用这个命令名称.
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ #这是定义实际运行的插件程序. 这个命令行用法使用命令check_nrpe �Ch查看.
}
6,objects/services.cfg:默认不存在,需要新建,在此文件中定义需要被监控的主机的resources
define service{
use local-service # 引用local-service定义属性值,该值在templates.cfg中定义
host_name Nagios-Conan3 #定义被监控的主机名
service_description check-host-alive
check_command check-host-alive #定义了使用监控的命令,在commands.cfg中定义
}
define service{
use local-service
host_name Nagios-Conan3
service_description Current Load
check_command check_nrpe!check_load
}
注:check_nrpe!check_load--之前在commands.cfg 中创建check_nrpe 的命令定义,此处定义了在被监控主机Nagios-Conan3上需要执行的监控命令。
7,objects/hosts.cfg:需要创建,指定了被监控主机的地址和名字等属性信息
define host{
use linux-server
host_name Nagios-Conan3
address 192.168.1.129
}
define hostgroup{
hostgroup_name linux servers #此处注意不能和localhost.cfg内定义的名字相同
alias Linux Servers1
members Nagios-Conan3
}
8,objects/templates.cfg :nagios主要用于监控主机资源以及服务,在nagios配置中称为对象,为了不必重复定义一些监控对象,nagios引入了一个模板配置文件,将一些共性的属性定义成模板,便于多次引用。此文件每个参数后面都有注释。
9,objects/localhost.cfg:定义了在本机上监控的服务
10,objects/contacts.cfg :定义了联系人和联系人组
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}
11,objects/timeperiods.cfg :在此文件中定义需要监控的时间段