RH442-1 利用snmp和mrtg监控linux服务器的网络流量

简介:

 利用snmp和mrtg监控linux服务器的网络流量

一、环境

snmpd、mrtg服务器:station2.example.com: 192.168.32.32

      被监控客户端:station3.example.com:192.168.32.33

二、snmp服务器端安装和配置(station2)

1.      snmp安装

[root@station2 ~]# yum install net-snmp.i386

[root@station2 ~]#yuminstall net-snmp-devel.i386

[root@station2 ~]#yum install net-snmp-utils.i386

 

2.      snmp配置

[root@station2 ~]# snmptranslate -On SNMPv2-MIB::system

.1.3.6.1.2.1.1                  #查看system在mib中oid号

 

[root@station2 ~]#cp /etc/snmp/snmpd /etc/snmp/snmpd.orig  

#备份snmpd文件,默认情况下在运行snmpconf命令进行配置snmp是会覆盖此文件

[root@station2 ~]# snmpconf    

The following installed configuration files were found:

   1:  ./snmpd.conf

   2:  /etc/snmp/snmpd.conf

Would you like me to read them in?  Their content will be merged with the

output files created by this session.

Valid answer examples: "all", "none","3","1,2,5"

Read in which (default = all): 2      

 #读取/etc/snmp/snmpd.conf文件内容,并将其内容加入到新配置文件中

 

I can create the following types of configuration files for you.

Select the file type you wish to create:

(you can create more than one as you run this program)

   1:  snmpd.conf

   2:  snmptrapd.conf

   3:  snmp.conf

Other options: quit

Select File: 1    

#选择配置文件名,默认路径在当前目录下

The configuration information which can be put into snmpd.conf is divided

into sections.  Select a configuration section for snmpd.conf

that you wish to create:

   1:  Trap Destinations

   2:  System Information Setup

   3:  Monitor Various Aspects of the Running Host

   4:  Extending the Agent

   5:  Access Control Setup

   6:  Agent Operating Mode

Other options: finished

Select section: 5     

#选择配置类型,5是访问配置,要通过snmp监控系统信息,得先配置访问控制

 

Section: Access Control Setup

Description:

  This section defines who is allowed to talk to your running

  snmp agent.

Select from:

   1:  a SNMPv3 read-write user

   2:  a SNMPv3 read-only user

   3:  a SNMPv1/SNMPv2c read-only access community name

   4:  a SNMPv1/SNMPv2c read-write access community name

Other options: finished, list

Select section: 3

#范围权限,选择3通过community(访问密码)进行只读访问

 

Configuring: rocommunity

Description:

  a SNMPv1/SNMPv2c read-only access community name

    arguments:  community [default|hostname|network/bits] [oid]

The community name to add read-only access for: example  

#example是community即访问密码

The hostname or network address to accept this community name from [RETURN for all]: 0.0.0.0/0                  #可访问得网段

The OID that this community should be restricted to [RETURN for no-restriction]:  #snmp监控类型,回车则表示监控所有信息。

Finished Output: rocommunity  example 0.0.0.0/0

Section: Access Control Setup

Description:

  This section defines who is allowed to talk to your running

  snmp agent.

Select from:

   1:  a SNMPv3 read-write user

   2:  a SNMPv3 read-only user

   3:  a SNMPv1/SNMPv2c read-only access community name

   4:  a SNMPv1/SNMPv2c read-write access community name

Other options: finished, list

Select section: finished                   #保存配置         

The configuration information which can be put into snmpd.conf is divided

into sections.  Select a configuration section for snmpd.conf

that you wish to create:

   1:  Trap Destinations

   2:  System Information Setup

   3:  Monitor Various Aspects of the Running Host

   4:  Extending the Agent

   5:  Access Control Setup

   6:  Agent Operating Mode

Other options: finished

Select section: finished

I can create the following types of configuration files for you.

Select the file type you wish to create:

(you can create more than one as you run this program)

   1:  snmpd.conf

   2:  snmptrapd.conf

   3:  snmp.conf

 

Other options: quit

Select File: quit

Error: An snmpd.conf file already exists in this directory.

'overwrite', 'skip', 'rename' or 'append'? : overwrite   #覆盖原配置文件

The following files were created:

  snmpd.conf 

These files should be moved to /usr/share/snmp if you

want them used by everyone on the system.  In the future, if you add

the -i option to the command line I'll copy them there automatically for you.

Or, if you want them for your personal use only, copy them to

/root/.snmp .  In the future, if you add the -p option to the

command line I'll copy them there automatically for you.

 

[root@station2 ~]# cp snmpd.conf /etc/snmp/snmpd.conf

cp:是否覆盖“/etc/snmp/snmpd.conf”? y   #将新配置文件覆盖原配置文件

 

[root@station2 ~]# cat /etc/snmp/snmpd.conf |grep example

#   example: pass .1.3.6.1.4.1.2021.255 /path/to/local/passtest

rocommunity  example 0.0.0.0/0

 

3.      启动snmpd服务

[root@station2 ~]# service snmpd start

启动 snmpd:                                               [确定]

 

[root@station2 ~]# chkconfig snmpd on

 

[root@station2 /]# snmpwalk -v1 -c example station2.example.com

#根据community为example查看stationa2.example的信息

SNMPv2-MIB::sysDescr.0 = STRING: Linux station2.example.com 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:43 EDT 2010 i686

SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10

DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (7433) 0:01:14.33

SNMPv2-MIB::sysContact.0 = STRING: Root <root@localhost> (configure /etc/snmp/snmp.local.conf)

SNMPv2-MIB::sysName.0 = STRING: station2.example.com

SNMPv2-MIB::sysLocation.0 = STRING: Unknown (edit /etc/snmp/snmpd.conf)

SNMPv2-MIB::sysORLastChange.0 = Timeticks: (1) 0:00:00.01

SNMPv2-MIB::sysORID.1 = OID: SNMPv2-MIB::snmpMIB

SNMPv2-MIB::sysORID.2 = OID: TCP-MIB::tcpMIB

SNMPv2-MIB::sysORID.3 = OID: IP-MIB::ip

SNMPv2-MIB::sysORID.4 = OID: UDP-MIB::udpMIB

SNMPv2-MIB::sysORID.5 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup

SNMPv2-MIB::sysORID.6 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance

SNMPv2-MIB::sysORID.7 = OID: SNMP-MPD-MIB::snmpMPDCompliance

SNMPv2-MIB::sysORID.8 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance

SNMPv2-MIB::sysORDescr.1 = STRING: The MIB module for SNMPv2 entities

SNMPv2-MIB::sysORDescr.2 = STRING: The MIB module for managing TCP implementations

SNMPv2-MIB::sysORDescr.3 = STRING: The MIB module for managing IP and ICMP implementations

。。。。。。

End of MIB

 

三、snmpd客户端口配置(station3)

1.      安装

[root@station2 ~]# yum install net-snmp.i386

2.      将stationa2的配置文件复制并覆盖station3的原配置文件

 [root@station3 ~]# scp 192.168.32.32:/etc/snmp/snmpd.conf /etc/snmp/snmpd.conf

root@192.168.32.32's password:

snmpd.conf                                 100% 2771     2.7KB/s   00:00   

 

3.      启动snmpd代理服务

[root@station3 snmp]# service snmpd start

启动 snmpd:                                               [确定]

[root@station3 snmp]# chkconfig snmpd on

 

四、服务器端mrtg的安装和配置(station2)

1.      mrtg安装

[root@station2 ~]# yum install mrtg

#注在此默认httpd已经安装并配置,安装mrtg后会默认生成一个httpd配置文件/etc/httpd/conf.d/mrtg

 

2.      配置mrtg

[root@station2 /]# cfgmaker --ifref=name --global "workdir:/var/www/mrtg" example@station2.example.com example@station3.example.com >/etc/mrtg/mrtg.cfg

#根据snmpd的community定义mrtg的报表配置文件

 

[root@station2 /]# cat /etc/cron.d/mrtg   

*/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

#该文件是安装mrtg时默认生成,表示每5分钟做一次数据读取

 

[root@station2 /]# 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

#根据/etc/cron.d/mrtg中内容读取数据生成报表,要执行3次此命令才会不提示错误并成功。

 

[root@station2 /]# indexmaker /etc/mrtg/mrtg.cfg>/var/www/mrtg/index.html

#根据mrtg配置文件生成mrtg的默认首页

 

3.     配置httpd并测试

[root@station2 conf.d]# vi /etc/httpd/conf.d/mrtg.conf

Alias /mrtg /var/www/mrtg

<Location /mrtg>

    Order deny,allow

    Deny from all

    Allow from 0.0.0.0/0.0.0.0     #配置/var/www/mrtg的访问权限

</Location>

[root@station2 conf.d]#servie httpd restart

通过IE访问http://192.168.32.32/mrtg


 

 

 

 

本文转自netsword 51CTO博客,原文链接:http://blog.51cto.com/netsword/557957


相关文章
|
存储 弹性计算 网络协议
阿里云服务器ECS实例规格族是什么?不同规格CPU型号、处理器主频及网络性能参数均不同
阿里云ECS实例规格族是指具有不同性能特点和适用场景的实例类型集合。不同规格族如计算型c9i、通用算力型u1、经济型e等,在CPU型号、主频、网络性能、云盘IOPS等方面存在差异。即使CPU和内存配置相同,性能参数和价格也各不相同,适用于不同业务需求。
1008 144
|
JSON 监控 API
在线网络PING接口检测服务器连通状态免费API教程
接口盒子提供免费PING检测API,可测试域名或IP的连通性与响应速度,支持指定地域节点,适用于服务器运维和网络监控。
2468 0
|
机器学习/深度学习 存储 监控
内部文件审计:企业文件服务器审计对网络安全提升有哪些帮助?
企业文件服务器审计是保障信息安全、确保合规的关键措施。DataSecurity Plus 是由卓豪ManageEngine推出的审计工具,提供全面的文件访问监控、实时异常告警、用户行为分析及合规报告生成功能,助力企业防范数据泄露风险,满足GDPR、等保等多项合规要求,为企业的稳健发展保驾护航。
542 0
|
弹性计算 安全 Linux
阿里云服务器ECS安装宝塔Linux面板、安装网站(新手图文教程)
本教程详解如何在阿里云服务器上安装宝塔Linux面板,涵盖ECS服务器手动安装步骤,包括系统准备、远程连接、安装命令执行、端口开放及LNMP环境部署,手把手引导用户快速搭建网站环境。
|
存储 监控 Linux
Dell OpenManage Enterprise 4.5 - Dell 服务器、存储和网络设备集中管理软件
Dell OpenManage Enterprise 4.5 - Dell 服务器、存储和网络设备集中管理软件
455 0
|
监控 Linux 网络安全
FinalShell SSH工具下载,服务器管理,远程桌面加速软件,支持Windows,macOS,Linux
FinalShell是一款国人开发的多平台SSH客户端工具,支持Windows、Mac OS X和Linux系统。它提供一体化服务器管理功能,支持shell和sftp同屏显示,命令自动提示,操作便捷。软件还具备加速功能,提升访问服务器速度,适合普通用户和专业人士使用。
4830 0
|
存储 监控 Linux
zabbix使用snmp监控Linux主机(二十)
使用snmp监控Linux主机 1.snmp协议介绍 SNMP(简单网络管理协议)也是应用层的一种协议,默认端口号为161,我们平时监控Linux主机都是安装一个agent客户端进行监控,但是有的公司还需要监控网络设备和Windows主机,这时就不得不采用snmp协议去监控设备了
1338 0
zabbix使用snmp监控Linux主机(二十)
|
存储 监控
第六十五章 使用 SNMP 监控 IRIS - 用户定义的 SNMP 监视器类示例
第六十五章 使用 SNMP 监控 IRIS - 用户定义的 SNMP 监视器类示例
308 0
|
监控 程序员 数据库
第六十四章 使用 SNMP 监控 IRIS - 扩展 IRIS MIB
第六十四章 使用 SNMP 监控 IRIS - 扩展 IRIS MIB
356 0
|
监控 网络协议 Unix
第六十三章 使用 SNMP 监控 IRIS - SNMP 故障排除
第六十三章 使用 SNMP 监控 IRIS - SNMP 故障排除
322 0