Nagios-安装与配置

来源:互联网 发布:333什么意思网络用语 编辑:程序博客网 时间:2024/04/30 03:07

1. Nagios 简介

nagios是一个开源软件,可以监控网络设备的网络流量、Linux/windows主机状态,甚至可以监控打印机
它可以运行在Linux上或windows上
基于浏览器的web界面方便运维人员查看监控项目的状态
支持web界面配置、管理操作
支持短信、邮件通知
可以自定义脚本实现自定义化监控
Nagios官网 http://www.nagios.org

2. Nagios安装 - 服务端(192.168.8.112)

(1)Centos6默认的yum源里没有nagios相关的rpm包,需要安装epel扩展源:

[root@master shell]# cd /etc/yum.repos.d/[root@master yum.repos.d]# wgethttp://mirrors.aliyun.com/repo/epel-6.repo

(2)安装nagios:(依赖于httpd php ,不需要mysql)

yum install -y httpd nagios nagios-plugins nagios-plugins-all  nrpe  nagios-plugins-nrpe

(3)设置登录nagios后台的用户和密码:htpasswd -c /etc/nagios/passwd nagiosadmin

[root@Dir ~]# htpasswd -c /etc/nagios/passwd nagiosadminNew password:Re-type new password:Adding password for user nagiosadmin

(4) 检测配置文件是否出错

[root@master shell]# nagios -v /etc/nagios/nagios.cfgNagios Core 3.5.1Copyright (c) 2009-2011 Nagios Core Development Team and Community ContributorsCopyright (c) 1999-2009 Ethan GalstadLast Modified: 08-30-2013.........        Checked 0 host dependencies.Checking commands...        Checked 25 commands.Checking time periods...        Checked 5 time periods.Checking for circular paths between hosts...Checking for circular host and service dependencies...Checking global event handlers...Checking obsessive compulsive processor commands...Checking misc settings...Total Warnings: 0Total Errors:   0Things look okay - No serious problems were detected during the pre-flight check

(5)启动服务

service httpd start; service nagios start

浏览器访问: http://192.168.8.112/nagios
用户名(上面创建过):nagiosadmin 密码:hx******

监控页面

3. Nagios安装 - 客户端(192.168.8.119)

(1)安装
在客户端机器上需要安装yum epel扩展源;
安装nagios客户端

yum install -y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe 

(2)客户端配置
vim /etc/nagios/nrpe.cfg
<1> 找到“allowed_hosts=127.0.0.1”
改为
“allowed_hosts=127.0.0.1,192.168.8.112(nagios服务端ip)” #后面的ip为服务端ip;
<2>找到” dont_blame_nrpe=0”
改为
“dont_blame_nrpe=1”

<3>启动客户端

   /etc/init.d/nrpe start      #nagios主机和被监控的服务器通过nrpe模块通信,传递数据

注:NRPE是监控软件nagios的一个扩展,它被用于被监控的服务器上,向nagios监控平台提供该服务器的一些本地的情况。例如,cpu负载、内存使用、硬盘使用等等。

4. 监控中心(192.168.8.112)添加被监控主机(192.168.8.119)

nagios web页面不能进行配置,需要手动编写配置文件增加被监控的主机。

cd /etc/nagios/conf.d/新建文件:vim 192.168.8.119.cfg      

配置如下:

;定义被监控主机hostdefine host{      use              linux-server                host_name        Web1     ;可自定义      alias            8.119             ;别名8.119,类似cacti     address           192.168.8.119     ;指明被监控机器IP  };定义要监控的服务  ping服务,直接ping,不用登陆到被监控机器define service{                                use                     generic-service            host_name               Web1  ;nagios主机名        service_description     check_ping   ;监控ping服务        check_command           check_ping!100.0,20%!200.0,50%                       ;有丢包,0%-ok,20%-warning,50%-critical出错                                                                       max_check_attempts 5 ;防误报,5次都确认出错再报警,为1则立即告警       normal_check_interval 1  ;1分钟之后重新检测};监控SSH服务,直接telnet 20端口define service{          use                     generic-service        host_name               Web1        service_description     check_ssh        check_command           check_ssh ;此命令在客户端配置        max_check_attempts      5        normal_check_interval 1};监控httpd,直接telnet 80 端口define service{        use                     generic-service        host_name               Web1        service_description     check_http        check_command           check_http        max_check_attempts      5        normal_check_interval 1}

说明:

配置文件中一共监控了三个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. 检测配置是否有错&重启nagios服务,更新配置

 nagios -v /etc/nagios/nagios.cfg /etc/init.d/nagios restart

浏览器查看监控项:

这里写图片描述

0 0