snmp网络管理协议、mrtg系统监测

什么是网络管理

  监督、组织和控制网络通信服务和信息处理所必需的各种活动的总称

  利用多种应用程序、工具和设备来监控和维护网络运行的一种技术

网络管理组成

被管理设备、网络管理代理、网管工作站、管理信息库、网络管理协议

网络管理协议

定义了管理工作站与被管理代理间的通信方法

SNMP协议->SNMPv1、SNMPv2和SNMPv3

轮询(Polling)和中断(Interrupe)

基于UDP协议

  -所有报文(除Trap)都使用161号端口

  -Trap报文使用162号端口

共同体名(community)

  -只读

  -读写

常用网络管理软件

可网管的企业设备

  路由器、交换机、windows服务器、Linux服务器、打印机...

配置snmp服务

1.安装snmp软件包

yum -y install net-snmp*

2.编辑snmp配置文件

--备份默认配置文件
mv /etc/snmp/snmpd.conf   /etc/snmp/snmpd.conf.bak
--新建配置文件
vi /etc/snmp/snmpd.conf

rocommunity public

3.重启服务

--开机启动
chkconfig snmpd on
--启动服务
service snmpd start

snmp常用指令

--查看系统所有的oid以及oid名称
snmpwalk -vl -cpublic localhost -m all
--查看该oid的描述
snmptranslate -Td .1.3.6.1.4.1.2021.9.1.8.1
--查看该oid的oid名称和值
snmpgt -vl -cpublic localhost .1.3.6.1.4.1.2021.9.18.1
--snmpget查到的是snmpwalk -vl -cpublic localhost -m all的一部分

mrtg系统监控

安装mrtg

yum -y install mrtg*

1.snmp调试

2.修改mrtg配置文件

--获取内存使用率,硬盘使用率 加入配置文件
[root@localhost mrtg]# free -k
             total       used       free     shared    buffers     cached
Mem:        515308     478716      36592          0      54880     325204
-/+ buffers/cache:      98632     416676
Swap:      1048568          0    1048568

[root@localhost mrtg]# df -k
文件系统               1K-块        已用     可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
                      19172036   4828168  13354276  27% /
/dev/sda1               101086     12239     83628  13% /boot
tmpfs                   257652         0    257652   0% /dev/shm
#Minimal mrtg.cfg
#----------------

HtmlDir: /var/www/mrtg
ImageDir: /var/www/mrtg
LogDir: /var/lib/mrtg
ThreshDir: /var/lib/mrtg

#----------------------------------------------
#监视eth0网卡(连接公网的)
#----------------------------------------------
Target[eth0_lan]: /192.168.10.130:public@localhost:
Options[eth0_lan]: growright
Directory[eth0_lan]: eth0
MaxBytes[eth0_lan]: 100000000
Kmg[eth0_lan]: K,M,G
YLegend[eth0_lan]: Bytes per Second
ShortLegend[eth0_lan]: B/s
Legend1[eth0_lan]: 每秒流入量 (单位 Bytes)
Legend2[eth0_lan]: 每秒流出量 (单位 Bytes)
LegendI[eth0_lan]: 流入:
LegendO[eth0_lan]: 流出:
Title[eth0_lan]: eth0网络流量[流入+流出]
PageTop[eth0_lan]: <h1>eth0网络流量【流入+流出】</h1>

#----------------------------------------------------------
#监视CPU负载[用户+闲置]
#----------------------------------------------------------
Target[cpuload]: .1.3.6.1.4.1.2021.11.50.0&.1.3.6.1.4.1.2021.11.53.0:public@localhost:
Options[cpuload]: nopercent,growright
Directory[cpuload]: cpu
MaxBytes[cpuload]: 100
Unscaled[cpuload]: dwym
YLegend[cpuload]: CPU Utilization
ShortLegend[cpuload]: %
Legend1[cpuload]: CPU用户负载(%)
Legend2[cpuload]: CPU闲置(%)
LegendI[cpuload]: 用户:
LegendO[cpuload]: 闲置:
Title[cpuload]: CPU负载[用户+闲置]
PageTop[cpuload]: <h1>CPU负载【用户+闲置】</h1>

#----------------------------------------------------------
#监视内存使用量[Mem+Swap]
#----------------------------------------------------------
Target[memory]:.1.3.6.1.2.1.25.2.3.1.6.1&.1.3.6.1.2.1.25.2.3.1.6.10:public@localhost:
Options[memory]: gauge,growright
Directory[memory]: mem
MaxBytes1[memory]: 515308
MaxBytes2[memory]: 1048568
Kmg[memory]: K,M,G
Kilo[memory]: 1024
Unscaled[memory]: dwym
YLegend[memory]: Mem Bytes
ShortLegend[memory]: B
Legend1[memory]: 已用Mem (Bytes)
Legend2[memory]: 已用Swap (Bytes)
LegendI[memory]: 已用Mem:
LegendO[memory]: 已用Swap:
Title[memory]: 内存使用量[Mem+Swap]
PageTop[memory]: <h1>内存使用量【Mem+Swap】</h1>

#----------------------------------------------------------
#监视硬盘空间[根分区+boot分区]
#----------------------------------------------------------
Target[disk]: .1.3.6.1.4.1.2021.9.1.8.1&.1.3.6.1.4.1.2021.9.1.8.2:public@localhost:
Options[disk]: gauge,growright
Directory[disk]: disk
MaxBytes1[disk]: 19172036
MaxBytes2[disk]: 101086
Kmg[disk]: K,M,G
Kilo[disk]: 1024
Unscaled[disk]: dwym
YLegend[disk]: Disk Bytes
ShortLegend[disk]: B
Legend1[disk]: 根分区已用空间
Legend2[disk]: boot分区已用空间
LegendI[disk]: 根分区已用:
LegendO[disk]: boot分区已用:
Title[disk]: 硬盘空间[根分区+boot分区]
PageTop[disk]: <h1>硬盘空间【根分区+boot分区】</h1>
/etc/mrtg/mrtg.cfg

3.cron轮循生成监控图片文件

目录/etc/cron.d下已经存在计划任务的脚本,因此不用自己写,系统会自己执行该目录下的脚本

--cron.d

*/5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg
_l --confcache-file /var/lib/mrtg/mrtg.ok

将5分钟执行一次改为2分钟执行一次,复制下面的指令

LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg
_l --confcache-file /var/lib/mrtg/mrtg.ok

在终端连续执行三次,没有报错,则说明执行正确。

4.生成首页index.html

用indexmake生成mrtg监控首页文件

[root@localhost proc]# indexmaker --output /var/www/mrtg/index.html --title="System state Monitor" /etc/mrtg/mrtg.cfg

配置虚拟目录到/var/www/mrtg下,然后访问该目录,出现如下图:

 

posted on 2016-06-16 23:07  gimin  阅读(390)  评论(0)    收藏  举报