安裝 bandwidthd 於 CentOS 5 伺服器上(bandwidthd on centos 5)
官方網站:http://bandwidthd.sourceforge.net/
注意,要在 switch 上,將 mirror port 功能打開,將全部流量出去的網路孔 a 鏡像 (mirror) 封包到另一個網路孔 b,然後 CentOS 機器(需實體機,而非虛擬機器)要接到網路孔 b 上,才可以依下面步驟安裝。
以下文字引用自「唉喲-MIS 先生」http://i-yow.blogspot.tw/2009/01/bandwidthd.html
1.安裝apache2並啟動
yum install httpd mod_ssl
chkconfig httpd on
service httpd start
2.安裝相關元件
yum install gcc gcc-c++ libpng libpng-devel gd gd-devel elinks libpcap-devel gnuplot
3.下載bandwidthd原始碼
cd /usr/local/src
elinks bandwidthd.sourceforge.net
下載bandwidthd-2.0.1.tgz
4.解壓縮bandwidthd
tar -xzvf bandwidthd-2.0.1.tgz
5.修改bandwidthd上限(預設為20,修改為100)
cd /usr/local/src/bandwidthd-2.0.1
vim graph.c
Top20修改為Top100 (有三個)
Counter < 21修改為Counter < 101 (有兩個)
6.安裝bandwidthd
cd /usr/local/src/bandwidthd-2.0.1
./configure
make install
◎如有發生libpcap錯誤,請安裝libpcap
rpm -i http://isoredirect.centos.org/centos/5/os/i386/CentOS/libpcap-devel-0.9.4-8.1.i386.rpm
rpm -i http://isoredirect.centos.org/centos/5.1/os/i386/CentOS/libpcap-devel-0.9.4-11.el5.i386.rpm
7.修改bandwidthd設定檔
vim /usr/local/bandwidthd/etc/bandwidthd.conf
subnet 192.168.1.0/24
dev "eth0"
8.建立bandwidthd連結
cd /var/www/html
ln -s /usr/local/bandwidthd/htdocs bandwidthd
9.建立bandwidthd啟動
vim /etc/rc.local
加入/usr/local/bandwidthd/bandwidthd
10.網頁
http://主機IP/bandwidthd
記得要先執行 bandwidthd (以 root 身份執行 /usr/local/bandwidthd/bandwidthd ) 再去網頁介面觀看流量,等幾分鐘後就會有圖出來。
單一 ip 有統計圖連結出現,但也是要過一會兒才會出來。
預設是重開機後所有資料需重建,若要重開機保留過往圖形紀錄,請參考以下 readme 檔中的這一段:
#### HOW TO KEEP YOUR GRAPHS BETWEEN REBOOTS #
Following is the easy way to keep your graphs between reboots. You can also opt
to build and use bandwidthd with database support, as described in "DATABASE SUPPORT"
below.
In the bandwidthd.conf file set:
output_cdf true
recover_cdf true
output_cdf will cause Bandwidthd to log all of it's data to the log.cdf file
in it's directory. recover_cdf will cause Bandwidthd to load that file when
it starts. You will also want to make a crontab entry like so:
0 0 * * * * /bin/kill -HUP `cat /var/run/bandwidthd.pid`
This will send Bandwidthd a HUP every night at midnight. When Bandwidthd
receives a HUP it schedules a rotation of it's log files during the next
graphing run. Daily log files rotate each HUP. Weekly/Monthly/Yearly log
files rotate every so many HUPs. Log files get rotated out 5 times before
deletion.
Fyi, if you use killall instead of kill, each of the children will receive
the HUP command twice, causing them to rotate their log files twice as
often as they should.
編輯:
vi /usr/local/bandwidthd/etc/bandwidthd.conf
加入兩行:
output_cdf true
recover_cdf true
以 root 身份:
#vi /etc/crontab
於 /etc/crontab 中加上一行:
0 0 * * * * /bin/kill -HUP `cat /var/run/bandwidthd.pid`
0 0 * * * root /bin/kill -HUP `cat /var/run/bandwidthd.pid`
重開機後等資料進來到網頁後,再重開機一次,看資料會不會被清空,沒被清空就表示成功了。
bandwidthd 實際運作的網頁在:
/usr/local/bandwidthd/htdocs/
目錄下。
鎖網頁:
可在 /usr/local/bandwidthd/htdocs/ 下加 .htaccess 檔,新增資料匣 httpd (root:root 755 權限),於下新增 passwd 檔。此兩檔均為 root:root 及 644 權限。
以 root 身份:
#vi /usr/local/bandwidthd/htdocs/.htaccess
加入以下文字
AuthType Basic
AuthName Bandwidthd
AuthUserFile /usr/local/bandwidthd/htdocs/httpd/passwd
require user admin
存檔。
#cd /usr/local/bandwidthd/htdocs/httpd/
#htpasswd -c passwd admin
(允許 admin 設定密碼)
#vi /etc/httpd/conf/httpd.conf
加入下面段落,記得要用 /var/www/html/bandwidthd 這個連結檔,非真實 /usr/local/bandwidthd/htdocs/ 目錄。
<Directory /var/www/html/bandwidthd>
AllowOverride All
Options MultiViews Indexes Includes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
#service httpd restart
接下來就可以開網頁測試。