nagios部署配置流程
nagios部署配置流程
nagios服務端:
1、部署nagios服務端(參考nagios官方部署文檔)、nagios-plugin、php、apache2
2、需要在服務端添/etc/hosts中添加解析
3、配置文件說明
nagios.cfg中配置需要監控的主機目錄dir_cfg=path/to/somewhere 該路徑下的文件均以主機名命名,以.cfg結尾
commands.cfg
配置接受nrpe傳過來的command需要在 commands.cfg 配置,模板如下:
# ‘check_nrpe‘ command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
#配置郵箱報警、微信報警
define command {
command_name sendEmail
command_line $USER1$/sendEmail/sendEmail.pl -f "[email protected]" -t $CONTACTEMAIL$ -s smtp.mxhichina.com:80 -u "** $HOSTNAME$—— $HOSTNAME$ $HOSTSTATE$ **" -xu [email protected] -xp ‘Z2h0o1g6n0z4h2i9cheng@‘ -m "***** New_NAGIOS Notification *****\n\nNotification type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHOSTNAME: $HOSTALIAS$\nIP$HOSTNAME$\nSTATUS: $SERVICESTATE$\n\nTime: $LONGDATETIME$\n\nSERVICEOUTPUT:\n\n$SERVICEOUTPUT$"}
define command {
command_name wei_baojing
command_line $USER1$/wei_baojing.py "通知類型: $NOTIFICATIONTYPE$<br><br>服務: $SERVICEDESC$<br>主機: $HOSTALIAS$<br>IP地址: $HOSTNAME$<br>狀態: $SERVICESTATE$<br><br>日期時間: $LONGDATEME$<br><br>附加信息:<br><br>$SERVICEOUTPUT$"
}
templates.cfg 需要配置監控的模板
define service {
service_description generic-zzcbj
name generic-zzcbj
contacts zzcbj
check_period 24x7
notification_period 24x7
max_check_attempts 1
check_interval 3
retry_interval 1
notification_interval 5
notification_options w,u,c,r,f
first_notification_delay 0
register 0
active_checks_enabled 1
passive_checks_enabled 1
notifications_enabled 1
}
localhost.cfg 監控本機配置
contacts.cfg
#配置微信 郵件報警
define contact {
contact_name zzcbj
alias zzcbj
email [email protected],[email protected]
pager admin
host_notification_period 24x7
service_notification_period 24x7
host_notification_options d,u,r,f,s
service_notification_options w,u,c,r,f,s
register 1
host_notification_commands sendEmail,wei_baojing
service_notification_commands sendEmail,wei_baojing
#host_notification_commands weixin_ywts
#service_notification_commands weixin_ywts
}
配置文件配置完成後可以檢查配置文件是否有問題
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
或
/etc/init.d/nagios configtest
客戶端: nrpe nagios-plugins 安裝
監控腳本放在/usr/local/nagios/libexec/
/usr/local/nagios/etc/nrpe.cfg 配置nagios服務端地址
/usr/local/nagios/etc/nrpe.cfg 文件中配置需要監控的腳本路徑 腳本來源於/usr/local/nagios/libexec/
nagios部署配置流程