×

扫描二维码登录本站

QQ登录

只需一步,快速开始

监控利器---nagios原理详解

标签: 监控
来自:网络


第一节 Nagios简介
     nagios是系统管理人员和运维监控人员必须的工具之一,利用nagios可以监控本地或者远程主机资源,
如磁盘空间,系统负载等情况,也可以监控各种应用,例如HTTP服务,FTP服务等。当主机或服务出现故障                 nagios培训
Nagios可以通过邮件手机飞信等形式在第一时间通知系统维护人员。
同时,Nagios可以提供一个可选的基于浏览器的Web界面,以方便系统管理员查看系统的运行状态、网络状态
各种系统问题以及日志异常。!
第二节 Nagios结构与特点
     从结构上讲,Nagios可分为核心和插件两个部分。Nagios核心部分只提供了少部分的监控功能,因此要搭建
一个完整的IT监控管理系统,用户还需要为Nagios安装相应的插件。
     特点:1>监视本地或远程主机资源(内存、进程、磁盘)
           2>监视网络服务资源(HTTP、PING、FTP、SMTP、POP3)
           3>允许用户编写自己的插件来监控特定的服务
           4>当监控对象出现异常可以通过邮件或者短信报警
           5>可以事先定义事件处理程序,当主机或者服务出现故障时自动调用指定的处理程序
           6>通过WEB界面来监控和各个主机和服务的运行状态。
第三节 Nagios原理以及工作原理(nagios本身并不具有太多功能,都是靠插件实现)
[ ttp://static.oschina.net/uploads/space/2014/0831/002406_PiCe_1026229.png][/url]
第四节、安装与配置
注意:一般源码安装软件需要装“Development tools”和“Development Librarys”

第5节  安装远程nrpe插件,监控远程主机资源(disk。procs)

通过nrpe检测外来linux/unix主机的服务(资源)。在被监控主机上需要安装nagios-plugin和nrpe; nagios监控主机再需用安装一个nrpe插件
[ ttp://static.oschina.net/uploads/space/2014/0831/002506_bBA3_1026229.png][/url]

NRPE原理图:
[ ttp://static.oschina.net/uploads/space/2014/0831/002546_9T8h_1026229.png][/url]

第一节讲到,nagios监控远程主机的方法很多,包括SNMP,NRPE,SSH和NCSA,这里详细讲述NRPE             nagios实施
NRPE(Nagios Remote Plugin Executor)是用于在远端服务器上运行检测命令的守护进程,它用于让Nagios监控端基于安装的方式触发远端主机上的检测命令,并将检测结果输入至监控端。而其执行的开销远远低于基于ssh的检测方式,而且检测过程并不需要远程主机上的系统账号等信息,有更高的安全性。



3.Nagios监控windos主机原理:

[ ttp://static.oschina.net/uploads/space/2014/0831/002639_kXwZ_1026229.png][/url]
被监控的win主机需要安装NSClients++软件,然而这个软件支持nrpe和nt的访问;
在nagios中默认已经有了check_nt监控命令,因此使用这个方式监控windows主机还是比较不错的。
当然因为nagios服务器一般需要安装nrpe,可以修改NSClients工具:
使用nrpe方式让nagios监控windows主机
1、打开nsclients的安装目录
2. 打开nsc文件进行编辑
在windows主机上查看开启的端口,一般是支持两种方式的:(nrpe和nt)
[ ttp://static.oschina.net/uploads/space/2014/0831/002715_nv7s_1026229.png][/url]
一个是12489,一个是5666
配置完成后就可以在nagios监控主机上进行测试windows主机
./check_nt –H 192.168.0.57 –p 12489 –v CPULOAD –w 80 –c 90 –l 5,80,90
./check_nrpe –H 192.168.0.57 –c checkCPU –a warn=80 crit=90 time=20 time=10 time=5               监控软件
多命令检测:
./check_nt –H 192.168.0.57 –p 12489 –v UPTIME
./check_nt –H 192.168.0.57 –p 12489 –v USEDDISKSPACE –w 80 –c 90 –l C
首先加载command.cfg
Define command(
Command_name check_nt
Command_line  $USER$/check_nt –H $HOSTADDRESS$  -p 12489 –s PASSWORD –v $ARG2$ )
其次加载service.cfg
  Define service (
Use     generic-service
Host_name   winhost
Service_description  W3SVC
Check_command    check_nt!SERVICESTATE! –d SHOWALL –l W3SVC)
最后修改模板文件
Cfg_file=/etc/nagios/objects/windows.cfg

第五节 安装绘图插件PNP(基于php和perl的利用rrdtool工具将nagios采集的数据绘制成图)
缺少RRDs perl的支持,安装rrdtool-perl(注意,必须得和系统的rrdtool版本一致)
PNP是一个小巧的开源软件包,它基于PHP和PERL,PNP可以利用rrdtool工具将Nagios采集的数据绘制成相关的图表,然后显示主机或者服务在一段时间内的运行状况
整合后的apache和php环境,需支持gd/zlib/jpeg.rrdtool perl
首先安装rrdtools
tar zxf pnp-0.4.13.tar.gz
[root@nagios pnp-0.4.13]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-rrdtool=/usr/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata/mysql-server
  make all
   make install
   make install-config
make install-init

2.配置pnp
root@nagios pnp-0.4.13]# cd /usr/local/nagios/etc/pnp/
[root@nagios pnp]# cp –p process_perfdata.cfg-sample process_perfdata.cfg                nagios配置
[root@nagios pnp]# cp –p npcd.cfg-sample  npcd.cfg
[root@nagios pnp]# cp –p rra.cfg-sample rra.cfg   
注意:如果不加-p需要chown修改/usr/local/nagios/etc/pnp的所有者
[root@nagios pnp]# vim process_perfdata.cfg
LOG_LEVEL = 2
1. 修改nagios配置
3.1增加小太阳标志(为何没出现呢)
[root@nagios objects]# vim templates.cfg
define host{
        name                    hosts-pnp      
        register                0
        action_url             /nagios/pnp/index.php?host=$HOSTNAME$
        process_perf_data       1
}

define service{
        name                    services-pnp  
        register                0
        action_url          /nagios/pnp/index.php?host=$HOSTNAME$&SERVICEDESC$
        process_perf_data       1
}
3.2修改nagios.cfg
process_performance_data=1
service_perfdata_command=process-service-perfdata
host_perfdata_command=process-host-perfdata
3.3修改command.cfg
define command{
        command_name    process-service-perfdata(host)
        command_line /usr/local/nagios/libexec/process_perfdata.pl
        }
3.4修改hosts.cfg和services.cfg文件
define host{
        use                     linux-server,hosts-pnp         
        host_name               nagios-server
        alias                   nagios
        address                 127.0.0.1
        icon_image              switch.gif
        statusmap_image         switch.gd2
        2d_coords               100,200
        3d_coords               100,200,100
        }
define host{
        use                     linux-server,hosts-pnp        
        host_name               mysql-server
        alias                   mysql
        address                 192.168.0.143
        icon_image              server.gif
        statusmap_image         server.gd2
        2d_coords               500,200
        3d_coords               500,200,100
        }

3.5 测试pnp功能
检查并且重启nagios服务
[ ttp://nagios-server/nagios]http://nagios-server/nagios[/url]  查看主机选项,点击小太阳
但是问题出现了,因为编译的时候出现没有发现RRDs perl modules                     开源监控软件
打开后出现php GD not found!    安装php-gd 重新启动两个服务
缺什么就安装什么,最后如此:
[ ttp://static.oschina.net/uploads/space/2014/0831/002754_j1IF_1026229.png][/url]
第六节 .安装报警机制,fention            
注意,fetion程序必须放在libexec目录,并且需要nagios用户执行                 
下载linux版飞信。
[root@server58 ~]# mv fetion /usr/local/nagios/libexec/
[root@server58 ~]# cd /usr/local/nagios/libexec/
[root@server58 libexec]# ll
[root@server58 libexec]# chown nagios.nagios fetion       必须以普通用户执行
[root@server58 libexec]# ll fetion
-rw-r--r-- 1 nagios nagios 503425 Jul 18  2011 fetion
[root@server58 libexec]# chmod a+x fetion
[root@server58 ~]# tar zxf linuxso_20101113.tar.gz -C /usr/lib         库文件,必须的
[root@server58 ~]# su - nagios
[nagios@server58 ~]$ /usr/local/nagios/libexec/fetion
/usr/local/nagios/libexec/fetion: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
[root@server58 ~]# yum install libstdc++.so.6 -y
[nagios@server58 ~]$ /usr/local/nagios/libexec/fetion             执行一下
/usr/local/nagios/libexec/fetion: error while loading shared libraries: libgssapi_krb5.so.2: cannot open shared object file: No such file or directory

[root@server58 ~]# yum install libgssapi_krb5.so.2 -y

[nagios@server58 ~]$ /usr/local/nagios/libexec/fetion
/usr/local/nagios/libexec/fetion: error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
[root@server58 ~]# yum install libz.so.1 -y

[nagios@server58 ~]$ /usr/local/nagios/libexec/fetion             说明飞信安装成功                nagios安装
Usage:
    --mobile=[mobile]
    --sid=[sid]
    --pwd=[pwd]
[nagios@server58 ~]$ /usr/local/nagios/libexec/fetion --mobile=18220561432 --pwd=tyq5211314 --to="18209247284" --msg-utf8="Good Luck"
必须以普通用户执行哦
图形验证码已经生成,文件名为:18220561432.jpg请识别后输入图形验证码:
如果发送成功,将会生成一个图形验证码。输入后就会成功。

4.整合fetion,把fetion整合到nagios中
[root@server58 libexec]# vim fetion.sh
/usr/local/nagios/libexec/fetion --mobile=18209247284 --pwd=xxbandy --to="$1" --msg-utf8="$2"
> /dev/null    加上这个如果正确就不会有提示
[root@server58 libexec]# chmod +x fetion.sh
[root@server58 libexec]# chown nagios.nagios fetion.sh
[root@server58 libexec]# ll fetion.sh
-rwxr-xr-x 1 nagios nagios 95 Mar 24 01:47 fetion.sh
[root@server58 libexec]# su - nagios
[nagios@server58 ~]$ /usr/local/nagios/libexec/fetion.sh 18209247284 "^_^"
SIP-C/4.0 280 Send SMS OK
T: sip:274959794@fetion.com.cn;p=20193
I: 2
Q: 1 M
L: 114
D: Sun, 24 Mar 2013 01:52:40 GMT
XI: 3C0CF0762B3BE378489E1BA9D73E4FA0

##修改template、command、contact配置文件,检测飞信脚本!

[root@server58 objects]# vim templates.cfg
define contact{
        name                            generic-contact         ; The name of this contact template
        service_notification_period     24x7                    ; service notifications can be sent anytime
        host_notification_period        24x7                    ; host notifications can be sent anytime
        service_notification_options    w,u,c,r,f,s             ; send notifications for all service states, flapping events, and scheduled downtime events
        host_notification_options       d,u,r,f,s               ; send notifications for all host states, flapping events, and scheduled downtime events
        service_notification_commands   notify-service-by-email,notify-service-by-fetion        ; send service notifications via email
        host_notification_commands      notify-host-by-email,notify-service-by-fetion   ; send host notifications via email
        register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
[root@server58 objects]# vim commands.cfg
# 'notify-host-by-fetion' command definition
define command{
        command_name    notify-host-by-fetion
        command_line    $USER1$/fetion.sh $CONTACTPAGER$ "$NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
        }

# 'notify-service-by-fetion' command definition
define command{
        command_name    notify-service-by-fetion
        command_line    $USER1$/fetion.sh $CONTACTPAGER$ "$NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }
[root@server58 objects]# vim contacts.cfg
        email                           nagios@localhost        ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
        pager                           18209247284
[root@server58 objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@server58 objects]# /etc/init.d/nagios reload
Running configuration check...done.
Reloading nagios configuration...done


想做Nagios Zabbix,Cacti,iTop各种交流的,可以进入开源监控工具Nagios交流  QQ群号 476809427





上一篇:你知道nagios nrpe吗?
下一篇:掌控Nagios监控服务器
monicazhang

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

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

成为第一个吐槽的人

手机版|小黑屋|最新100贴|论坛版块|ITIL先锋论坛 |粤ICP备11099876号|网站地图
Powered by Discuz! X3.4 Licensed  © 2001-2017 Comsenz Inc.
返回顶部