当前位置: 首页 > news >正文

nagios

RPM包源
centos5 32位epel源下载地址: www.lishiming.net/data/attachment/forum/epel-release-5-4_32.noarch.rpm
64位下载地址:  www.lishiming.net/data/attachment/forum/epel-release-5-4_64.noarch.rpm
 
 
centos6
32位epel yum源下载地址: www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm
64位下载地址: www.lishiming.net/data/attachment/forum/epel-release-6-8_64.noarch.rpm
 
 
 
1、Nagios安装 - 服务端(192.168.0.11)
Centos6默认的yum源里没有nagios相关的rpm包,但是我们可以安装一个epel的扩展源:
rpm -ivh  www.lishiming.net/data/attachment/forum/epel-release-6-8_64.noarch.rpm
yum install -y httpd nagios nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe
设置登录nagios后台的用户和密码:htpasswd -c /etc/nagios/passwd nagiosadmin
vim /etc/nagios/nagios.cfg
nagios -v /etc/nagios/nagios.cfg 检测配置文件
启动服务:service httpd start; service nagios start
浏览器访问: http://ip/nagios
 
 
2、Nagios安装 - 客户端(192.168.0.12)
在客户端机器上 rpm -ivh  http://www.aminglinux.com/bbs/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm
yum install -y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe
vim /etc/nagios/nrpe.cfg  找到“allowed_hosts=127.0.0.1” 改为 “allowed_hosts=127.0.0.1,192.168.0.11” 后面的ip为服务端ip; 找到” dont_blame_nrpe=0” 改为  “dont_blame_nrpe=1”
启动客户端 /etc/init.d/nrpe start
 
 
3、监控中心(192.168.0.11)添加被监控主机(192.168.0.12)
cd /etc/nagios/conf.d/
vim 192.168.0.12.cfg                   //加入:
  1. define host{
  2.         use                     linux-server            ; Name of host template to use
  3.                                                         ; This host definition will inherit all variables that are defined
  4.                                                         ; in (or inherited by) the linux-server host template definition.
  5.         host_name               192.168.0.12
  6.         alias                   0.12
  7.         address                 192.168.0.12
  8.         }
  9. define service{
  10.         use                     generic-service
  11.         host_name               192.168.0.12
  12.         service_description     check_ping
  13.         check_command           check_ping!100.0,20%!200.0,50%
  14.         max_check_attempts 5
  15.         normal_check_interval 1
  16. }
  17. define service{
  18.         use                     generic-service
  19.         host_name               192.168.0.12
  20.         service_description     check_ssh
  21.         check_command           check_ssh
  22.         max_check_attempts      5
  23.         normal_check_interval 1
  24. }
  25. define service{
  26.         use                     generic-service
  27.         host_name               192.168.0.12
  28.         service_description     check_http
  29.         check_command           check_http
  30.         max_check_attempts      5
  31.         normal_check_interval 1
  32. }
 
4、配置文件的简单说明
我们定义的配置文件中一共监控了三个service:ssh, ping, http 这三个项目是使用本地的nagios工具去连接远程机器,也就是说即使客户端没有安装nagios-plugins以及nrpe也是可以监控到的。其他的一些service诸如负载、磁盘使用等是需要服务端通过nrpe去连接到远程主机获得信息,所以需要远程主机安装nrpe服务以及相应的执行脚本(nagios-plugins)
max_check_attempts 5  #当nagios检测到问题时,一共尝试检测5次都有问题才会告警,如果该数值为1,那么检测到问题立即告警
normal_check_interval 1#重新检测的时间间隔,单位是分钟,默认是3分钟
notification_interval           60 #在服务出现异常后,故障一直没有解决,nagios再次对使用者发出通知的时间。单位是分钟。如果你认为,所有的事件只需要一次通知就够了,可以把这里的选项设为0。
 
5、 继续添加服务
服务端vim /etc/nagios/objects/commands.cfg
增加:define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }
继续编辑 vim /etc/nagios/conf.d/192.168.0.12.cfg
增加如下内容:
  1. define service{
  2.         use     generic-service
  3.         host_name       192.168.0.12
  4.         service_description     check_load
  5.         check_command           check_nrpe!check_load
  6.         max_check_attempts 5
  7.         normal_check_interval 1
  8. }
  9. define service{
  10.         use     generic-service
  11.         host_name       192.168.0.12
  12.         service_description     check_disk_hda1
  13.         check_command           check_nrpe!check_hda1
  14.         max_check_attempts 5
  15.         normal_check_interval 1
  16. }
  17. define service{
  18.         use     generic-service
  19.         host_name       192.168.0.12
  20.         service_description     check_disk_hda2
  21.         check_command           check_nrpe!check_hda2
  22.         max_check_attempts 5
  23.         normal_check_interval 1
  24. }
 
check_nrpe!check_load :这里的check_nrpe就是在commands.cfg刚刚定义的,check_load是远程主机上的一个检测脚本
在远程主机上vim /etc/nagios/nrpe.cfg 搜索check_load,这行就是在服务端上要执行的脚本了,我们可以手动执行这个脚本
把check_hda1更改一下:/dev/hda1 改为 /dev/sda1
再加一行command[check_hda2]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda2
客户端上重启一下nrpe服务: service nrpe restart
服务端也重启一下nagios服务: service nagios restart
 
6、  配置图形显示 pnp4nagios
(1)安装
yum install pnp4nagios rrdtool
 
(2)配置主配置文件
vim /etc/nagios/nagios.cfg  //修改如下配置
  1. process_performance_data=1   
  2. host_perfdata_command=process-host-perfdata
  3. service_perfdata_command=process-service-perfdata
  4. enable_environment_macros=1     
 
(3)修改commands.cfg
vim /etc/nagios/objects/commands.cfg  //注释掉原有对process-host-perfdata和process-service-perfdata,重新定义
  1. define command {  
  2.        command_name    process-service-perfdata  
  3.        command_line    /usr/bin/perl /usr/libexec/pnp4nagios/process_perfdata.pl  
  4. }  
  5.   
  6. define command {  
  7.        command_name    process-host-perfdata  
  8.        command_line    /usr/bin/perl /usr/libexec/pnp4nagios/process_perfdata.pl -d HOSTPERFDATA  
  9. }  
 
(4)修改配置文件templates.cfg
vim /etc/nagios/objects/templates.cfg define host {  
        name       hosts-pnp  
        register   0  
        action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_  
        process_perf_data               1  
}  
define service {  
        name       srv-pnp  
        register   0  
        action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
        process_perf_data               1  
}  
 
 
(5)修改host和service配置
vim /etc/nagios/conf.d/192.168.0.12.cfg
把 “define host{
        use                     linux-server”
改为:
define host{
        use                     linux-server,hosts-pnp
 
修改对应的service,比如
define service{
        use     generic-service
        host_name       192.168.0.12
        service_description     check_disk_hda1
        check_command           check_nrpe!check_hda1
        max_check_attempts 5
        normal_check_interval 1
}
改为:
define service{
        use     generic-service,srv-pnp
        host_name       192.168.0.12
        service_description     check_disk_hda1
        check_command           check_nrpe!check_hda1
        max_check_attempts 5
        normal_check_interval 1
}
 
(6) 重启和启动各个服务:
service nagios restart
service httpd restart
service npcd start
 
(7) 访问测试
两种访问方法:
ip/nagios/
ip/pnp4nagios/
 
 
7、配置邮件告警
vim /etc/nagios/objects/contacts.cfg //增加:
  1. define contact{
  2.         contact_name               123
  3.         use                             generic-contact
  4.         alias                           aming
  5.         email              lishiming2009@139.com
  6.         }
  7. define contact{
  8.         contact_name               456
  9.         use                             generic-contact
  10.         alias                            aaa
  11.         email              aminglinux@139.com
  12.         }
  13. define contactgroup{
  14.         contactgroup_name           common
  15.         alias                                  common
  16.         members                          123,456
  17.         }
 
然后在要需要告警的服务里面加上contactgroup
  1. define service{
  2.         use     generic-service
  3.         host_name       192.168.0.12
  4.         service_description     check_load
  5.         check_command           check_nrpe!check_load
  6.         max_check_attempts 5
  7.         normal_check_interval 1
  8.         contact_groups        common
  9. }
 
8、 几个重要参数说明
notifications_enabled : 是否开启提醒功能。1为开启,0为禁用。一般,这个选项会在主配置文件(nagios.cfg)中定义,效果相同。
notification_interval: 之前刚介绍过,表示重复发送提醒信息的最短间隔时间。默认间隔时间是60分钟。如果这个值设置为0,将不会发送重复提醒。
notification_period: 发送提醒的时间段。非常重要的主机(服务)我定义为7×24,一般的主机(服务)就定义为上班时间。如果不在定义的时间段内,无论什么问题发生,都不会发送提醒。
notification_options: 这个参数定义了发送提醒包括的情况:d = 状态为DOWN, u = 状态为UNREACHABLE , r = 状态恢复为OK ,  f = flapping。,n=不发送提醒。

转载于:https://www.cnblogs.com/a12a/p/6693166.html

相关文章:

  • 开发App没有数据源?不存在的!国内值得关注的API集合
  • 2015携程JAVA工程师笔试题(基础却又没多少人做对的面向对象面试题)
  • JavaScript服务器推送技术之 WebSocket
  • 在 Windows 上安装Rabbit MQ 指南
  • 20165318 预备作业二 学习基础和C语言基础调查
  • 终极简洁设置tabbar在push到新界面的时候隐藏,返回时显示
  • 06.系统规划
  • 打开mat文件
  • netty如何知道连接已经关闭,socket心跳,双工?异步?
  • Android 线性布局(LinearLayout)相关官方文档 - 指南部分
  • hexo 添加标签
  • 重载()运算符和重载强制类型转换
  • 配置openssh实现sftp远程文件上传
  • 单反相机学习资料
  • 正则表达式
  • $translatePartialLoader加载失败及解决方式
  • 【技术性】Search知识
  • 345-反转字符串中的元音字母
  • canvas 高仿 Apple Watch 表盘
  • Django 博客开发教程 16 - 统计文章阅读量
  • JAVA SE 6 GC调优笔记
  • Java 内存分配及垃圾回收机制初探
  • leetcode讲解--894. All Possible Full Binary Trees
  • PHP 小技巧
  • React as a UI Runtime(五、列表)
  • Xmanager 远程桌面 CentOS 7
  • 测试如何在敏捷团队中工作?
  • 诡异!React stopPropagation失灵
  • 基于 Babel 的 npm 包最小化设置
  • 记一次和乔布斯合作最难忘的经历
  • 讲清楚之javascript作用域
  • 人脸识别最新开发经验demo
  • 使用SAX解析XML
  • 微信开放平台全网发布【失败】的几点排查方法
  • 走向全栈之MongoDB的使用
  • MyCAT水平分库
  • 翻译 | The Principles of OOD 面向对象设计原则
  • 正则表达式-基础知识Review
  • ​Kaggle X光肺炎检测比赛第二名方案解析 | CVPR 2020 Workshop
  • #QT(智能家居界面-界面切换)
  • #数学建模# 线性规划问题的Matlab求解
  • #我与Java虚拟机的故事#连载02:“小蓝”陪伴的日日夜夜
  • (8)STL算法之替换
  • (LNMP) How To Install Linux, nginx, MySQL, PHP
  • (官网安装) 基于CentOS 7安装MangoDB和MangoDB Shell
  • (求助)用傲游上csdn博客时标签栏和网址栏一直显示袁萌 的头像
  • (十八)用JAVA编写MP3解码器——迷你播放器
  • (转载)在C#用WM_COPYDATA消息来实现两个进程之间传递数据
  • ..回顾17,展望18
  • .NET DevOps 接入指南 | 1. GitLab 安装
  • .NET 回调、接口回调、 委托
  • .NET 设计模式—适配器模式(Adapter Pattern)
  • .NET开源快速、强大、免费的电子表格组件
  • .pings勒索病毒的威胁:如何应对.pings勒索病毒的突袭?
  • /bin/rm: 参数列表过长"的解决办法