Linux服务器---流量监控MRTG

MRTG

       MRTG可以分析网络流量,但是它必须依赖SNMP协议。将收集到的数据生成HTML文件,以图片的形式展示出来

1、安装一些依赖软件

[root@localhost bandwidthd-2.0.1]# yum install -y net-snmp

 

2、配置snmp,编辑配置文件“/etc/snmp/snmpd.conf”

[root@localhost bandwidthd]# gedit /etc/snmp/snmpd.conf

view    systemview    included  .1.3.6.1.2.1.1

view    systemview    included  .1.3.6.1.2.1.25.1.1

view    systemview    included  .1.3.6.1.2.1.2

 

3、启动snmp服务

[root@localhost bandwidthd]# service snmpd start

正在启动snmpd                                           [确定]

[root@localhost bandwidthd]#

 

4、下载bandwidthd软件(https://oss.oetiker.ch/mrtg/pub/?M=D),或者以yum方式在线安装

[root@localhost bandwidthd]# yum install -y mrtg

 

5、修改配置文件”/etc/httpd/conf.d/mrtg.conf”

[root@localhost bandwidthd]# gedit /etc/httpd/conf.d/mrtg.conf 

<Location /mrtg>

    Order deny,allow

#    Deny from all      //这句要注释掉

    Allow from all      //这里为all,允许检测所有ip

    Allow from ::1

    # Allow from .example.com

</Location>

 

6、生成mrtg文件,并做一些修改。

[root@localhost bandwidthd]# cfgmaker public@192.168.0.113>/etc/mrtg/mrtg.cfg       //生成文件,注意ip地址需要用户自己设置

[root@localhost bandwidthd]# gedit /etc/mrtg/mrtg.cfg      //修改文件

#  for UNIX

 WorkDir: /var/www/mrtg      //当前处于centos系统,因此这句去掉注释.这个路径是apache下的网页路径

#  or for NT

# WorkDir: c:\mrtgdata

### Global Defaults

#  to get bits instead of bytes and graphs growing to the right

 

 Options[_]: growright, bits    //去掉注释

 

7、生成html文件,执行三次指令

[root@localhost bandwidthd]# env LANG=C mrtg /etc/mrtg/mrtg.cfg   //第一次

2018-08-22 14:50:00, Rateup WARNING: /usr/bin/rateup could not read the primary log file for 192.168.0.113_2

2018-08-22 14:50:00, Rateup WARNING: /usr/bin/rateup The backup log file for 192.168.0.113_2 was invalid as well

2018-08-22 14:50:00, Rateup WARNING: /usr/bin/rateup Can't remove 192.168.0.113_2.old updating log file

2018-08-22 14:50:00, Rateup WARNING: /usr/bin/rateup Can't rename 192.168.0.113_2.log to 192.168.0.113_2.old updating log file

[root@localhost bandwidthd]# env LANG=C mrtg /etc/mrtg/mrtg.cfg    //第二次

[root@localhost bandwidthd]# env LANG=C mrtg /etc/mrtg/mrtg.cfg    //第三次

 

8、在浏览器输入“127.0.0.1/mrtg/192.168.0.113_2.html”,这样就可以访问了

       

 

posted @ 2019-01-07 06:50  一生有你llx  阅读(947)  评论(0编辑  收藏  举报