FREEBSD6.0上安裝snmp+mrtg還是比較簡單的,不過網絡上的安裝教程大多缺胳膊少腿,有的難度挺高,理論說了一大推,讓人忘而怯步呀!今天偶來發一篇簡單易懂的.為新手准備的.如果你已經安裝好了apache的話,看下面:
一:安裝snmp:
以下%為SHELL提示符,
安裝snmp:
%cd /usr/ports/net-mgmt/net-snmp
%make install
加入:
------------------------------------------------------------------
snmpd_enable="YES"
snmpd_flags="-a -p /var/run/snmpd.pid"
snmptrapd_enable="YES"
snmptrapd_flags="-a -p /var/run/snmptrapd.pid"
------------------------------------------------------------------
運行下:
%/etc/netstart
加入一行:
-------------------------------------------------------------
rocommunity public #默認讓snmp使用public用戶
--------------------------------------------------------------
啟動snmpd:
%/usr/local/etc/rc.d/snmpd.sh start
二:安裝mrtg:
確定ports下的mrtg在什麼位置:
%whereis mrtg
mrtg: /usr/ports/net-mgmt/mrtg
安裝mrtg:
%cd /usr/ports/net-mgmt/mrtg
%make install
進入你apache的data目錄(視個人情況而定,我的是/usr/local/www/apache22/data/wh-hisense/):
%cd /usr/local/www/apache22/data/wh-hisense
在當前的WEB目錄創建mrtg的目錄:
%mkdir mrtg
三:配置mrtg:
進入mrtg的配置文件所在目錄:
%cd /usr/local/etc/mrtg
用cfgmaker創建mrtg的配置文件:
%ee mrtg.cfg
修改如下:
#####################################
WorkDir: /usr/local/www/apache22/data/wh-hisense/mrtg #注:去掉前面的#號喲,冒號後面不要有空格,否則會出錯.
Language: gb2312 #注:這表示簡體中文版,,這可是自己加上去的哦!!!
#####################################
並在文件尾加入,既cpu,內存等的監視:
-----------------------------------------------------------------------------------------------------
#Monitoring TCP connections
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 User vs Idle CPU usage
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
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
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
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
--------------------------------------------------------------------------------------
生成index.html文件:
/usr/local/bin/indexmaker –-title="流量監控" --output=/home/http/mrtg/index.html mrtg.cfg
多運行幾次:
/usr/local/bin/mrtg mrtg.cfg
直到沒有出錯提示為止
加入crontab每隔2分鐘讓數據刷新一次:
%ee /etc/crontab
------------------------------------------------------------------------
*/2 * * * * root /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg
--------------------------------------------------------------------