• 沒有找到結果。

其他軟體

在文檔中 網路流量自動監控系統 (頁 21-30)

第二章 軟硬體簡介

2.2 軟體

2.2.6 其他軟體

(或者說是流量),是網路管理人員所必須要注意的事項,因為當主機 各大伺服器常使用的軟體,就是 MRTG (Multi Router Traffic Grapher) 這一套軟體。MRTG 耗用的系統資源很小,因此有很多外掛的程式也依 附在 MRTG 底下,因為 MRTG 的繪圖挺漂漂的說!我們這裡僅提供下 面的偵測方法:

MRTG 的運作過程:

要瞭解 MRTG 的運作,就必須瞭解一下 SNMP (Simple Network Management Protocol) 這個協定,因為 MRTG 是透過 SNMP 協定來監 控流量的。所以,所有的 MRTG 所偵測的裝置都必須符合 SNMP 的協 定。那什麼是 SNMP 呢?簡單的說,就是一種可以提供裝置(主機設 備)的各類資訊的一種協定,諸如:網路流量、主機名稱、CPU 用量等 等的資訊都可以藉由此一協定來提供。不過,由於不同廠牌的裝置可 能會有無法相容的情況,因而後來又有所謂 MIB (Management

Information Base) 的協定產生。不論如何, MRTG 就是藉由 SNMP 這 個協定來監測與取得相關的資訊以製作圖表的!詳細的 SNMP 你可以 在 http://www.net-snmp.org/ 查得。

所以我們可以知道,MRTG 基本上是透過以 SNMP 的協定,向主機

MRTG 為使用 Perl 程式寫成的,並且使用到 zlib 、 gd 及

我們使用了預設的 Apache 路徑,為 /usr/local/apache/htdocs 這 個路徑來安裝 mrtg 輸出的圖表,要注意,如果沒有 apache 的話,

1.下載 ucd-snmp-4.2.1.tar.gz, mrtg-2.9.17.tar.gz ; 2.安裝 ucd-snmp-4.2.1.tar.gz:

oot @tsai /root]# cd /usr/local/src

oot @tsai src]# cp /root/ucd-snmp-4.2.1.tar.gz .

oot @tsai src]# tar -zxvf ucd-snmp-4.2.1.tar.gz oot @tsai src]# cd ucd-snmp-4.2.1

oot @tsai ucd-snmp-4.2.1]# ./configure prefix=/usr/local/snmp

...(過程我就省略了)

************** Configuration Section **************

You are about to be prompted by a series of questions. Answer

them carefully, as they determine how the snmp agent and related applications are to function.

After the configure script finishes, you can browse the newly

created config.h file for further - less important - parameters to

modify. Be careful if you re-run configure though since config.h will

be over written.

-Press return to continue- (這裡按 enter 吧)

disabling above prompt for future runs... yes checking System Contact Information...

*** System Contact Information:

Describes who should be contacted about the host the agent is

running on. This information is available in the MIB-II tree. This

Can Also Be Over-Ridden Using The "syscontact" Syntax In The Agent'S

Configuration Files.

System Contact Information (root@):root@tsai.adsldns.org (這 裡輸入你的 e-mail)

setting System Contact Information

to... root@tsai.adsldns.org checking System Location...

*** System Location:

Describes the location of the system. This information is

available in the MIB-II tree. This Can also be over-ridden using the

"syslocation" syntax in the agent's configuration files.

ystem Location (Unknown):RedHat 6.1 S(這裡可以隨便輸入,不 正確也沒關係)

setting System Location to... RedHat 6.1 checking Location to write logfile...

*** Logfile location:

Enter the default location for the snmpd agent to dump information & errors to. If not defined (enter the keyword

"none"

at the prompt below) the agent will use stdout and stderr instead.

(Note: This value can be over-ridden using command line options.)

Location to write logfile (/var/log/snmpd.log):(按 enter 即 可)

setting Location to write logfile to... /var/log/snmpd.log checking Location to write persistent information...

*** snmpd persistent storage location:

Enter a directory for the snmp library to store persistent

data in the form of a configuration file.

Location to write persistent information (/var/ucd-snmp):(按 enter 即可)

[root @tsai ucd-snmp-4.2.1]# make

[root @tsai ucd-snmp-4.2.1]# make install

上面輸入的資訊,在進行 MRTG 的製圖時,會顯示在圖表上面,不過,

這也是可以改的資訊,所以,如果不小心輸入錯誤也沒關係的。這樣 就將 ucd-snmp 安裝妥當了!

3.啟動 ucd-snmp :

直接在 shell 下面打上 /usr/local/snmp/sbin/snmpd 即可!或者 直接加在 /etc/rc.d/rc.local 當中,就可以自動開機時啟動了!

4.安裝 MRTG :

[root @tsai /root]# cd /usr/local/src

[root @tsai src]# cp /root/mrtg-2.9.17.tar.gz . [root @tsai src]# tar -zxvf mrtg-2.9.17.tar.gz [root @tsai src]# cd mrtg-2.9.17

[root @tsai

mrtg-2.9.17]# ./configure --prefix=/usr/local/mrtg-2 \

> --with-gd=/usr/include \

> --with-gd-lib=/usr/lib \

> --with-gd-inc=/usr/include \

> --with-png=/usr/include \

> --with-zlib=/usr/include

[root @tsai mrtg-2.9.17]# make; make install [root @tsai mrtg-2.9.17]# mkdir

/usr/local/apache/htdocs/mrtg (請注意,這裡與你的 WWW 主頁 的放置地點有關,請依你的系統來設定,另外,由於我們需要設定 網 路流量、CPU 與 RAM 使用率,因此在 mrtg 中,可以再建立三個子目 錄,比較容易管理啦!)

[root @tsai mrtg-2.9.17]# mkdir /usr/local/apache/htdocs/mrtg/net [root @tsai mrtg-2.9.17]# cp

images/* /usr/local/apache/htdocs/mrtg/net (將一些影像檔拷

[root @tsai mrtg-2.9.17]# cd /usr/local/mrtg-2/bin [root @tsai bin]# ./cfgmaker

--output=/usr/local/apache/htdocs/mrtg/net/mrtg.cfg \

> public@vbird.adsldns.org

上面這個步驟會在你的主機上面製造一個參數檔,

而你未來的設定都會自動的在這個參數檔中設定完成了!

[root @tsai bin]#

vi /usr/local/apache/htdocs/mrtg/net/mrtg.cfg 不過由於程式自動設定的 mrtg.cfg 有些地方會有瑕疵,

因此,請將底下這三行修改成你的樣式喔!

WorkDir: /usr/local/apache/htdocs/mrtg/net/

Options[_]: growright, bits Language: big5

[root @tsai

bin]# ./mrtg /usr/local/apache/htdocs/mrtg/net/mrtg.cfg 開始測試你的參數檔,正常的話,進行

這個動作要執行三次,就可以正常工作了,

不過,若是有問題的話,就需要改 mrtg.cfg ,再執行直到沒有錯誤 發生為止!

[root @tsai bin]# ./indexmaker \

> --output=/usr/local/apache/htdocs/mrtg/net/index.html \

> --title=VBird 主機流量統計表 \

> /usr/local/apache/htdocs/mrtg/net/mrtg.cfg

上面這個程式 indexmaker 是在製作首頁!當然,你也可以自訂首 頁!

上面是說,會自動的輸出一個 index.html 的檔案到

/usr/local/apache/htdocs/mrtg/net 中,就是主網頁啦!

上面請特別注意:在 public@vbird.adsldns.org 這一行呢,public 是有其意義的(在 snmp 這個通訊服務裡面的預設搜尋的一個代碼), 所以,如果你的主機的動態 DNS 名稱為 your.domain.name 則你就

『一定』要寫成 public@your.domain.name 才行!千萬不要弄錯了!

已經有很多網友遇到這個問題!

2.設定五分鐘偵測一次:

好了,開始偵測吧,就修改 /etc/crontab 吧!

[root @tsai bin]# vi /etc/crontab

#1. Runing The MRTG Net Flow Control

*/5 * * * * root /usr/local/mrtg-2/bin/mrtg

/usr/local/apache/htdocs/mrtg/net/mrtg.cfg > /dev/null 2>&1

。Target[vbird.adsldns.org_2]: 2: public@192.168.1.2 上面是一般的用法,其中半括號內的是裝置的名稱,同一個裝置 的各參數中,這個名稱要一致!

。Target[vbird.adsldns.org_3]:

`/usr/local/apache/htdocs/mrtg/cpu/mrtg.cpu`

後面接的是一個自訂的加掛的可執行檔案,這個檔案執行之後,會顯 示四個數據,這樣就可以繪圖了!在繪製非 MRTG 程式的預設咚咚 中,這個是最常使用的方法了!

•MaxBytes[裝置名稱]:

。MaxBytes[vbird.adsldns.org_2]: 1250000

後面的數字代表資料監測時,最大的傳送速率,使用 bytes,所以 10Mbps 則為 1.25MBytes,大約是 1250000 Bytes。這個數值程式會 自動判斷啦!不過你也可以自己修改,用到這個數字的時候是在你的 圖表下方,每一個說明後面的(xx%)時用到的。

。MaxBytes[vbird.adsldns.org_3]: 100

如果你的資料並不是 Bytes 時,例如監測 CPU 負載率時,那這個數 值就需要改變啦!

•Options[裝置名稱]:

。Options[vbird.adsldns.org_2]: growright, bits (用在網 路流量中)

。Options[vbird.adsldns.org_3]: growright, nopercent, gauge (用在 CPU 負載中)

growright:將資料隨時間變化的順序以右而左繪圖;

bits:資料單位為 bits;

nopercent:在圖下方的說明文字中,不顯示百分比;

gauge:圖表的上限固定!

在文檔中 網路流量自動監控系統 (頁 21-30)

相關文件