nagios安装完毕之后,它的配置文件在/usr/local/nagios/etc/下,每个配置文件都有不同的用途,如下是各个配置文件的含义:
一,配置文件相关了解 [iyunv@test1~]# cd /usr/local/nagios/etc [iyunv@test1 etc]# ls -l -rw-rw-r-- 1 nagios nagios 11408 08-30 11:55 cgi.cfg (CGI配置文件) -rw-r--r-- 1 root root 26 08-30 11:56 htpasswd.users (Apache的验证密码文件) -rw-rw-r-- 1 nagios nagios 43776 08-30 11:55 nagios.cfg (主配置文件) drwxrwxr-x 2 nagios nagios 4096 08-30 11:55 objects (对象定义文件目录) -rw-rw---- 1 nagios nagios 1340 08-30 11:55 resource.cfg (资源配置文件) 我们修要修改的的是nagios.cfg 和 objects 目录下的文件,来检测主机是否存活。
二,主配置文件nagios.cfg 主配置文件的内容很多,对于这个版本,我们需要修改和添加的主要是对象配置文件,即:cfg_file= cfg_file=/usr/local/nagios/etc/objects/commands.cfg (命令定义文件) cfg_file=/usr/local/nagios/etc/objects/contacts.cfg (联系人信息定义文件) cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg (添加此行联系人组定义文件) cfg_file=/usr/local/nagios/etc/objects/hosts.cfg (添加此行 主机定义文件) cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg (添加此行 主机组定义文件) cfg_file=/usr/local/nagios/etc/objects/services.cfg (添加此行 服务定义文件) cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg (时间周期定义文件) cfg_file=/usr/local/nagios/etc/objects/templates.cfg # Definitions for monitoring the local (Linux) host #cfg_file=/usr/local/nagios/etc/objects/localhost.cfg (注释掉此行)
主机定义文件的配置 [iyunv@test1 etc]# vi objects/hosts.cfg define host{ host_name test1.test.com
alias test1
address 192.168.87.129
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 sagroup notification_interval 30 notification_period 24x7 notification_options d,u,r }
主机组定义文件的配置 [iyunv@test1 etc]# vi objects/hostgroups.cfg - define hostgroup {
hostgroup_name nagios
alias nagios
members test1.test.com
}
服务定义文件的配置 [iyunv@test1 etc]# vi objects/services.cfg define service {
host_name test1.test.com
service_description check-host-alive
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups sagroup
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check-host-alive
}
~
联系组定义文件配置 [iyunv@test1 etc]# vi objects/contactgroups.cfg define contactgroup { contactgroup_name sagroup alias system administrator group members nagiosadmin }
.修改目录的所有者 [iyunv@test1 etc]# chown -R nagios:nagios objects/
检测配置文件是否正确 [iyunv@test1 etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg Total Warnings: 0 Total Errors: 0
测试 http://192.168.87.129/nagios/
三,其他的配置文件讲解
1,templates.cfg配置
主要用于监控主机资源和服务
(1) 定义联系人
define contact{
name generic-contact 联系人模板的名字
service_notification_period 24x7 ; 服务警告时间段
host_notification_period 24x7 ; 主机警告时间段
service_notification_options w,u,c,r,f,s; w:警告,u:未知状态,c:紧急状态,r:恢复状态,
host_notification_options d,u,r,f,s d:宕机
service_notification_commands notify-service-by-email, notify-service-by-sms;
host_notification_commands notify-host-by-email,notify-host-by-sms;
当主机或者是服务发生故障的时候,通过邮件和短信方式发送提醒
register 0
}
(2)主机定义 define host{
name linux-server ; 主机模板名
use generic-host ; use在这里是引用的意思
check_period 24x7 ;
check_interval 5 ; 多久检查一次,默认是5分钟
retry_interval 1 ;
max_check_attempts 10 ;
check_command check-host-alive ;
notification_period workhours ; 发送通知的时间段
notification_interval 120 ;
notification_options d,u,r ;
contact_groups admins ; check_command check-host-alive ;检查主机是否正常的命令
register 0 ;
} (3)服务定义 define service{
name local-service ;
use generic-service ;
max_check_attempts 4 ;
normal_check_interval 5 ;
retry_check_interval 1 ;
notifications_enabled 1 ;
event_handler_enabled 1 ;
flap_detection_enabled 1 ;
failure_prediction_enabled 1 ;
process_perf_data 1 ;
retain_status_information 1 ;
retain_nonstatus_information 1 ;
is_volatile 0 ;
check_period 24x7 ;
max_check_attempts 3 ;
normal_check_interval 10 ;
retry_check_interval 2 ;
contact_groups admins ;
notification_options w,u,c,r ;
notification_interval 60 ;
notification_period 24x7 ;
register 0 ;
notes_url /nagios/cgi-bin/show.cgi?host=$HOSTNAME$&service=$SERVICEDESC$
}
2,resource.cfg配置 这是一个变量定义文件,只有一行内容 $USER1$=/usr/local/nagios//libexec 很显然,这样指定了nagios插件的路径
3,commands.cfg配置 这里用到了宏的定义,也就是继承的思想。这里的原理就是调用nagios插件进行检测监控
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
define command{
command_name check_ftp
command_line $USER1$/check_ftp -H $HOSTADDRESS$ $ARG1$
}
|