歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> Linux文化 >> 手把手:RPM/編譯/自動安裝MRTG

手把手:RPM/編譯/自動安裝MRTG

日期:2017/2/27 12:08:15   编辑:Linux文化

出處 菜鳥油 ( http://www.noobu.com ) 作者:滄藍 歡迎轉載,轉載請注明出處與作者,謝謝 本文的完美排版/最後更新修正版本:http://www.noobu.com/0504_mrtg_install.html

MRTG (Multi Router Traffic Grapher) 是一款系統帶寬監測軟件。也是最著名、使用最廣泛的同類軟件之一。下面將介紹三種不同的安裝方法。

首先,是通過 yum 安裝的RPM安裝方式。菜鳥油的服務器為CentOS,控制面板采用的是DSM,由於其特殊性,導致部分MRTG與部分軟件不兼容。編譯時會顯示如下錯誤:

** Ooops, one of many bad things happened:

a) You don’t have the GD library installed. Get it from http://www.boutell.com, compile it and use either –with-gd-lib=DIR and –with-gd-inc=DIR to specify its location. You might also have to use –with-z-inc, –with-z-lib and –with-png-inc, –with-png-lib for gd versions 1.6 and higher. Check config.log for more information on the problem.

b) You have the GD library installed, but not the gd.h header file. Download the source (see above) and use –with-gd-inc=DIR to specify where the file can be found.

c) You have the library and the header file installed, but you also have a shared GD library in the same directory. Remove the shared library files and/or links (e.g. libgd.so.2.0.0, libgd.so and libgd.so.2). This is especially likely if you’re using a recent (post 1.8.4) version of GD and didn’t configure it with –disable-shared.

d) You have gd library installed and also it’s headers, but you are missing libpng (and headers) or freetype (and headers) (mrtg does not use freetype, but if your copy of gd is precompiled against it, you have to install it …

由於更改這些軟件的配置可能會導致控制面板失效,所以,筆者采用yum來安裝已編譯好的RPM包:

yum install mrtg

安裝完MRTG後(默認安裝到 /var/www/mrtg ),根據系統的不同,還需要做一些配置工作。

先更新一下搜索庫:

updatedb

然後分別搜索以下內容:

locate cfgmaker locate indexmaker locate mrtg.cfg

以下假定這三個文件的路徑分別為:

/usr/bin/cfgmaker /usr/bin/indexmaker /etc/mrtg/mrtg.cfg

請根據自己的實際情況更改後面內容中的相關代碼。

執行以下代碼配置MRTG(請將粗體部分替換為您的實際服務器IP):

/usr/bin/cfgmaker --output=/etc/mrtg/mrtg.cfg [email protected]

如果有多個IP需要監視的,就運行該命令多次。

執行以下代碼生成MRTG的頁面(title部分是頁面的標題):

/usr/bin/indexmaker --output=/var/www/mrtg/index.html --title="MRTG Graph" /etc/mrtg/mrtg.cfg

修改配置文件:

nano /etc/mrtg/mrtg.cfg

去除 WorkDir: 前的“#”,並設置路徑為 /var/www/mrtg 。 可選:去除 Options[_]: growright, bits 前的“#”。

接著,請確認你的Apache web目錄(比如/var/www/html或/home/username/pubic_html/或/usr/local/apache/htdocs等)。執行以下命令:

ln -s /var/www/mrtg path/to/apache/web/mrtg

請將粗體部分替換為您的Apache web目錄。

如此,就能通過浏覽器訪問MRTG頁面了。

最後一部是將生成MRTG圖形的代碼加入到Cron中,讓系統定時自動更新。命令為 env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg

如果需要MRTG的log文件的話:

touch /var/log/mrtg.log

並將Cron中( nano /etc/crontab )的運行命令改為 env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg –logging /var/log/mrtg.log ,例如:

*/5 * * * * env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --logging /var/log/mrtg.log

至此,采用RPM的安裝方式就順利完成了。此方法應當也適用於apt-get,不過筆者沒有實驗過。

方法二:編譯安裝

由於在方法一中已經詳細的說明了如何配置MRTG,所以編譯安裝只要執行以下命令就行了:

wget http://people.ee.ethz.ch/~oetiker/webtools/mrtg/pub/mrtg.tar.gz tar -xzvf mrtg.tar.gz cd mrtg-版本

./configure –prefix=/usr/local/mrtg \ –with-gd=/usr/include \ –with-gd-lib=/usr/lib \ –with-gd-inc=/usr/include \ –with-png=/usr/include \ –with-zlib=/usr/include && make && make install

安裝完成後,請參照方法一來進行配置。

方法三:自動安裝

方法一中的配置是最簡單的,也就是,大部分都采用默認設置。所以,能夠監測的數據有限。而國外有用戶特別針對大部分人的情況設計了一個自動安裝程序,程序安裝時會自動從MRTG網站下載最新的軟件包,自動編譯、安裝,並配置。程序默認安裝在 /var/www/html/mrtg,有需要的話請參考方法一中的 ln -s 進行目錄連接。

執行以下命令自動安裝MRTG:

wget http://serveio.com/da/install.mrtg.sh chmod +x install.mrtg.sh ./install.mrtg.sh

該自動安裝程序在以下操作系統上測試通過(均采用Direct Admin控制面板):

RedHat 9 Fedora Core 3 Debian 3.0 CentOS 3.4 CentOS 4.0 自動安裝程序的作者:Matt Savona

可選步驟:

安裝 net-snmp (Simple Network Management Protocol)

yum install net-smnp

安裝完以後,配置/etc/snmp/snmpd.conf文件,使其能配合mrtg工作。

去除下面的“#”號 #view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc

將 access notConfigGroup “” any noauth exact systemview none none 改為: access notConfigGroup “” any noauth exact mib2 none none

啟動snmpd服務:

/etc/rc.d/init.d/snmpd start

希望這篇文章能幫助你順利的安裝MRTG。:)


Copyright © Linux教程網 All Rights Reserved