1、hosts里的配置
# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.110.157 nagios2016.com nagios2016 ##一定要有本机的ip对应
2、hostname与/etc/sysconfig/network里的hostname一致,并与hosts里的一致
不满足上面两个条件的话,在邮件日志中就会有如下错误
Feb 4 13:52:37 nagios2016 sendmail[1772]: u145qP2A001770: u145qb2A001772: DSN: Service unavailable
3、开启报警功能
vim /usr/local/nagios/etc/nagios.cfg 修改下面参数为1 enable_event_handlers=1 #开启报警功能
4、修改联系人
vim /usr/local/nagios/etc/objects/contacts.cfg define contact{ contact_name nagiosadmin use generic-contact -contact template (defined above) alias Nagios Admin email 6476464@qq.com ;这个地方就是要接收报警信息的邮件地址,多个联系人可以用逗号隔开 }
5、检测配置文件
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check #正常情况是这样的
6、重启Nagios服务
service nagios restart
7、安装sendmail
yum -y install sendmail service sendmail start #启动服务 service sendmail status #查看sendmail运行没
8、测试是否能正常发邮件
# mail -s "test" 6476464@qq.com test . EOT
如果能正确收到邮件那么就配置正确了。
9、在nagios中测试发邮件
点上面红框,进入
点提交,看能正确收到邮件不,能收到,则配置都正常。