天天看點

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

syscontact Vivek G Gite <[email protected]>

dontLogTCPWrappersConnects yes

#/etc/init.d/snmpd restart

# snmpwalk -v 1 -c public localhostIP-MIB::ipAdEntIfIndex

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>

                                       <td>Maintainer:</td>

                                       <td>Vivek G Gite &lt;[email protected]&gt;</td>

                                       <td>Description:</td>

                                       <td>lo  </td>

                                       <td>ifType:</td>

                                       <td>softwareLoopback (24)</td>

                                       <td>ifName:</td>

                                       <td>lo</td>

                                       <td>Max Speed:</td>

                                       <td>1250.0 kBytes/s</td>

                                       <td>Ip:</td>

                                       <td>127.0.0.1 (localhost.localdomain)</td>

                       </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分鐘自動刷行一次

繼續閱讀