歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> 關於Unix >> FreeBsd下MRTG安裝和配置全過程

FreeBsd下MRTG安裝和配置全過程

日期:2017/2/28 11:14:55   编辑:關於Unix


這篇是早早以前寫下來的,用GOOGLE搜一下,發現被轉貼了很多地方。所以把它依舊再放回來,測試下GOOGLE能否搜索到
由於MRTG 不象APACHE 那麼龐大, 精密。所以決定用PORTS 安裝。
首先要安裝的是SNMP ,因為MRTG就是通過SNMP 監視流量來制作成可視化圖表
pub# cd /usr/ports/net-mgmt/net-snmp/
pub# make install && make clean
pub# rehash
測試一下
pub# snmpd
pub# ps waux |grep snmpd
root 614 0.0 0.8 5612 4308 ?? S 12:45AM 0:00.23 snmpd
這一步好了,假如系統和PORTS TREE 本身沒問題,這一步也應該沒問題
接下來 就是PORTS 安裝MRTG
pub# cd /usr/ports/net-mgmt/mrtg/
pub# make install && make clean
pub#rehash
測試一下
pub# mrtg
Usage: mrtg
mrtg-2.11.1 is the Multi Router Traffic Grapher.
If you want to know more about this tool, you might want
to read the docs. They came together with mrtg!
看到這個就應該是沒問題了
做完上面以後
最後就是配置工作 使MRTG 能為我們工作 ,這個是最“復雜”的一步,其實前面安裝也挺復雜的,只是借助了PORTS 才會覺得“簡單” 有機會可以全部編譯安裝試一下 以求深入理解MRTG && snmp
1. 在WEB 發布目錄/pub/site 建立一mrtg 目錄,為的是能把生成的圖表發布在浏覽器裡面
pub# mkdir mrtg
pub# cd /usr/local/share/snmp/
pub# ls
#############################
#
# An example configuration file for configuring the ucd-snmp snmpd ag
#
############################
#
# This file is intended to only be an example. If, however, you want
............................................
找一下
# sec.name source community
com2sec local localhost COMMUNITY
com2sec mynetwork NETWORK/24 COMMUNITY
rocommunity prowork
在這個地方添加 rocommunity prowork
添加在這裡比較容易記憶 ,方便以後查找,它也可以放在其它的地方,注意不要在前面加 # ^_^ ,其中的prowork 就是等會我們要使用的訪問名字 ,
這一步和別的朋友寫的文檔上面有點不太一樣 , 注意多點沒壞處
2. 生成 mrtg 配置文件 ,用於初始化,獲取 snmp 信息
pub# cd /usr/local/etc/mrtg
pub# cfgmaker [email protected] > mrtg.prowork
--base: Get Device Info on [email protected] :
--base: Vendor Id:
--base: Populating confcache
--snpo: confcache [email protected] : Descr vr0 --> 1
--snpo: confcache [email protected] : Descr lo0 --> 2
--snpo: confcache [email protected] : Type 6 --> 1
--snpo: confcache [email protected] : Type 24 --> 2
--snpo: confcache [email protected] : Ip 127.0.0.1 --> 2
--snpo: confcache [email protected] : Ip 192.168.1.28 --> 1
--snpo: confcache [email protected] : Eth 00-05-5d-a1-b6-7d --> 1
--snpo: confcache [email protected] : Eth --> 2
--base: Get Interface Info
--base: Walking ifIndex
--base: Walking ifType
--base: Walking ifAdminStatus
--base: Walking ifOperStatus
出現以上信息就證明通過了 (我在freebsd6.2的平台上邊,根本不會有上邊的顯示)
在這個地方有幾點要注意, 一個是prowork@後面的 192.168.0.206 在很多時候盡量用IP地址來代替,當然假如是放在
公網上面的機器是動態IP 就不得不使用域名,那也是沒辦法的事
情,總之目的就是要獲得要抓的網卡上面的流量,得要給MRTG
知道是哪塊網卡才行 ,所以一定要給它正確的地址 。
還有一個就是前面prowork@中的prowork ,這個就是在前面
寫錯 就會出現
pub# cfgmaker [email protected] > mrtg.prowork
--base: Get Device Info on [email protected] :
SNMP Error:
no response received
SNMPv1_Session (remote host: "192.168.1.28" [192.168.1.28].161)
community: "com2sec"
request ID: 1181035357
PDU bufsize: 8000 bytes
timeout: 2s
retries: 5
backoff: 1)
at /usr/local/lib/perl5/site_perl/5.005/SNMP_util.pm line 627
SNMPWALK Problem for 1.3.6.1.2.1.1 on [email protected] ::::::v4only
at /usr/local/bin/cfgmaker line 796
WARNING: Skipping [email protected] : as no info could be retrieved
3 .在正確生成 mrtg.prowork的配置文件後就該修改修改裡面的
內容以求能符合自己的習慣 ,
pub# cat mrtg.prowork
# Created by
# /usr/local/bin/cfgmaker [email protected]
### Global Config Options
# for UNIX
#這是設定要存放MRTG的信息發布頁面的路徑 ,也就是存放能
#打開頁面看流量信息頁面的那個地方
WorkDir: /pub/site/mrtg/
# or for NT
# WorkDir: c:\mrtgdata
### Global Defaults
# to get bits instead of bytes and graphs growing to the right
# Options[_]: growright, bits
EnableIPv6: no
######################################################################
# Location: Right here, right now.
######################################################################
### Interface 1 >> Descr: 'vr0' | Name: '' | Ip: '192.168.1.28' | Eth: '00-05-5d-a1-b6-7d' ###
Target[192.168.1.28_1]: 1:[email protected]:
SetEnv[192.168.1.28_1]: MRTG_INT_IP="192.168.1.28" MRTG_INT_DESCR="vr0"
MaxBytes[192.168.1.28_1]: 1250000
Description: vr0
ifType: ethernetCsmacd (6)
ifName: prowork nic
Max Speed: 1250.0 kBytes/s
### Interface 2 >> Descr: 'lo0' | Name: '' | Ip: '127.0.0.1' | Eth: '' ###
### The following interface is commented out because:
### * it is a Software Loopback interface
### * has a speed of 0 which makes no sense
#
# Target[192.168.1.28_2]: 2:[email protected]:
# SetEnv[192.168.1.28_2]: MRTG_INT_IP="127.0.0.1" MRTG_INT_DESCR="lo0"
# MaxBytes[192.168.1.28_2]: 0
#
# Description: lo0
# ifType: softwareLoopback (24)
# ifName:
# Max Speed: 0.0 Bytes/s
#
Options[_]: growright, bits
Language:gb2312
WithPeak[_]: wmy
可以修改讓它符合自己的習慣因為裡面有些 等會會在WEB頁面
顯示出來
注意的是任何指令左側 都不要有空格出現 否則會提示 :
ERROR: Line 8 ( WorkDir: /var/www/html/mrtg) in CFG file (mrtg)does not make sense
這個一點都不假 ,不相信試試看
4. 生成WEB 頁面 index.html
indexmaker --title 'prowork net' -output /pub/site/mrtg/index.html mrtg.prowork
--title 為 index.html 的標題 /pub/site/mrtg/為發布頁面的
絕對路徑 mrtg.prowork 為配置文件
這時候應該在 /pub/site/mrtg/裡面生成了一個配置頁面
打開看的時候 ,應該是看到有 幾個紅叉叉的頁面 並沒有預想
的那樣 ,原因是差了最後一步 :運行MRTG
5.運行 MRTG
pub# mrtg /usr/local/etc/mrtg/mrtg.prowork
Rateup WARNING: /usr/local/bin/rateup could not read the primary log file for 192.168.1.28_1
Rateup WARNING: /usr/local/bin/rateup The backup log file for 192.168.1.28_1 was invalid as well
Rateup WARNING: /usr/local/bin/rateup Can't remove 192.168.1.28_1.old updating log file
Rateup WARNING: /usr/local/bin/rateup Can't rename 192.168.1.28_1.log to 192.168.1.28_1.old updating log file
pub# mrtg /usr/local/etc/mrtg/mrtg.prowork
Rateup WARNING: /usr/local/bin/rateup Can't remove 192.168.1.28_1.old updating log file
pub# mrtg /usr/local/etc/mrtg/mrtg.prowork
pub# mrtg /usr/local/etc/mrtg/mrtg.prowork
pub# ls
果然不假 ,真如別的朋友上面寫的一樣會“抱怨”三次
到這一步 應該是一個MRTG 該可以正常使用了
就看到了令人驚奇的一面
結尾:
排程 ,因為流量是不住變化的所以每隔一段時間就要去探測
一次 , 時間長了 精確度不夠 ,時間短 頻繁去探測 ,又會
加重系統負擔 , 別人告訴我 ,一般是 5-10分鐘 最佳
#ee /etc/crontab添加下邊這些內容
*/5 * * * * /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.prowork


最後再加上一些可以監控機器cpu占用,空閒內存,tcp連接數的配置文件內容如下:
添加對CPU,內存,TCP連接數的監控.
#monitoring User vs Idle CPU usage
Target[kontor.cpu]:ssCpuRawUser.0&ssCpuRawIdle.0:[email protected]
RouterUptime[kontor.cpu]: [email protected]
MaxBytes[kontor.cpu]: 100
Title[kontor.cpu]: CPU LOAD
PageTop[kontor.cpu]:

User CPU Load %


Unscaled[kontor.cpu]: ymwd
ShortLegend[kontor.cpu]: %
YLegend[kontor.cpu]: CPU Utilization
Legend1[kontor.cpu]: User CPU in % (Load)
Legend2[kontor.cpu]: Idle CPU in % (Load)
LegendI[kontor.cpu]: User
LegendO[kontor.cpu]: Idle
Options[kontor.cpu]: growright,nopercent
#monitoring User vs System CPU usage
Target[kontor.usrsys]:ssCpuRawUser.0&ssCpuRawSystem.0:[email protected]
RouterUptime[kontor.usrsys]: [email protected]
MaxBytes[kontor.usrsys]: 100
Title[kontor.usrsys]: CPU LOAD
PageTop[kontor.usrsys]:

CPU (user and system) Load %


Unscaled[kontor.usrsys]: ymwd
ShortLegend[kontor.usrsys]: %
YLegend[kontor.usrsys]: CPU Utilization
Legend1[kontor.usrsys]: User CPU in % (Load)
Legend2[kontor.usrsys]: System CPU in % (Load)
LegendI[kontor.usrsys]: User
LegendO[kontor.usrsys]: System
Options[kontor.usrsys]: growright,nopercent
#monitoring Active CPU usage
Target[kontor.cpusum]:ssCpuRawUser.0&ssCpuRawUser.0:[email protected] + ssCpuRawSystem.0&ssCpuRawSystem.0:[email protected] + ssCpuRawNice.0&ssCpuRawNice.0:[email protected]
RouterUptime[kontor.cpusum]: [email protected]
MaxBytes[kontor.cpusum]: 100
Title[kontor.cpusum]: CPU LOAD
PageTop[kontor.cpusum]:

Active CPU Load %


Unscaled[kontor.cpusum]: ymwd
ShortLegend[kontor.cpusum]: %
YLegend[kontor.cpusum]: CPU Utilization
Legend1[kontor.cpusum]: Active CPU in % (Load)
LegendI[kontor.cpusum]: Active
Options[kontor.cpusum]: growright,nopercent
#Monitoring TCP connections
Target[tcpopen]: .1.3.6.1.2.1.6.9.0&.1.3.6.1.2.1.6.9.0:[email protected]
Options[tcpopen]: nopercent,growright,gauge,noinfo
Title[tcpopen]: Open TCP connections
PageTop[tcpopen]:

Open TCP connections


MaxBytes[tcpopen]: 1000000
YLegend[tcpopen]: # conns
ShortLegend[tcpopen]: connections
LegendI[tcpopen]: Connections:
Legend1[tcpopen]: Open TCP connections
#Monitoring Free Memory
Target[freemem]: .1.3.6.1.4.1.2021.4.11.0&.1.3.6.1.4.1.2021.4.11.0:[email protected]
Options[freemem]: nopercent,growright,gauge,noinfo
Title[freemem]: Free Memory
PageTop[freemem]:

Free Memory


MaxBytes[freemem]: 1000000
kMG[freemem]: k,M,G,T,P,X
YLegend[freemem]: bytes
ShortLegend[freemem]: bytes
LegendI[freemem]: Free Memory:
Legend1[freemem]: Free memory, not including swap, in bytes
修改了mrtg使用的配置文件,要重新生成頁面文件,

#cd /usr/local/etc/mrtg

#indexmaker --title 'prowork net' -output /pub/site/mrtg/index.html mrtg.prowork
#mrtg mrtg.prowork
到這裡也就完全結束了。
Copyright © Linux教程網 All Rights Reserved