os版本:Rad Hat Enterprise
Linux 5
還需要有apache的支持,本次試驗apache安裝在/usr/local/apache下
所需軟件安裝包如下,均為源代碼安裝包
gd-2.0.33.tar.gz
zlib-1.2.3.tar.gz
libpng-1.2.15.tar.gz
jpegsrc.v6b.tar.gz
freetype-2.1.9.tar.gz
fontconfig-2.3.2.tar.gz
mrtg-2.13.2.tar.gz
一、安裝在MRTG所需的組件
1、安裝zlib庫
tar -xvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
make
make install
2.安裝libpng庫
tar -zxvf libpng-1.2.15.tar.gz
cd libpng-1.2.15
./configure
make
make install
3、安裝JPEG庫
tar -zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
./configure --enable-static --enable-shared
make
make install
4、安裝安裝Freetype
tar -zxvf freetype-2.1.9.tar.gz
cd freetype-2.1.9
./configure
make
make install
5、安裝Fontconfig(freetype-devel fontconfig-devel )
tar -zxvf fontconfig-2.3.2.tar.gz
cd fontconfig-2.3.2.tar.gz
./configure
make
make install
6、編譯GD庫
安裝GD庫
安裝命令如下
tar -zxvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure
如果在輸出信息中如下圖
Support for PNG library: no
Support for JPEG library: no
Support for Freetype 2.x library: no
Support for Fontconfig library: no
Support for Xpm library: no
Support for pthreads: yes
(圖片沒顯示)如果全部都顯示的為yes,我們就可以直接去裝MRTG了,此次環境中只有 一項顯示為yes,所以還要安裝其組件
make
make install
二、安裝mrtg
tar -zxvf mrtg-2.13.2.tar.gz
cd mrtg-2.13.2
./configure --prefix=/usr/local/mrtg --with-gd=/usr/include --with-gd-lib=/usr/lib --with-gd-inc=/usr/include --with-png=/usr/include --with-png-lib=/usr/lib --with-zlib=/usr/include --with-zlib-lib=/usr/lib
make
make install
三、調整參數,對端口進行流量監控
1、 生成mrtg.cfg文件,用於存放mrtg配置信息
/usr/local/mrtg/bin/cfgmaker --output /usr/local/apache/htdocs/mrtg.cfg
[email protected] (public為SNMP團體名稱,ip為被監控的設備。)
2、修改mrtg.cfg文件參數
vi /usr/local/apache/htdocs/mrtg.cfg
把#去掉 把Workdir後的路徑改成/usr/local/apache/htdocs :指定mrtg的工作目錄
把#Options[_]: growright, bits :前面的#去掉
在加入一行Language:Chinese :使mrtg支持中文
3、env LANG=C /usr/local/mrtg/bin/mrtg /usr/local/apache/htdocs/mrtg.cfg :多執行幾遍,直到不出現信息
4、生成頁面文件
/usr/local/mrtg/bin/indexmaker --output /usr/local/apache/htdocs/index.html --title=ruishengIDC /usr/local/apache/htdocs/mrtg.cfg(中間的參數可以省略)
5、讓數據自動刷新
crontab -e
然後寫入*/5 * * * * env LANG=C /usr/local/mrtg/bin/mrtg /usr/local/apache/htdocs/mrtg.cfg (注:如之前未加env LANG=C的話,則這裡也不用加),意思為讓系統在後台每五分鐘執行一次env LANG=C /usr/local/mrtg/bin/mrtg /usr/local/apache/htdocs/mrtg.cfg
注:第三塊調整參數時有先後順序,如只出來的圖上沒有顯示流量有可能是步驟執行先後錯誤,使用rm -f /usr/local/apache/htdocs/.mrtg.cfg.swp 清除一下緩存,然後在按照順序執行一下即可