Linux CentOS5.5 安装MRTG 实现网卡流量监控

 

一.安装snmp和mrtg

 yum -y sysstat install net-snmp net-snmp-utils net-snmp-devel mrtg http

 

二.使用snmpconf命令配置SNMP

 

[root@bogon ~]# snmpconf 

 

The following installed configuration files were found:

 

   1:  /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): 1

选择要修改的snmp配置文件

 

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

修改后的文件存放在当前目录下,并命名为snmpd.conf

 

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:  Access Control Setup

   3:  Monitor Various Aspects of the Running Host

   4:  Agent Operating Mode

   5:  Extending the Agent

   6:  System Information Setup

 

Other options: finished

 

Select section: 2

添加可用的帐号

 

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

添加基于SNMPv1/SNMPv2版本协议的只读权限帐号

 

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: local

此帐号的名称为local

The hostname or network address to accept this community name from [RETURN for all]: 127.0.0.1

此帐号只允许通过127.0.0.1这个地址登录,也就是不允许本机以外的服务器通过local得到SNMP信息

 

The OID that this community should be restricted to [RETURN for no-restriction]:  <Enter>

直接回车,不输入任何OID,表示此帐号可以访问本机所有的SNMP信息

Finished Output: rocommunity  local 127.0.0.1 

 

 

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

 

添加基于SNMPv1/SNMPv2版本协议的只读权限帐号

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: mynet

此帐号的名称为mynet

The hostname or network address to accept this community name from [RETURN for all]: 172.29.141.0/24

此帐号只允许通过172.29.141.0/24这个网段登录

The OID that this community should be restricted to [RETURN for no-restriction]: 1.3.6.1.2.1.1

此帐号只能访问服务器中OID编号为1.3.6.1.2.1.1的SNMP信息

Finished Output: rocommunity  mynet 172.29.141.0/24 1.3.6.1.2.1.1

 

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

输入 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:  Access Control Setup

   3:  Monitor Various Aspects of the Running Host

   4:  Agent Operating Mode

   5:  Extending the Agent

   6:  System Information Setup

 

Other options: finished

 

Select section: finished

输入 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

输入 quit

 

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.

 

三.启动SNMP

 mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak

 mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak

 /etc/init.d/snmpd restart

 chkconfig snmpd on

 

四.配置MRTG

1. cfgmaker --global "WorkDir: /var/www/html" --global "Options[_]: growright,bits" --ifref=name local@127.0.0.1 > /etc/mrtg/mrtg.cfg

生成新的MRTG配置文件,通过local登录127.0.0.1,并依据网卡设备名进行数据流量统计,统计的时间轴从右到作推移,并以bit为单位,统计的结果数据存放在/var/www/html中

 

2.indexmaker /etc/mrtg/mrtg.cfg > /var/www/html/mrtg.html

通过/etc/mrtg/mrtg.cfg这个配置文件生成用于http访问的页面文件mrtg.html

 

3.vi  /etc/cron.d/mrtg  输入

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

 

4.执行三次 

 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.修改 /etc/httpd/conf.d/mrtg.conf  ,去掉 “Allow  from "  前面的 #  

 

6.执行  /etc/init.d/httpd  restart   开启  httpd服务器  

注意,如果已经有 其他web server占用80端口,则不能开启httpd

 

五.打开   浏览器,输入   http://127.0.0.1/mrtg.html  可看到统计结果

 

声明:本文档可以随意更改,但必须署名原作者

作者:凤凰舞者 qq:578989855

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值