|
..
http://code.google.com/p/jdocuments/source/browse/trunk/+jdocuments+--username+zhb1208/JDoc/%E6%9E%B6%E6%9E%84%E8%AE%BE%E8%AE%A1/nagios/nagios%E7%9B%91%E6%8E%A7%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%9A%84ip%E8%BF%9E%E6%8E%A5%E6%95%B0.txt?r=220
Source path: svn/ trunk/ jdocuments --username zhb1208/ JDoc/ 架构设计/ nagios/ nagios监控服务器的ip连接数.txt | |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
| ========================nagios监控服务器的ip连接数======================== | -------------------------- | author:zhanghongbing | date:2011-06-25 | version:1.0 | -------------------------- | | vim /usr/local/nrpe/etc/nrpe.cfg | 添加 | command[check_ips]=/usr/local/nrpe/libexec/ip_conn.sh 8000 10000 #ip连接数 | | ip_conn.sh脚本需要自己写,下面给出脚本的内容: | | #!/bin/sh | #if [ $#-ne 2 ] | #then | # echo “usage:$0 -w num1 -c num2″ | #exit 3 | #fi | ip_conns=`netstat -an |grep tcp |grep est |wc -l` | if [ $ip_conns -lt $1 ] | then | echo “ok -connectcounts is $ip_conns” | exit 0 | fi | | if [ $ip_conns -gt $1 -a $ip_conns -lt $2 ] | then | echo “warning -connectcounts is $ip_conns” | exit 1 | fi | | if [ $ip_conns -gt $2 ] | then | echo “critical -connectcounts is $ip_conns” | exit 2 | fi | | 我在nrpe配置文件nrpe.cfg把脚本所需的两个参数写上了,因此这个脚本就不需判断两个参数输入值的情况。只要当前ip连接数大于8000,系统就发warning报警,超过10000,则发“critical”报警信息。把这个脚本放在目录/usr/local/nrpe/libexec下,并给于执行权限。 | | | | ===============================================END=============================================== |
|
http://www.ttlsa.com/html/1173.html
原文地址:
http://blog.sina.com.cn/s/blog_6eee53080100yed4.html
插件下载地址 :
http://www.rayfile.com/files/4d6f1bb0-e591-11e0-9847-0015c55db73d/
如果失效,这个插件太不好找和下载了。可以邮件找我要59866276@qq.com
一:主要步骤
1,安装snmpd服务包,并且设置好团体名称,添加系统启动
2,部署check_traffic.sh到nagios的插件目录到libexec并且授权哦。
3,网卡检测参数。
4,nagios设置command.cfg的command,添加service.cfg
二:具体干活细节
1,安装snmpd,修改内容,设置开机启动
安装snmpd
yum install net-snmp*
修改snmpd.conf
vim snmpd.conf内容如下:(注意修改加粗部分内容)
com2sec notConfigUser ip 团体名称
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
access notConfigGroup “” any noauth exact all none none
view all included .1 80
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root (configure /etc/snmp/snmp.local.conf)
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat
设置系统启动
chkconfig –add snmpd
chkconfig snmpd on
2,部署check_traffic.sh
上传到nagios的安装目录libexec,并且授权755,属性为nagios的用户和组
chmod 755 check_traffic.sh
chown nagios.nagios check_traffic.sh
3、网卡参数检测
[iyunv@10.60.30.53 /usr/local/nagios/libexec]$ ./check_traffic.sh -V 2c -C 团体名称 -H 10.60.30.52 -L
List Interface for host 10.60.30.52.
RFC1213-MIB::ifDescr.1 orresponding to “lo”
RFC1213-MIB::ifDescr.2 orresponding to “eth0″
RFC1213-MIB::ifDescr.3 orresponding to “eth1″
RFC1213-MIB::ifDescr.4 orresponding to “eth2″
RFC1213-MIB::ifDescr.5 orresponding to “eth3″
RFC1213-MIB::ifDescr.6 orresponding to “sit0″
[iyunv@10.60.30.53 /usr/local/nagios/libexec]$
可以测试是否能够正常采集到数据(如果取不到,检查snmpd的团体名称、被监控者的IP,还有selinux是否关闭)
[iyunv@10.60.30.53 /usr/local/nagios/libexec]$ ./check_traffic.sh -V 2c -C 团体名称 -H 10.60.30.52 -I 2 -w 1200,1500 -c 1700,1800 -K -B
OK – The Traffic In is 0.37KB, Out is 0.75KB, Total is 1.12KB. The Check Interval is 1129s |In=0.37KB;1200;1700;0;0 Out=0.75KB;1500;1800;0;0 Total=1.12KB;2700;3500;0;0 Interval=1129s;1200;1800;0;0
[iyunv@10.60.30.53 /usr/local/nagios/libexec]$
解释:
-V snmp协议版本
-C 共同体名
-I 参数对应上面-L输出的网卡index值。标示监视相应的网卡。
-w 警告值 -c报警值
4,nagios的配置
增加nagios的command.cfg
# ‘check_traffic’ command definition
define command{
command_name check_traffic
command_line $USER1$/check_traffic.sh -V 2c -C 团体名称 -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$ -c $ARG3$ -K -B
}
解释:-I 第几个网卡 -K –B设置的报警参数数值是KB,不是MB
增加service.cfg
define service{
use generic-service ; Name of service template to use
host_name db_31
service_description check_eth0_traffic
check_command check_traffic!2!4000,5000!6000,7000;该处设置的是kB,不是MB
}
监控后情况:
图8-1
pnp画图情况:
图8-1
更多0
原创文章如转载请注明:ttlsa.com
http://www.xmydlinux.org/201011/51.html
本文所用到的监控流量插件来自"石头"的 1.20 版 shell 插件。感谢之。。。。
下载地址为: 点击下载 。 总体设置可以分为两块, linux 主机及非 linux 主机。稍有出入。不多说直接上配置
一、 linux主机
主要步骤:
1、安装snmpd服务软件包并设置启动之。
2、上传监控插件至被监控机nagios/libexec目录并授权
3、网卡参数检测
4、 nrpe.cfg文件增加监控command
5、 nagios服务器配置service.cfg添加监控项
| 具体实施:
1、 安装修改启动snmpd服务
安装:[iyunv@nagios nagios]# yum -y install net-snmp*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Setting up Install Process
Package 1:net-snmp-devel-5.3.2.2-9.el5_5.1.i386 already installed and latest version
Package 1:net-snmp-libs-5.3.2.2-9.el5_5.1.i386 already installed and latest version
Package 1:net-snmp-utils-5.3.2.2-9.el5_5.1.i386 already installed and latest version
Package 1:net-snmp-perl-5.3.2.2-9.el5_5.1.i386 already installed and latest version
Package 1:net-snmp-5.3.2.2-9.el5_5.1.i386 already installed and latest version
Nothing to do
#我已经安装过了。。就上面这些包了。。
| 修改snmpd.conf
# sec.name source community
com2sec notConfigUser 127.0.0.1(localhost也可不改) XXXX(共同体名)
# group context sec.model sec.level prefix read write notif
access notConfigGroup "" any noauth exact mib2 none none
#改system为mib2
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
#去掉前面的"#"注释符
|
2、上传插件被授权
上传check_traffic.sh至/usr/local/nagios/libexec
改属主为:nagios
chown nagios.nagios ./check_traffic.sh
|
3、网卡参数检测:
[iyunv@OAServer etc]# /usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -L
List Interface for host 127.0.0.1.
Interface index 1 orresponding to lo
Interface index 2 orresponding to bond0
Interface index 3 orresponding to eth0
Interface index 4 orresponding to eth1
Interface index 5 orresponding to sit0
| 可以测试是否能够正常采集到数据
/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 2 -w 1200,1500 -c 1700,1800 -K -b
OK - The Traffic In is 356Kbps, Out is 414Kbps, Total is 770Kbps. The Check Interval is 30s |In=356Kbps;1200;1700;0;0 Out=414Kbps;1500;1800;0;0 Total=770Kbps;2700;3500;0;0 Interval=30s;1200;1800;0;0
| 注:-V snmp协议版本
-C 共同体名
-I 参数对应上面-L输出的网卡index值。标示监视相应的网卡。
该插件其它使用方法及各参数解释详情"-help"或者看上面论坛石头描述
更改/var/tmp/check_traffic* 文件权限为nagios用户可读写。简单的给个777吧。。
chmod 777 /var/tmp/check_traffic_127.0.0.1_2.hist_dat_root__32
|
4、 更改nrpe.cfg增加如下行:
command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 2 -w 300,350 -c 500,600 -K -B
| 重启nrpe程序
[iyunv@OAServer ~]# ps aux |grep nrpe
nagios 2822 0.0 0.0 4808 1448 ? Ss Jun01 0:04 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
root 1123 0.0 0.0 5936 736 pts/2 S+ 11:02 0:00 grep nrpe
[iyunv@OAServer ~]# kill -9 2822
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
| 5、nagios服务器(监控端)编辑service.cfg增加监控网卡流量项目;
define service{
host_name WEB
service_description check_traffic
check_command check_nrpe!check_traffic
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups sagroup
}
|
二、其它设备:(win主机、交换、路由、防火墙)
这些主机上都是没办法安装nrpe插件的。所以我们只有通过snmp协议采集。(两者异同之处就在于snmp数据报文是否在网络传输。前者snmp数据只会在本机产生,自己采集自身数据而后由nrpe插件传输到nagios服务器前端显示出来(数据文件在本机)。后者则是nagios服务器通过snmp协议采集目标主机信息而后前端显示(数据文件在服务器)。就安全性而言,前者更优于后者。
主要步骤:
1、设置主机snmp协议(共同体名、权限、trap目标主机)
2、nagios服务器snmp连接测试及网卡参数确定
3、nagios服务器commands.cfg配置
4、service.cfg监控项目添加
5、重启nagios服务测试
|
具体实施:
演示设备:windows2003、netscreen防火墙、H3C路由以及H3C交换机。
1、 设置主机snmp协议
Windows主机:添加snmp组件。。在服务里找到"snmp service"编辑如下:
防火墙:
路由器:
交换机:
snmp-agent
snmp-agent local-engineid 800063A2000FE2CCFAA36877
snmp-agent community write XXXXX
snmp-agent sys-info version all
snmp-agent target-host trap address udp-domain XXXXXX params securityname XXXXX
|
1、 nagios服务器snmp连接测试及网卡参数确定:
以防火墙为例,找到个接口参数:
[iyunv@nagios nagios]# /usr/local/nagios/libexec/check_traffic.sh -V 2c -C ksense -H 192.168.20.254 -L
List Interface for host 192.168.20.254.
Interface index 1 orresponding to ethernet0/0
Interface index 2 orresponding to ethernet0/1
Interface index 3 orresponding to ethernet0/2
Interface index 4 orresponding to ethernet0/3
Interface index 5 orresponding to vlan1
注意:index 后数字和网卡对应关系。后面写service.cfg时需用到。
|
2、 配置commands.cfg增加如下内容:
[iyunv@nagios nagios]# tail -8 /usr/local/nagios/etc/commands.cfg
#######################################################################
#
#check_traffic
#
#######################################################################
define command{
command_name check_traffic
command_line $USER1$/check_traffic.sh -V 2c -C ksense -H $HOSTADDRESS$ -I $ARG1$ $ARG2$ $ARG3$ -K -B
}
| 3、 service.cfg监控项目添加:
以防火墙设备为例,其它方法相同
define service{
host_name juniper-ssg-320
service_description check_traffic_trust
check_command check_traffic!1 -w 600,600 -c 800,800
#注:叹号后面数据对应上面的"$ARG1$ $ARG2$ $ARG3$"3个字段,中间空格隔开
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups sagroup
}
define service{
host_name juniper-ssg-320
service_description check_traffic_DMZ
check_command check_traffic!2 -w 600,600 -c 800,800
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups sagroup
}
define service{
host_name juniper-ssg-320
service_description check_traffic_untrust1
check_command check_traffic!3 -w 600,600 -c 800,800
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups sagroup
}
define service{
host_name juniper-ssg-320
service_description check_traffic_untrust2
check_command check_traffic!4 -w 600,600 -c 800,800
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups sagroup
}
| 5、
[iyunv@nagios nagios]# !1025
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
………………
Total Warnings: 0
Total Errors: 0
检查下配置文件是否有报错。。。没有就重启nagios服务即可生效了。
|
监控效果图:
Pnp图形:
http://www.cnblogs.com/chinalinux/archive/2012/08/11/2633967.html
首先安装net-snmp的软件包
yum -y install net-snmp*
修改snmpd.conf文件
vim /etc/snmp/snmpd.conf
第41行 修改为 com2sec notConfigUser localhost public
第62行修改为:access notConfigGroup "" any noauth exact mib2 none none
第89行view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc 前面的注释去掉
启动snmpd服务
下载监控流量的脚本:http://www.chlinux.net/check_traffic.sh
添加nrpe命令:
command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 2 -w 300,300 -c 500,600 -K -B
重启nrpe
添加服务:
define service{
use local-service,srv-pnp
host_name localhost
service_description traffic
check_command check_nrpe!check_traffic
notifications_enabled 1
process_perf_data 1
}
重启nagios服务
效果图如下:
http://bbs.linuxtone.org/thread-21187-1-1.html
总有人问通过nagios怎么监控网络流量,这里就分享一下:
使用/usr/local/nagios/libexec/中的check_traffic.sh,不但可以监控Linux的网卡流量,也可以监控Windows服务器的流量,此脚本check_traffic.sh来源于网络,如果你的nagios里没有它就下载附件上传,并修改权限即可。
监控脚本 check_traffic.sh,上传至Nagios服务器 /usr/local/nagios/libexec/ 目录里
修改权限:
chown nagios.nagios check_traffic.sh
chmod 755 check_traffic.sh
1、Check_traffic.sh的用法
[iyunv@oracle libexec]#/usr/local/nagios/libexec/check_traffic.sh -h
Usage:
./check_traffic.sh [ -v ] [ -6 ] [ -r ] -V 1|2c|3 -C snmp-community -H host [ -L ] -I interface -w in, out-warning-value -c in, out-critical-value -K/M -B/b
Example:
./check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 4 -w 200,100 -c 300,200 -K -B
We can use -r to use Range Value Options:
Example:
./check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 4 -r -w 200-300,100-200 -c 100-400,50-250 -K -B
If you don't use -K/M -B/b options, default -K -b, corresponding to Kbps
Make sure that the check interval greater than 5 Seconds.
Or modify the Min_Interval var in this file Line 180.
And, if you want in Verbose mode, use -v, to check the debug messages in the file /tmp/check_traffic.$$.
Or use ./check_traffic.sh [ -v ] -V 1|2c|3 -C snmp-community -H host -L
To list all interfaces on specify host. 列出主机所有网络接口信息,这个可以知道网卡的index值
2、以IP:192.168.0.2的Windows 2008系统为例子:
获取值的默认单位是Kbps。
然后通过/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 192.168.0.2 -L
去确认自己要监控对象的网卡代号
List Interface for host 192.168.0.2.
Interface index 1 orresponding to MS TCP Loopback interface
Interface index 2 orresponding to Citrix PV Ethernet Adapt
输出信息中index后面的数字就是你要监控网卡的代号
可以自己通过命令先执行一下:
/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 192.168.0.2 -I 2 -w 10,10 -c 30,30
输出:
OK - The Traffic In is 4Kbps, Out is 0.0Kbps, Total is 4Kbps. The Check Interval is 127s |In=4Kbps;10;30;0;0 Out=0.0Kbps;10;30;0;0 Total=4Kbps;20;60;0;0 Interval=127s;1200;1800;0;0
V 代表snmp版本
C 代表community的名称
H 代表主机IP
I 代表网卡号
w 、c 代表的是黄色警告、红色报警 10,10 30,30(代表in,out)
一切OK后就能看到以下监控信息图:
注意:
如果以非nagios用户身份,手动测试执行过该脚本,请在正式使用该脚本前,删除/var/tmp下对应测试生成的/var/tmp/check_traffic_${Host}_${Interface}.hist_dat文件,否则会造成nagios用户无法读写该文件的错误。
还有出现以下提示的意思是:
OK - It's the first time for this plugins run. We'll get the data from the next time
意思是说,OK,没问题, - 这个插件是第一次为此运行。从下一次开始我们将得到相关的数据
The check interval must greater than 30 Seconds. But now it's 20. Please retry it later.
检查间隔必须大于30秒。但现在是20秒。请稍后重试。
check_traffic.rar(7.33 KB)
源自:http://www.cnyunwei.com/thread-1000-1-1.html
http://bbs.linuxtone.org/thread-7586-1-1.html
利用nagios-snmp-plugins.1.1.1.tgz 监控windows主机的网卡流量
步骤:
1、nagios-snmp-plugins安装
下载地址:http://sourceforge.net/projects/ ... .1.1.1.tgz/download
# tar zxvf nagios-snmp-plugins.1.1.1.tgz
安装nagios-snmp-plugins先得安装 install Net::SNMP perl module
# perl -MCPAN -e shell
cpan> install Net::SNMP
# cd nagios-snmp-plugins.1.1.1
# ./install
注:默认会安装在/usr/local/nagios/libexec目录
2、配置
2.1、添加以下内容到/usr/local/nagios/etc/objects/commands.cfg
define command{
command_name check_snmp_int
command_line $USER1$/check_snmp_int.pl -H $HOSTADDRESS$ -C $ARG1$ -n $ARG2$ -f -kB -Y -w$ARG3$,$ARG4$ -c $ARG5$,$ARG6$
}
2.2、在相应主机服务配置文件中添加以下内容
define service{
use generic-service
host_name winserver
service_description Bandwidth
check_command check_snmp_int!public!Broadcom NetXtreme Gigabit Ethernet!2!50!10!60
is_volatile 0
max_check_attempts 3
check_interval 1
retry_interval 1
check_period 24x7
notification_interval 5
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
register 1
}
注: check_snmp_int!public!Broadcom NetXtreme Gigabit Ethernet!2!50!10!60
Broadcom NetXtreme Gigabit Ethernet 为网卡名称
public 为snmp的团体名称
2,50 是input/output 警告报警
10,60是inout/putput 严重报警
3、监控
重启nagios服务
# /etc/init.d/nagios restart
如下图所示:
http://storysky.blog.iyunv.com/628458/623867
以前的nagios里面并没有在意过对网卡流量进行报警,直到前几天遭到ddos攻击,某个子站点的流量瞬间飙升到900Mb,虽然后来撑住了但是也受到了不小的影响,当时第一个报警的是
check_nginx 然后是 check_load 最后是check_cpu 为了完善监控项目,建议将网卡流量也加入到nagios的监控里面。之前记得石头写过一个监控网卡流量的脚本不知道更新没有。
打开石头版主的论坛页面 www.itnms.net 找到开源区 nagios 板块的精华贴,check_traffic.sh 果然在那里呢,而且不出所料 勤劳的石头兄把他更新到了1.2.2,呵呵。赶紧下载下来体验下吧
因为这个插件 涉及到了snmp协议,需要先确保 本地有没有安装net-snmp和net-snmp-utils,因为需要用到net-snmp-utils 的工具 snmpwalk,对于snmp并不需要进行什么设置,但要注意必须启动他。具体的教程可以看这个地址
http://www.itnms.info/discuz/viewthread.php?tid=767&extra=page%3D1%26amp%3Bfilter%3Ddigest
下面是通过命令行执行的效果:
./check_nrpe -c check_traffic -H 192.168.32.30
The check interval must greater than 30 Seconds. But now it's 21. Please retry it later.
每次检查之间需要间隔30秒,呵呵想的真周到
./check_nrpe -c check_traffic -H 192.168.3.30
OK - The Traffic In is 4.27Mbps, Out is 2.01Mbps, Total is 6.28Mbps.
The Check Interval is 75s |In=4.27Mbps;30;40;0;0 Out=2.01Mbps;20;30;0;0 Total=6.28Mbps;50;70;0;0 Interval=75s;1200;1800;0;0
加入到nagios 里的效果:
还有个功能让我很喜欢这个脚本,那就是石头把出图的部分也加进去了,考虑的很周到,下面几张图是网卡流量图,虽然和cacti的功能类似,但是这个更直接一些。
呵呵,再次感谢石头为大家写了这么实用的插件 O(∩_∩)O~
本文出自 “story的天空” 博客,请务必保留此出处http://storysky.blog.iyunv.com/628458/623867
http://www.itdhz.com/post-265.html
插件名称:check_iftraffic
功能说明:
1.监控网卡是否DOWN;
2.监控网卡是否有流量,并输出流量大小。
3.DOWN或者是无流量自动告警。
使用方法:
1.客户端配置
先下载check_iftraffic文件到/usr/local/nagios/libexec
1 | cd /usr/local/nagios/libexec |
2 | wgetftp://bsmp:1qaz2wsx@219.133.33.39/linux/nagios/check_iftraffic |
3 | chown nagios.nagios /usr/local/nagios/libexec/check_iftraffic |
4 | chmod 755 /usr/local/nagios/libexec/check_iftraffic | 然后在/usr/local/nagios/etc/nrpe.cfg文件中添加如下行
1 | command[check_iftraffic]=/usr/local/nagios/libexec/check_iftraffic eth0 eth1 |
2.主控端配置
修改你要监控的服务器的配置文件
vi /usr/local/nagios/etc/objects/gd_sw/119.146.208.32.cfg
添加如下内容
2 | use generic-service ; Name of service template to use |
3 | host_name gd_sw_119.146.208.10 |
4 | service_description check_iftraffic |
5 | check_command check_nrpe!check_iftraffic |
6 | contact_groups mt_gd_sw |
好了,到这里就完成了。但你还需要把主控程序重启一下让配置生效。
service nagios restart
然后你就可以看到如下效果图
标签:check_iftraffic流量监控
« 用rsync实现网站镜像和备份 | kickstart配置文件读取格式»
引用地址:
评论:
moper 2012-05-14 23:56
貌似用nagios的挺多,好东西哈。 |
http://blog.c1gstudio.com/archives/579
google一下snmp的漏洞,避免下载到未打补丁的版本
Net-SNMP远程绕过认证漏洞
受影响系统:
Net-SNMP net-snmp 5.4.x
Net-SNMP net-snmp 5.3.x
Net-SNMP net-snmp 5.2.x
不受影响系统:
Net-SNMP net-snmp 5.4.1.1
Net-SNMP net-snmp 5.3.2.1
Net-SNMP net-snmp 5.2.4.1
检查有无安装snmp
下载net-snmp
http://www.net-snmp.org/download.html
http://nchc.dl.sourceforge.net/sourceforge/net-snmp/net-snmp-5.4.2.1-1.f9.i386.rpm
http://nchc.dl.sourceforge.net/sourceforge/net-snmp/net-snmp-devel-5.4.2.1-1.f9.i386.rpm
http://nchc.dl.sourceforge.net/sourceforge/net-snmp/net-snmp-perlmods-5.4.2.1-1.f9.i386.rpm
安装snmp
error: Failed dependencies:
libc.so.6(GLIBC_2.4) is needed by net-snmp-5.4.2.1-1.i386
libc.so.6(GLIBC_2.7) is needed by net-snmp-5.4.2.1-1.i386
librpm-4.4.so is needed by net-snmp-5.4.2.1-1.i386
librpmio-4.4.so is needed by net-snmp-5.4.2.1-1.i386
检查glib版本
glibc-2.3.4-2
glibc-common-2.3.4-2
glibc-kernheaders-2.4-9.1.87
glibc-devel-2.3.4-2
glibc-headers-2.3.4-2
glibc升级风险比较大,改用soure编译
先安装beecrypt
- wget http://downloads.sourceforge.net/beecrypt/beecrypt-4.1.2.tar.gz
- tar zxvf beecrypt-4.1.2.tar.gz
- cd beecrypt-4.1.2
- ./configure --prefix=/usr
- make
_bc-py.c:8:20: Python.h: No such file or directory
rpm-python-4.3.3-18_nonptl
gnome-python2-bonobo-2.6.0-3
python-2.3.4-14.2
libxml2-python-2.6.16-6
python-elementtree-1.2.6-4.2.1
python-sqlite-1.1.7-1.2
gnome-python2-2.6.0-3
gnome-python2-canvas-2.6.0-3
mod_python-3.1.3-5.1
dbus-python-0.22-12.EL.7
MySQL-python-1.0.0-1.RHEL4.1
python-urlgrabber-2.9.8-2
没有python-devel,升级下python
http://blog.c1gstudio.com/archives/588
更新动态库
- ldconfig -v
- ln -s /lib/libelf.so.1 /usr/lib/libelf.so
安装net-snmp
- wget http://nchc.dl.sourceforge.net/sourceforge/net-snmp/net-snmp-5.4.2.1.tar.gz
- tar zxvf net-snmp-5.4.2.1.tar.gz
- cd net-snmp-5.4.2.1
- ./configure -enable-mfd-rewrites -with-default-snmp-version="2" -with-sys-contact="admin" -with-sys-location="China" -with-logfile="/var/log/snmpd.log" -with-persistent-directory="/var/net-snmp"
编译的输出
- SNMP Versions Supported: 1 2c 3
- Net-SNMP Version: 5.4.2.1
- Building for: linux
- Network transport support: Callback Unix TCP UDP
- SNMPv3 Security Modules: usm
- Agent MIB code: default_modules => snmpv3mibs mibII ucd_snmp notification notification-log-mib target agent_mibs agentx disman/event disman/schedule utilities host
- Embedded Perl support: enabled
- SNMP Perl modules: building -- embeddable
- SNMP Python modules: disabled
- Authentication support: MD5 SHA1
- Encryption support: DES AES
安装出错
- grep: /usr/lib/libbeecrypt.la: No such file or directory
- /bin/sed: can't read /usr/lib/libbeecrypt.la: No such file or directory
- libtool: link: `/usr/lib/libbeecrypt.la' is not a valid libtool archive
- #请安装beecrypt
- /usr/bin/ld: cannot find -lelf
- collect2: ld returned 1 exit status
- #ln -s libelf.so.1 /usr/lib/libelf.so
community string
网络设备在使用SNMP中都设有community string,它类似于简单的口令验证机制,用来确认是否具有可读或读写的权限。许多用户在购买设备以来,从未修改系统缺省的community string,因此非授权用户使用缺省口令就可以对重要的系统信息、设备的状态等进行修改。
将”COMMUNITY”字段改为你要设置的密码.比如”public”或privatepass.
将“localhost”改为你想哪台机器可以看到你的snmp信息,如localhost或10.10.10.10。
SNMP的版本
在SNMP协议得益于重大升级,因为在1988年推出。
不幸的是,很大比例的网络内容供应商,甚至一些网络管理系统厂商都没有利用这些改进。
许多网络元素只支持SNMPv1和SNMPv2c 。 支持SNMPv3的是最小的。
版本 描述
SNMPv1 SNMPv1 ,其中实施以社区为基础的安全
SNMPv2c SNMPv2以社区为基础的安全
SNMPv2u SNMPv2与基于用户的安全
SNMPv2 SNMPv2党为基础的安全
SNMPv3安全机制 SNMPv3安全机制,而实现基于用户的安全
配置snmp
- mkdir /usr/local/etc/snmp
- cp EXAMPLE.conf /usr/local/etc/snmp/snmpd.conf
- vi usr/local/etc/snmp/snmpd.conf
- # sec.name source community
- com2sec local localhost privatepass
- #com2sec mynetwork NETWORK/24 public
- ####
- # Second, map the security names into group names:
- # sec.model sec.name
- #group MyRWGroup v1 local
- #group MyRWGroup v2c local
- #group MyRWGroup usm local
- #group MyROGroup v1 mynetwork
- #group MyROGroup v2c mynetwork
- #group MyROGroup usm mynetwork
- group MyROGroup v1 local
- group MyROGroup v2c local
- ####
- # Third, create a view for us to let the groups have rights to:
- # incl/excl subtree mask
- #view all included .1 80
- view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
- ####
- # Finally, grant the 2 groups access to the 1 view with different
- # write permissions:
- # context sec.model sec.level match read write notif
- access MyROGroup "" any noauth exact mib2 none none
- #access MyRWGroup "" any noauth exact all all none
- #启动
- /usr/local/sbin/snmpd
- #加入启动
- echo '/usr/local/sbin/snmpd' >> /etc/rc.local
- #查看161端口是否开启
- netstat -ano|grep 161
- #测试
- snmpwalk -v 1 -c privatepass localhost system
SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost.localdomain 2.6.9-5.ELsmp #1 SMP Wed Jan 5 19:30:39 EST 2005 i686
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (2612) 0:00:26.12
SNMPv2-MIB::sysContact.0 = STRING: Me
SNMPv2-MIB::sysName.0 = STRING: localhost.localdomain
SNMPv2-MIB::sysLocation.0 = STRING: Right here, right now.
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (0) 0:00:00.00
SNMPv2-MIB::sysORID.1 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
SNMPv2-MIB::sysORID.2 = OID: SNMP-MPD-MIB::snmpMPDCompliance
SNMPv2-MIB::sysORID.3 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance
SNMPv2-MIB::sysORID.4 = OID: SNMPv2-MIB::snmpMIB
SNMPv2-MIB::sysORID.5 = OID: TCP-MIB::tcpMIB
SNMPv2-MIB::sysORID.6 = OID: IP-MIB::ip
SNMPv2-MIB::sysORID.7 = OID: UDP-MIB::udpMIB
SNMPv2-MIB::sysORID.8 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup
SNMPv2-MIB::sysORDescr.1 = STRING: The SNMP Management Architecture MIB.
SNMPv2-MIB::sysORDescr.2 = STRING: The MIB for Message Processing and Dispatching.
SNMPv2-MIB::sysORDescr.3 = STRING: The management information definitions for the SNMP User-based Security Model.
SNMPv2-MIB::sysORDescr.4 = STRING: The MIB module for SNMPv2 entities
SNMPv2-MIB::sysORDescr.5 = STRING: The MIB module for managing TCP implementations
SNMPv2-MIB::sysORDescr.6 = STRING: The MIB module for managing IP and ICMP implementations
SNMPv2-MIB::sysORDescr.7 = STRING: The MIB module for managing UDP implementations
SNMPv2-MIB::sysORDescr.8 = STRING: View-based Access Control Model for SNMP.
SNMPv2-MIB::sysORUpTime.1 = Timeticks: (0) 0:00:00.00
SNMPv2-MIB::sysORUpTime.2 = Timeticks: (0) 0:00:00.00
SNMPv2-MIB::sysORUpTime.3 = Timeticks: (0) 0:00:00.00
SNMPv2-MIB::sysORUpTime.4 = Timeticks: (0) 0:00:00.00
SNMPv2-MIB::sysORUpTime.5 = Timeticks: (0) 0:00:00.00
SNMPv2-MIB::sysORUpTime.6 = Timeticks: (0) 0:00:00.00
SNMPv2-MIB::sysORUpTime.7 = Timeticks: (0) 0:00:00.00
SNMPv2-MIB::sysORUpTime.8 = Timeticks: (0) 0:00:00.00
snmp安装完毕
安装check_traffic脚本
下载check_traffic_v1.1.6.zip脚本
http://www.itnms.net/discuz/viewthread.php?tid=767&extra=pageD1&page=1
上传./check_traffic.sh 至/usr/local/nagios/libexec
- cd /usr/local/nagios/libexec/
- chown nagios:nagios ./check_traffic.sh
- chmod 755 ./check_traffic.sh
用 -L选项列出对应主机所有的interface,来确定你要监控的网络接口(如果能你确认接口的index值,这一步可以省略)。
通过输出,我们确认要监控的网络接口为4,对应为”Macronix MX98715-Based Ethernet Adapter (Generic) – 数据包计划程序微型端口”
- ./check_traffic.sh -V 2c -C privatepass -H localhost -L
List Interface for host localhost.
Interface index 1 orresponding to lo
Interface index 2 orresponding to eth0
Interface index 3 orresponding to eth1
Interface index 4 orresponding to sit0
按照说明,选择版本为2c(一般选择1或者2c),community为privatepass,interface为2,单位为KB/s,in流量对应warning/critical值为200/400,out流量对应warning/critical值为300/500.
- sudo -u nagios ./check_traffic.sh -V 2c -C privatepass -H localhost -I 2 -w12,30 -c15,50 -K -b
Can not found data in the history data file.
If it’s the first time for this plugins, that’s OK.
Otherwise,please use debug mode and check the debug file.
第一次执行,因为history data file不存在,因此会由此提示,可以忽略。
如果每次执行都忽略,则要检查/var/tmp下是否有/var/tmp/check_traffic_${Host}_${Interface}.hist_dat文件生成。
文件的内容是系统当前的时间,in及out当前的数值。
nagios监控本机的配置
修改/usr/local/nagios/etc/objects/commands.cfg,增下以下内容
- define command{
- command_name check_traffic_nv
- command_line $USER1$/check_traffic.sh -V 2c -C privatepass -H localhost -I $ARG1$ -w $ARG2$ -c $ARG3$ -M -b
- }
修改/usr/local/nagios/etc/objects/localhost.cfg,增下以下内容
- define service{
- use local-service,srv-pnp ; Name of service template to use
- host_name nagios
- service_description check_nv_traffic_eth0
- check_command check_traffic_nv!2!12,30!15,35
- notifications_enabled 0
- normal_check_interval 5 ;5分钟
- retry_interval 1 ;1分钟
- }
nagios监控远程机的配置
修改/usr/local/nagios/etc/objects/remotehost.cfg,增下以下内容
- define service{
- use local-service,srv-pnp ; Name of service template to use
- host_name nagios
- service_description check_nv_traffic_eth0
- check_command check_nrpe!check_traffic_nv
- notifications_enabled 0
- normal_check_interval 5 ;5分钟
- retry_interval 1 ;1分钟
- }
修改/usr/local/nagios/etc/nrpe.cfg增加以下内容
- command[check_traffic_nv]=/usr/local/nagios/libexec/check_traffic_nv.sh -V 2c -C privatepass -H localhost -I 2 -w 12,30 -c 15,35 -M -b
访问http://localhost/nagios
点击Service Detail
点击check_nv_traffic_eth0服务旁的小太阳
等5分钟后就可以看到图表
which: no snmpwalk in (/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin)
如果check_nv_traffic_eth0服务报找不到snmpwalk.
- ln -s /usr/local/bin/snmpwalk /usr/bin/snmpwalk
有时我作的软链接会丢失,挺奇怪的。。。
http://space.itpub.net/20575781/viewspace-709840
一共三种方法
A、利用nagios自带的插件check_mrtgtraf对网卡流量进行监控
这种方法要依赖mrtg数据,并且使用起来就Bytes和Bites换算也有点问题,不推荐使用。
这里只简单介绍下check_mrtgtraf ,它定时检查mrtg的日志文件,获取当前流量
如下例子,但该插件个人觉得功能简单切有限 ,自己已经弃用。
/u/nagios/libexec/check_mrtgtraf -F /var/www/html/mrtg/192.168.0.21_2.log -a AVG -w 300000,300000 -c 400000,400000 -e 1
Traffic WARNING - Avg. In = 295.2 KB/s, Avg. ut = 58.7 KB/s|in=295.211914KB/s;300000.000000;400000.000000;0.000000 in=58.667969KB/s;300000.000000;400000.000000;0.000000
B、网络流传其他一类的流量监测方法的脚本,我试用了几个最终感觉还是不太方便。
不要感觉到坑爹,笔者也是使用了以上两种方法之后最终选择下面这一种的,方便快捷功能强。
C、使用check_snmp_int.pl 插件监控网络
推荐使用,简单方便功能多,流量计算也比较准确(我是和同步的mrtg监控和cacti监控页面对比过数据)。
参考页面http://nagios.manubulon.com/snmp_int.html
下载地址http://nagios.manubulon.com/check_snmp_int.pl
前提:您的要被监控的主机也要开放snmp服务才行。
环境:nagios监控服务器和被监控服务器均是linux服务器
1、下载该插件到nagios监控服务器
首先确保监控服务器上snmp和perl相关包都已安装,执行以下语句测试是否返回正确值。
perl check_snmp_int.pl -H 192.168.0.21 -C zjhcsoft -n eth1 -k -Y -B -w 200,400 -c 0,800
该语句表示:-H 表示监控192.168.0.21服务器 -C 表示组织名称为 zjhcsoft -n 表示检查eth1 网卡 -Y -B 联合使用表示返回的是以bits/s的网卡流量 -w 和-c 表示警告伐值 in伐值,out伐值
确定手动执行可以返回正确结果如下,如果超过-c的伐值会有如下警告
eth1:UP (WARN 5095.5Kbps/CRIT 37443.9Kbps):(1 UP): CRITICAL
2、确定该插件正常使用后配置nagios
编辑 commands.cfg文件,创建一个本地命令
[iyunv@cacti objects]# vi commands.cfg
# 'check_snmp_int_iftraffic' command definition
define command{
command_name check_snmp_int_iftraffic
command_line $USER1$/check_snmp_int.pl -H $HOSTADDRESS$ -C $ARG1$ -n $ARG2$ -k -Y -B -w $ARG3$ -c $ARG4$
}
创建检查服务,编辑配置文件
[iyunv@cacti objects]# vi network_interface_service.cfg
define service{
use generic-service ; Inherit values from a template
host_name web1,web2,web3,web4,web6
service_description Output Interface Bandwidth Usage
check_command check_snmp_int_iftraffic!zjhcsoft!eth2!1200,5000!2000,10000
notifications_enabled 0
}
检查配置无误
[nagios@cacti objects]$ /u/nagios/bin/nagios -v /u/nagios/etc/nagios.cfg
重启nagios
[iyunv@cacti objects]# service nagios restart
3、检查nagios监控页面确定页面返回正常监控数据
补充:以上是snmp v1版本的 如果设备是v2版本 就要加一个参数‘-2’,在nagios再新配置一个v2版本的本地命令
# 'check_snmp_int_iftraffic_v2' command definition
define command{
command_name check_snmp_int_iftraffic
command_line $USER1$/check_snmp_int.pl -H $HOSTADDRESS$ -C $ARG1$ -2 -n $ARG2$ -k -Y -B -w $ARG3$ -c $ARG4$
}
监控snmp为v2版本的网络设备
define service{
use generic-service ; Inherit values from a template
host_name Netscreen ISG 2000
service_description Output Interface Bandwidth Usage
check_command check_snmp_int_iftraffic_v2!zjhcsoft!ethernet1/1!1200,5000!2000,10000
notifications_enabled 0
}
4、遇到问题
[iyunv@cacti libexec]# perl check_snmp_int.pl -H 192.168.0.21 -C zjhcsoft -n eth1 -k -w 200,400 -c 0,800
eth1:UP No usable data on file (1 rows) :(1 UP): UNKNOWN
[iyunv@cacti libexec]# perl check_snmp_int.pl -H 192.168.0.21 -C zjhcsoft -n eth1 -k -w 200,400 -c 0,800
eth1:UP No usable data on file (2 rows) :(1 UP): UNKNOWN
网站解释:
(我总结下就是最好执行时间超过5分钟,这样才有正确结果可以返回,我没有修改默认数值,有兴趣的同学可以深入研究下。) |
|