1. 程式人生 > >Linux伺服器---流量監控MRTG

Linux伺服器---流量監控MRTG

MRTG

MRTG可以分析網路流量,但是它必須依賴SNMP協議。將收集到的資料生成HTML檔案,以圖片的形式展示出來

1、安裝一些依賴軟體

[[email protected] bandwidthd-2.0.1]# yum install -y net-snmp

 

2、配置snmp,編輯配置檔案“/etc/snmp/snmpd.conf”

[[email protected] 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服務

[[email protected] bandwidthd]# service snmpd start

正在啟動snmpd                                           [確定]

[[email protected] bandwidthd]#

 

4、下載bandwidthd軟體(https://oss.oetiker.ch/mrtg/pub/?M=D),或者以yum方式線上安裝

[[email protected] bandwidthd]# yum install -y mrtg

 

5、修改配置檔案”/etc/httpd/conf.d/mrtg.conf”

[[email protected] 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檔案,並做一些修改。

[[email protected] bandwidthd]# cfgmaker [email protected]>/etc/mrtg/mrtg.cfg       //生成檔案,注意ip地址需要使用者自己設定

[[email protected] 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檔案,執行三次指令

[[email protected] bandwidthd]# env 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

[[email protected] bandwidthd]# env mrtg /etc/mrtg/mrtg.cfg    //第二次

[[email protected] bandwidthd]# env mrtg /etc/mrtg/mrtg.cfg    //第三次

 

8、在瀏覽器輸入“127.0.0.1/mrtg/192.168.0.113_2.html”,這樣就可以訪問了

螢幕快照 2018-08-22 下午2.55.45.png