centos 安裝mrtg流量監控

1、安裝net-snmp

#yum install net-snmp net-snmp-utils -y
#snmpwalk -v 1 -c public localhostIP-MIB::ipAdEntIfIndex
Created directory: /var/lib/net-snmp/mib_indexes
Timeout: No Response from localhost
現在是提取不到數據的,我們需要對/etc/snmp/snmpd.conf 進行一些修改
# vim /etc/snmp/snmpd.conf

#com2secnotConfigUser  default         public
com2sec local    localhost           public
com2sec mynetwork   192.168.0.0/24網段)    public(團體名重要)
#group   notConfigGroupv1           notConfigUser
#group   notConfigGroupv2c           notConfigUser

group MyRWGroup v1         local
group MyRWGroup v2c        local
group MyRWGroup usm        local
group MyROGroup v1         mynetwork
group MyROGroup v2c        mynetwork
group MyROGroup usm        mynetwork

#view    systemview    included  .1.3.6.1.2.1.1
#view    systemview    included  .1.3.6.1.2.1.25.1.1
view all    included .1                              80
#access  notConfigGroup ""     any       noauth    exact systemview none none
access MyROGroup ""     any       noauth    exact all    none   none
access MyRWGroup ""     any       noauth    exact all    all    none
將下邊的這部分稍微改動一下,其實就是一些描述的東西
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)

syslocation Linux6.
syscontact Vivek G Gite
[email protected]

以上就是要修改的地方了!
# /etc/init.d/snmpd restart
# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.192.168.0.55 = INTEGER: 2
現在就可以提取到數據了
#chkconfig snmpd on

2、安裝MRTG

1)生成配置文件

cfgmaker public@*.*.*.* >> /etc/mrtg/mrtg.cfg

2)生成index.html首頁

indexmaker--output=/data/web/mrtg/index.html /etc/mrtg/mrtg.cfg

3)成像

mrtg /etc/mrtg/mrtg.cfg

 

現在裝一下mrtg,我這裏用到的是mrtg-2.16.2-5.el6.x86_64  
# yum install -y mrtg
# mkdir -p /var/www/html/mymrtg
cfgmakerpublic@*.*.*.* > /etc/mrtg/mrtg.cfg

如果後續還要添加主機的時候使用cfgmakerpublic@*.*.*.* >> /etc/mrtg/mrtg.cfg

這樣mrtg可以自動獲取能監控設備的信息(對於Cisco交換機就可以監控單獨端口的流量),snmpwalk -v 2c -c public 192.168.123.111 if

修改配置文件vim /etc/mrtg/mrtg.cfg

#for UNIX

WorkDir: /data/web/mrtg/114.255.92.153    #這行去掉註釋和空格,填寫合適路徑

#  or for NT

#WorkDir: c:\mrtgdata

###Global Defaults

#  to get bits instead of bytes and graphsgrowing to the right

Options[_]: growright, bits               #這行去掉註釋和空格

RunAsDaemon:yes                           #加這兩行是爲了沒5分鐘自動刷新一次

Interval:5

如果監控一臺遠程主機,這樣做的話,需要給遠程主機也安裝snmp,進行配置,將本機的配置文件複製過去即可!配置文件如下:

com2seclocal     localhost          public
com2sec mynetwork 192.168.0.0/24      public
group MyRWGroup v1         local
group MyRWGroup v2c        local
group MyRWGroup usm        local
group MyROGroup v1         mynetwork
group MyROGroup v2c        mynetwork
group MyROGroup usm        mynetwork
view all    included .1                              80
access MyROGroup ""     any       noauth    exact all    none   none
access MyRWGroup ""     any       noauth    exact all    all    none
com2sec local    localhost           public
com2sec mynetwork 192.168.0.0/24      public
syslocation Linux6.
syscontact Vivek G Gite <[email protected]>
dontLogTCPWrappersConnects yes

#/etc/init.d/snmpd restart
# snmpwalk -v 1 -c public localhostIP-MIB::ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.192.168.0.222 = INTEGER: 4
IP-MIB::ipAdEntIfIndex.192.168.122.1 = INTEGER: 5
# chkconfig snmpd on

#indexmaker--output=/var/www/html/mymrtg/index.html /etc/mrtg/mymrtg.cfg
Use of uninitialized value $first in hash element at /usr/bin/indexmaker line353.
這裏有時候會出現一個錯誤,是因爲生成的/etc/mrtg/mymrtg.cfg 文件裏接口內容被注掉了,將下邊內容下的東西註釋行去掉,改成下邊這樣子:
### Interface 1 >> Descr: 'lo' | Name: 'lo' | Ip: '127.0.0.1' | Eth: ''###
### The following interface is commented out because:
### * it is a Software Loopback interface
Target[localhost_1]: 1:public@localhost:
SetEnv[localhost_1]: MRTG_INT_IP="127.0.0.1"MRTG_INT_DESCR="lo"
MaxBytes[localhost_1]: 1250000
Title[localhost_1]: Traffic Analysis for 1 -- server26.example.com
PageTop[localhost_1]: <h1>Traffic Analysis for 1 --server26.example.com</h1>
               <div id="sysdetails">
                       <table>
                               <tr>
                                       <td>System:</td>
                                       <td>server26.example.com in Linux6.</td>
                               </tr>
                               <tr>
                                       <td>Maintainer:</td>
                                       <td>Vivek G Gite &lt;[email protected]&gt;</td>
                               </tr>
                               <tr>
                                       <td>Description:</td>
                                       <td>lo  </td>
                               </tr>
                               <tr>
                                       <td>ifType:</td>
                                       <td>softwareLoopback (24)</td>
                               </tr>
                               <tr>
                                       <td>ifName:</td>
                                       <td>lo</td>
                               </tr>
                               <tr>
                                       <td>Max Speed:</td>
                                       <td>1250.0 kBytes/s</td>
                               </tr>
                               <tr>
                                       <td>Ip:</td>
                                       <td>127.0.0.1 (localhost.localdomain)</td>
                               </tr>
                       </table>
               </div>

# indexmaker --output=/var/www/html/mymrtg/index.html/etc/mrtg/mymrtg.cfg(生成主頁文件)

# mrtg /etc/mrtg/mrtg.cfg(啓動mrtg)

-----------------------------------------------------------------------
ERROR: Mrtg will most likely not work properly when the environment
       variable LANG is set to UTF-8. Please runmrtg in an environment
       where this is not the case. Try thefollowing command to start:

       env /usr/bin/mrtg/etc/mrtg/mymrtg.cfg
-----------------------------------------------------------------------
#  env /usr/bin/mrtg /etc/mrtg/mymrtg.cfg
這條命令前兩次運行會出錯,運行三次就ok了

爲了方便,我們可以寫一個crontab
# crontab -e
*/5 * * * * /usr/bin/mrtg /etc/mrtg/mymrtg.cfg --logging /var/log/mrtg.log
由於頁面訪問是基於httpd的,記得開啓httpd服務哦!

也可以在每個配置文件中加入一下代碼,每5分鐘自動刷行一次

RunAsDaemon:yes

Interval:5


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章