Nagios的安装与配置(4)
本帖最后由 monicazhang 于 2015-10-30 21:40 编辑20151030淡然续上
echo -n "Restarting Apache service..."/sbin/service httpd restart;;esac;;HARD)echo -n "Restarting Apache service..."/sbin/service httpd restart;;esac;;esacexit 01) 配置Nagios监控机上的配置文件Ø 修改nagios.cfgenable_event_handlers=1 #开启全局
事件处理Ø 在命令配置文件中定义重启apache的命令# cd /usr/local/nagios/etc/#vi objects/commands.cfg#restart the apache service on a remote server nagios安装define command{command_name restart-httpdcommand_line /usr/bin/ssh nagios@$HOSTADDRESS$ "sudo /usr/local/nagios/libexec/eventhandlers/restart-httpd $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$" }Ø 配置主机监控文件修改services.cfg配置,加入事件处理配置
#vi /usr/local/nagios/etc/objects/services.cfgdefine service { use srv-pnp host_name nagios-test1 service_description check_tcp 80 check_period 24x7 max_check_attempts 4 normal_check_interval 3 retry_check_interval2 contact_groups admins notification_interval 10 notification_period 24x7 notification_options w,u,c,r event_handler_enabled 1 #启用事件处理 event_handler restart-httpd #事件处理执行的命令 check_command check_tcp!80 }
1) 测试在被监控机停止apache服务,等待几分钟后检查被监控机的apache服务是否自动启动。Nagios通过NRPE执行event_hander 1) 在远程机器上编写service重启脚本
vi /usr/local/nagios/libexec/service_hander内容如下:#!/bin/sh## Event handler script for restarting the service on the remote machine 开源监控软件## Note: This script will only restart service if the service is# retried 2 times (in a "soft" state) or if the services somehow# manages to fall into a "hard" error state.### What state is service in?case "$1" inOK);;WARNING);;UNKNOWN);;CRITICAL)# Is this a "soft" or a "hard" state?case "$2" inSOFT)# What check attempt are we on? We don't want to restart the service on the first# check, because it may just be a fluke!case "$3" in2)echo -n "Restarting $4 service..."/sbin/service $4 restart;;esac;;HARD)echo -n "Restarting $4 service..."/sbin/service $4 restart;;esac;;esacexit 0
重新编译nrpe,需要让nrpe传递参数./configure --prefix=/usr/local/nagios--enable-command-args nagios配置修改nrpe.cfgvi/usr/local/nagios/etc/nrpe.cfgdont_blame_nrpe 0改为1command=/usr/local/nagios/libexec/service_hander $ARG1$ $ARG2$ $ARG3$ $ARG4$配置完nrpe后需要重启启动nrpe服务服务端配置(修改ssh方式下的command.cfg)vi /usr/local/nagios/etc/objects/commands.cfg
找到以下内容:define command{command_name restart-httpdcommand_line /usr/bin/ssh nagios@$HOSTADDRESS$ "sudo /usr/local/nagios/libexec/eventhandlers/restart-httpd $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$" }修改为:define command{ command_name restart-httpd command_line /usr/local/nagios/libexec/check_nrpe -H 172.26.188.202 -c restart_service -a $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$ httpd }报警通知邮件报警通知安装配置sendmail sendmail安装yum -y install sendmail sendmail-cf sendmail-devel dovecot cyrus-sasl cyrus-sasl-lib cyrus-sasl-plainsendmail配置n 配置MTA vim /etc/mail/sendmail.mc A、找到DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl 监控软件修改为DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnlB、找到TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnldefine(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl 去掉注释及前面的dnl,把两行移到最前面。n 生成sendmail.cf主配置文件。mv /etc/mail/sendmail.cf /etc/mail/sendmail.cf-bak
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cfn 设置local-host-names文件echo "nagios-server.com" >>/etc/mail/local-host-names
此处abc.com是域名,即DNS解析MX解析的域名n 设置访问控制access和access.db。Acces的配置为:地址 控制Vi /etc/mail/accesslocalhost.localdomain RELAYlocalhost RELAY127.0.0.1 RELAY192.168.0.71 RELAY192.168.0.129 RELAYMakemap hash access < accessn 添加账户:groupadd usermail
adduser -g usermail -s /sbin/nologin user1 nagios实施
passwd user1n 设置别名vim /etc/aliasesnagios邮件报警配置 Ø 配置邮件报警command#vi /usr/local/nagios/etc/objects/commands.cfg# 'notify-host-by-email' command definitiondefine 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 nagios培训
待续:http://ITIL-foundation.cn/thread-53046-1-1.html
本帖关键字:Nagios
页:
[1]