Jumat, 31 Agustus 2007

pengaturan bandwidth menggunakan HTB-tools

Mungkin rekan-rekan sudah sering mendengar mengenai limiter menggunakan metode HTB ( Hierarchical Token Bucket), tetapi masih sering banyak pertanyaan-pertanyaan dalam pengaplikasian limiter bandwidth.
Di sini saya mencoba menggunakan HTB-tool yang sudah tersedia.
Saya menggunakan distro centos(redhat family) dan dapat berjalan dengan baik :)
sebelum melakukan instalasi sebaiknya di pastikan dahulu bahwa server mendukung:
- GNU/Linux distribution;
- GCC compiler;
- Iproute2 (the latest version is recommended from here);
- Linux Kernel 2.4.32 or 2.6.15.1 (www.kernel.org);
- dialog for HTB-tools beta 4 (the latest version from here)
- Apache and php for web q_show and web HTB-tools config file generator.
- flex version 2.5.4a.

langkah instalasi:
download HTB-tools
http://htb-tools.arny.ro/download.php --> pilih yang sesuai dengan distro yang digunakan.
setelah itu ekstrak file dan install. saya mendownload htb-tools versi 0.2.7a
#tar xzvf HTB-tools-0.2.7a.tar.gz
masuk ke direktory HTB-tools
# cd HTB-tools-0.2.7a
#make
#make full
#make install

setelah itu ikuti petunjuk dalam instalasinya
kalau di redhat, maka semua program HTB-tools akan di install dalam direktory /etc/
bila sudah selasai, dan tidak ada error, maka tinggal mengkonfigurasi htb tersebut
# mcedit /etc/htb/eth1-qos.cfg -->> untuk mengkonfigurasi downstream
################
# eth1-qos.cfg #
################
# for how to configure and use see docs/HowTo/

class class_1 {
bandwidth 160;
limit 670;
burst 2;
priority 1;

client group_1 {
bandwidth 16;
limit 64;
burst 2;
priority 1;
dst {
192.168.100.2/32;
192.168.100.40/32;
};
};

client group_2 {
bandwidth 45;
limit 200;
burst 2;
priority 1;
dst {
192.168.100.11/32;
192.168.100.12/32;
192.168.100.13/32;
192.168.100.14/32;
192.168.100.15/32;
};
};

client group_3 {
bandwidth 45;
limit 200;
burst 2;
priority 1;
dst {
192.168.100.16/32;
192.168.100.17/32;
192.168.100.18/32;
192.168.100.19/32;
192.168.100.20/32;
};
};

client group_4 {
bandwidth 45;
limit 200;
burst 2;
priority 1;
dst {
192.168.100.21/32;
192.168.100.22/32;
192.168.100.23/32;
192.168.100.24/32;
192.168.100.25/32;
192.168.100.26/32;
};
};

};

class default { bandwidth 200; };
Dalam contoh di atas, saya membagi dalam kelompok. tiap kelompok ada 5 clien, dan dalam setiap kelompok diberikan bandwidth sebesar 45kbps bila trafic sibuk, dan 200kbps bila bandwidth tidak terpakai.
cukup mudah kan...
dibandingkan dengan membuat skript tc seperti contoh di bawah ini
#!/bin/sh
# script written by robby
# this script only creates the qdiscs and classes required for shaping, it
# does NOT create the necessary filters

rc_done=" done"
rc_failed=" failed"
return=$rc_done
#interface
interface='eth1'

TC='/sbin/tc'
tc_reset ()
{
$TC qdisc del dev $interface root 2> /dev/null > /dev/null
}
###############
#seting script#
###############
tcclass='/sbin/tc class add dev eth1 parent'
tcqdisc='/sbin/tc qdisc add dev eth1 parent'
tcfilter='/sbin/tc filter add dev eth1 protocol ip parent 1:0 prio'
tcfilteru32ip='/sbin/tc filter add dev eth1 parent 1:0 protocol ip prio 25 u32 match ip dst'

tc_status ()
{
echo "[qdisc - $interface]"
$TC -s qdisc show dev $interface
echo "------------------------"
echo
echo "[class - $interface]"
$TC -s class show dev $interface
}
tc_showfilter ()
{
echo "[filter - $interface]"
$TC -s filter show dev $interface
}
case "$1" in
start )
echo -n "wait....Starting traffic shaping"
tc_reset

#configure interface

# add root qdisc
$TC qdisc add dev eth1 root handle 1: htb default 100 r2q 2
#add master qdisc
$tcclass 1: classid 1:1 htb rate 1024kbit

$tcclass 1:1 classid 1:100 htb rate 1024kbit ceil 1024kbit burst 200k
$tcqdisc 1:100 handle 100: sfq perturb 10
$tcfilter 10 u32 match ip protocol 1 0xff flowid 1:100

#operator
$tcclass 1:1 classid 1:101 htb rate 20kbit ceil 56kbit burst 1k prio 1
$tcqdisc 1:101 handle 101: sfq perturb 10
$tcfilteru32ip 192.168.100.2/32 flowid 1:101

#group WS1-WS5
$tcclass 1:2 classid 1:102 htb rate 64kbit ceil 256kbit burst 1k prio 1
$tcqdisc 1:102 handle 102: sfq perturb 10
$tcfilteru32ip 192.168.100.3/32 flowid 1:102
$tcfilteru32ip 192.168.100.4/32 flowid 1:102
$tcfilteru32ip 192.168.100.5/32 flowid 1:102
$tcfilteru32ip 192.168.100.6/32 flowid 1:102
$tcfilteru32ip 192.168.100.7/32 flowid 1:102

#group WS6-WS10
$tcclass 1:2 classid 1:103 htb rate 40kbit ceil 200kbit burst 1k prio 1
$tcqdisc 1:103 handle 103: sfq perturb 10
$tcfilteru32ip 192.168.100.8/32 flowid 1:103
$tcfilteru32ip 192.168.100.9/32 flowid 1:103
$tcfilteru32ip 192.168.100.10/32 flowid 1:103
$tcfilteru32ip 192.168.100.11/32 flowid 1:103
$tcfilteru32ip 192.168.100.12/32 flowid 1:103

#filter tcp ack
$TC filter add dev $interface protocol ip parent 1: prio 1 u32 match ip protocol 6 0xff match u8 0x05 0x0f at 0 match u16 0x0000 0xffc0 at 2 match u8 0x10 0xff at 33 flowid 1:2

#--------------------------------------------------------------
#end
tc_status
;;
stop)
echo -n "Stopping traffic shaper"
tc_reset || return=$rc_failed
echo -e "$return"
;;
restart|reload)
$0 stop && $0 start || return=$rc_failed
;;
stats|status)
tc_status
;;
filter)
tc_showfilter
;;
*)
echo "Usage: $0 {start|stop|restart|stats|filter}"
exit 1
esac
test "$return" = "$rc_done" || exit 1
#-------------------------------------------------------------

Tidak ada komentar: