MRTG install and Configure on CentOS 6.5

=======================================================================

1. MRTG 2.16.2 安裝基本套件
 
-yum -y install perl gd libpng zlib httpd net-snmp* mrtg

2. 設定與啟動 SNMP
  
 -vim /etc/snmp/snmpd.conf
       
增加底下兩行(在57行)
        view systemview included .1.3.6.1.2.1.2.2.1.10    ------>
The total number of octets received on the interface, including framing characters.
        view systemview included .1.3.6.1.2.1.2.2.1.16    ------>
The total number of octets transmitted out of the interface, including framing characters. 
    -service snmpd restart

3. 建立 MRTG 資料夾到 /var/www/html/mrtg
    -mkdir /var/www/html/mrtg

4. 設定 MRTG
    -vi /etc/mrtg/mrtg.cfg
       
增加底下四行(在最後面)
        Target[eth1]: 3:public@127.0.0.1
        MaxBytes[eth1]: 1250000    ------>
後面數字代表資料監測時,最大傳送速率,使用 bytes,所以 10Mbps 1.25MBytes
        Title[eth1]: Traffic Analysis
        PageTop[eth1]: <H1>127.0.0.1 eth1</H1>
        Refresh: 300    ------>
網頁每300秒會自動重新整理一次
        Interval: 5    ------>MRTG
5秒讀取設定檔一次
        Options[eth1]: growright    ------>
圖表由右邊開始畫起
       
       
備註:
                public
前面的數字可用下面偵測,一般 eth1 代號是 3
                [root@localhost ~]# ip link
                1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
                    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
                2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
                    link/ether 68:05:ca:16:cb:d4 brd ff:ff:ff:ff:ff:ff
                3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
                    link/ether 00:1a:92:02:34:95 brd ff:ff:ff:ff:ff:ff
                4: eth2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
                    link/ether 78:44:76:a7:0e:06 brd ff:ff:ff:ff:ff

5. 產生基本網頁
 
-執行三次下面指令,產生基本網頁
   
[root@localhost ~]# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
        2014-11-20 11:01:42, Rateup WARNING: /usr/bin/rateup could not read the primary log file for eth1
        2014-11-20 11:01:42, Rateup WARNING: /usr/bin/rateup The backup log file for eth1 was invalid as well
        2014-11-20 11:01:42, Rateup WARNING: /usr/bin/rateup Can't remove eth1.old updating log file
        2014-11-20 11:01:42, Rateup WARNING: /usr/bin/rateup Can't rename eth1.log to eth1.old updating log file
        [root@localhost ~]# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
        2014-11-20 11:01:46, Rateup WARNING: /usr/bin/rateup Can't remove eth1.old updating log file
        [root@localhost ~]# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg

6.產生 MRTG 首頁與重啟 httpd
  -執行
   
[root@localhost ~]# indexmaker /etc/mrtg/mrtg.cfg > /var/www/mrtg/index.html
       [root@localhost ~]# service httpd restart

    正在停止
httpd: [ 確定 ]
    正在啟動
httpd: [ 確定 ]

7.設定排程
 
-編輯 /etc/crontab
   
[root@localhost ~]# vim /etc/crontab    ------>新增底下規則
        */5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg > /dev/null 2>&1

8.啟動 MRTG 監控
  -開啟瀏覽器
   
localhost/mrtg/

9.開放其它機器查詢
    -vim /etc/httpd/conf.d/mrtg.cfg
        找到
        <Location /mrtg>
            Order deny,allow
            Deny from all
            Allow from 127.0.0.1
            Allow from ::1
            # Allow from. example.com
        </Location>

        增加允許瀏覽 MRTG 的機器或網段
   
<Location /mrtg>
            Order deny,allow
            Deny from all
            Allow from 172.16.1.0/24
            Allow from 127.0.0.1
            Allow from ::1
            # Allow from. example.com
        </Location>

    重新啟動
httpd 讓設定生效
        
[root@localhost ~]#service httpd restart