- ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
- <Directory "/usr/local/nagios/sbin">
- AuthType Basic
- Options ExecCGI
- AllowOverride None
- Order allow,deny
- Allow from all
- AuthName "Nagios Access"
- AuthUserFile /usr/local/nagios/etc/htpasswd
- Require valid-user
- </Directory>
- Alias /nagios /usr/local/nagios/share
- <Directory "/usr/local/nagios/share">
- AuthType Basic
- Options None
- AllowOverride None
- Order allow,deny
- Allow from all
- AuthName "Nagios Access"
- AuthUserFile /usr/local/nagios/etc/htpasswd
- Require valid-user
- </Directory>
- #将localhost.cfg注释掉,而改用多文件配置,使得配置文件更加清晰明了。
- #cfg_file=/usr/local/nagios/etc/objects/localhost.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/contacts.cfg
- #联系组配置文件路径
- cfg_file=/usr/local/nagios/etc/objects/contactgroups.cfg
- #监控服务配置文件路径
- cfg_file=/usr/local/nagios/etc/objects/services.cfg
- #监视时段配置文件路径
- cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
- #在Web界面下重启Nagios、停止主机/服务检查等操作,默认值为0
- check_external_commands=1
- #根据自己的情况定义这个命令检查时间间隔,默认值为1秒
- command-check_interval=10s
- authorized_for_system_information=nagios
- authorized_for_configuration_information=nagios
- authorized_for_system_commands=nagios
- authorized_for_all_services=nagios
- authorized_for_all_hosts=nagios
- authorized_for_all_service_commands=nagios
- authorized_for_all_host_commands=nagios
- # 'check-nrpe' command definition
- define command{
- command_name check_nrpe
- command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
- }
- define host {
- host_name nagios-server
- alias nagios server
- address 192.168.2.4
- contact_groups sagroup
- check_command check-host-alive
- max_check_attempts 5
- notification_interval 10
- notification_period 24x7
- notification_options d,u,r
- }
- define hostgroup {
- hostgroup_name sa-servers
- alias sa servers
- members nagios-server
- }
- define contact {
- contact_name nagios
- alias nagios administrator
- service_notification_period 24x7
- host_notification_period 24x7
- service_notification_options w,u,c,r
- host_notification_options d,u,r
- service_notification_commands notify-service-by-email
- host_notification_commands notify-host-by-email
- email [email protected]
- }
- define contactgroup {
- contactgroup_name sagroup
- alias system administrator group
- members nagios
- }
- define service {
- host_name nagios-server
- 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
- }
- define service {
- host_name nagios-server
- service_description check_tcp 80
- 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_tcp!80
- }
- define service {
- host_name nagios-server
- service_description check-disk
- 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_nrpe!check_df
- }
- define service {
- host_name nagios-server
- service_description check-load
- 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_nrpe!check_load
- }
- define service {
- host_name nagios-server
- service_description total_procs
- 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_nrpe!check_total_procs
- }
- log_facility=daemon
- pid_file=/var/run/nrpe.pid
- server_address=192.168.2.4
- server_port=5666
- nrpe_user=nagios
- nrpe_group=nagios
- allowed_hosts=127.0.0.1,192.168.2.4
- dont_blame_nrpe=0
- debug=0
- command_timeout=60
- connection_timeout=300
- command[check_load]=/usr/local/nrpe/libexec/check_load -w 15,10,5 -c 30,25,20
- command[check_df]=/usr/local/nrpe/libexec/check_disk -w 20% -c 10%
- command[check_zombie_procs]=/usr/local/nrpe/libexec/check_procs -w 5 -c 10 -s Z
- command[check_total_procs]=/usr/local/nrpe/libexec/check_procs -w 150 -c 200
- command[check_ips]=/usr/local/nrpe/libexec/ip_conn.sh 8000 10000
- #allowed_hosts指允许监控你的nagios服务器地址。因为是客户机,这里必须要填上nagios监控主机的ip,也可以填上127.0.0.1,用逗号分隔。
- #这里command[*]里定义的项目,就是在主机的check_nrpe中添加的定义字符串,请看services.cfg中的“check_nrpe!check_df”你就明白这些字符串是干什么用的了。也就可以自己手动添加一些自己要监控的程序进去了。
- #这里的check_ips中指定的ip_conn.sh脚本是要手动创建的(脚本摘自田逸老师的《互联网运营智慧》一书)。
- #!/bin/sh
- #if [ $# -ne 2 ]
- # echo "Usage:$0 -w num1 -c num2"
- #exit 3
- #fi
- ip_conns=`netstat -an | grep tcp |grep EST |wc -l`
- if [ $ip_conns -lt $1 ]
- then
- echo "OK -connect counts is $ip_conns"
- exit 0
- fi
- if [ $ip_conns -gt $1 -a $ip_conns -lt $2 ]
- then
- echo "Warning -connect counts is $ip_conns"
- exit 1
- fi
- if [ $ip_conns -gt $2 ]
- then
- echo "Critical -connect counts is $ip_conns"
- exit 2
- fi
- #指定2个连接数,当连接数大于指定的第一个数的时候,给予warning警报,当连接数大于指定的第二个数的时候,给予Critical警报。
- /usr/local/apache/bin/apachectl -k start
- /usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d
- /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
配置全部完成。
后记:在配置完成当初,完全是忘了配置php了,哎,一直提示没有权限登录。等后来编译了php以后,还是报错,我就很诧异。怎么回事呢,后来仔细检查httpd.conf,才发现原来是这一行搞的怪
ScriptAlias /nagios /usr/local/nagios/share
<Directory "/usr/local/nagios/share">
应该为Alias,改回来以后,登录nagios不报错了,但是疯狂的报Critical错误,经分析,全是check_nrpe连接外部主机的。经过反复测试,并且查看各个代码,发现原来是hostname那里连不过去。经过测试,添加到/etc/hosts中,问题解决。过了一会,全ok了。哎,一波三折啊。写的太不仔细了,太郁闷了。以后一定不会这样了。
本文出自 “周旭光_不断进取” 博客,谢绝转载!