×

微信扫一扫,快捷登录!

Nagios的安装与配置(4)

标签: 暂无标签
本帖最后由monicazhang于2015-10-3021:40编辑

20151030淡然
续上




echo-n"RestartingApacheservice..."
/sbin/servicehttpdrestart
;;
esac
;;
HARD)
echo-n"RestartingApacheservice..."
/sbin/servicehttpdrestart
;;
esac
;;
esac
exit0
1)配置Nagios监控机上的配置文件
Ø修改nagios.cfg
enable_event_handlers=1#开启全局

事件处理
Ø在命令配置文件中定义重启apache的命令
#cd/usr/local/nagios/etc/
#viobjects/commands.cfg
#restarttheapacheserviceonaremoteservernagios安装
definecommand{
command_namerestart-httpd
command_line/usr/bin/sshnagios@$HOSTADDRESS$"sudo/usr/local/nagios/libexec/eventhandlers/restart-httpd$SERVICESTATE$$SERVICESTATETYPE$$SERVICEATTEMPT$"
}
Ø配置主机监控文件
修改services.cfg配置,加入事件处理配置
#vi/usr/local/nagios/etc/objects/services.cfg
defineservice{
usesrv-pnp
host_namenagios-test1
service_descriptioncheck_tcp80
check_period24x7
max_check_attempts4
normal_check_interval3
retry_check_interval2
contact_groupsadmins
notification_interval10
notification_period24x7
notification_optionsw,u,c,r
event_handler_enabled1#启用事件处理
event_handlerrestart-httpd#事件处理执行的命令
check_commandcheck_tcp!80
}

1)测试
在被监控机停止apache服务,等待几分钟后检查被监控机的apache服务是否自动启动。
Nagios通过NRPE执行event_hander
1)在远程机器上编写service重启脚本
vi/usr/local/nagios/libexec/service_hander
内容如下:
#!/bin/sh
#
#Eventhandlerscriptforrestartingtheserviceontheremotemachine开源监控软件
#
#Note:Thisscriptwillonlyrestartserviceiftheserviceis
#retried2times(ina"soft"state)oriftheservicessomehow
#managestofallintoa"hard"errorstate.
#
#
#Whatstateisservicein?
case"$1"in
OK)
;;
WARNING)
;;
UNKNOWN)
;;
CRITICAL)
#Isthisa"soft"ora"hard"state?
case"$2"in
SOFT)
#Whatcheckattemptareweon?Wedon'twanttorestarttheserviceonthefirst
#check,becauseitmayjustbeafluke!
case"$3"in
2)
echo-n"Restarting$4service..."
/sbin/service$4restart
;;
esac
;;
HARD)
echo-n"Restarting$4service..."
/sbin/service$4restart
;;
esac
;;
esac
exit0

重新编译nrpe,需要让nrpe传递参数
./configure--prefix=/usr/local/nagios--enable-command-argsnagios配置
修改nrpe.cfg
vi/usr/local/nagios/etc/nrpe.cfg
dont_blame_nrpe0改为1
command[restart_service]=/usr/local/nagios/libexec/service_hander$ARG1$$ARG2$$ARG3$$ARG4$
配置完nrpe后需要重启启动nrpe服务
服务端配置(修改ssh方式下的command.cfg
vi/usr/local/nagios/etc/objects/commands.cfg

找到以下内容:
definecommand{
command_namerestart-httpd
command_line/usr/bin/sshnagios@$HOSTADDRESS$"sudo/usr/local/nagios/libexec/eventhandlers/restart-httpd$SERVICESTATE$$SERVICESTATETYPE$$SERVICEATTEMPT$"
}
修改为:
definecommand{
command_namerestart-httpd
command_line/usr/local/nagios/libexec/check_nrpe-H172.26.188.202-crestart_service-a$SERVICESTATE$$SERVICESTATETYPE$$SERVICEATTEMPT$httpd
}
报警通知邮件报警通知安装配置sendmail
sendmail安装
yum-yinstallsendmailsendmail-cfsendmail-develdovecotcyrus-saslcyrus-sasl-libcyrus-sasl-plain
sendmail配置
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')dnl
B、找到TRUST_AUTH_MECH(`EXTERNALDIGEST-MD5CRAM-MD5LOGINPLAIN')dnl
define(`confAUTH_MECHANISMS',`EXTERNALGSSAPIDIGEST-MD5CRAM-MD5LOGINPLAIN')dnl
去掉注释及前面的dnl,把两行移到最前面。
n生成sendmail.cf主配置文件。
mv/etc/mail/sendmail.cf/etc/mail/sendmail.cf-bak
m4/etc/mail/sendmail.mc>/etc/mail/sendmail.cf
n设置local-host-names文件
echo"nagios-server.com">>/etc/mail/local-host-names
此处abc.com是域名,即DNS解析MX解析的域名
n设置访问控制accessaccess.db
Acces的配置为:地址控制
Vi/etc/mail/access
localhost.localdomainRELAY
localhostRELAY
127.0.0.1RELAY
192.168.0.71RELAY
192.168.0.129RELAY
Makemaphashaccess<access
n添加账户:
groupaddusermail
adduser-gusermail-s/sbin/nologinuser1
nagios实施
passwduser1
n设置别名
vim/etc/aliases
nagios邮件报警配置
&#216;配置邮件报警command
#vi/usr/local/nagios/etc/objects/commands.cfg
#'notify-host-by-email'commanddefinition
definecommand{
command_namenotify-host-by-email
command_line/usr/bin/printf"%b""*****Nagios*****NotificationType:$NOTIFICATIONTYPE$Host:$HOSTNAME$State:$HOSTSTATE$Address:$HOSTADDRESS$Info:$HOSTOUTPUT$Date/Time:$LONGDATETIME$"|/bin/mail-s"**$NOTIFICATIONTYPE$HostAlert:$HOSTNAME$is$HOSTSTATE$**"$CONTACTEMAIL$
}
#'notify-service-by-email'commanddefinitionnagios培训




待续:http://www.ITILxf.com/thread-53046-1-1.html
本帖关键字:Nagios




上一篇:Nagios的安装与配置(3)
下一篇:Nagios的安装与配置(5)
monicazhang

写了 2297 篇文章,拥有财富 12859,被 21 人关注

您需要登录后才可以回帖 登录 | 立即注册
B Color Link Quote Code Smilies

成为第一个吐槽的人

Powered by IT 运维管理
返回顶部