トラフィックコントローラーを構築する
トラフィックコントロールを実施する事でネットワークで必要な帯域の確保や、トラフィックを制限をポート毎に行い他のサービスへの反応が悪くなるのを防ぐことが出来ます。
構築内容の概要
-
OpenBlockS 600D
aptitiudeでアップデート
brctlのインストール
cbq.iniのダウンロード
スクリプトの修正
設定ファイルの作成
ブリッジポートの設定
想定する設置構成
設定に必要な情報
-
OpenBlockS 600Dがインターネットにでれる様にネットワークを設定する必要があります。
手順
- OpenBlockS 600Dの初期設定
[OpenBlockS 600D 最初の設定]を参照し、初期設定を実施して下さい。 - brctlのインストール
ブリッジ設定をするためにbridge-utilsをインストールします。# aptitude install bridge-utils The following NEW packages will be installed: bridge-utils . . . Setting up bridge-utils (1.4-5) ...
- cbq.iniのダウンロード
トラフィックコントロールを実施する為のスクリプト(CBQ.ini)をダウンロードします。#wget http://jaist.dl.sourceforge.net/project/cbqinit/cbqinit/0.7.3/cbq.init-v0.7.3 . . . 100%[================================================>] 33,438 --.-K/s in 0.1s 2011-09-07 14:00:50 (261 KB/s) - `cbq.init-v0.7.3' saved [33438/33438]
- cbq.init-v0.7.3のファイル名を変更し/etc/init.dへ移動します。
#mv cbq.init-v0.7.3 /etc/init.d/cbq.ini
- 実行権限を付与します。
#chmod +x cbq.ini
- 設定ファイルの保存先/etc/sysconfig/cbqを作成します。
#mkdir /etc/sysconfig/cbq
- そのままのcbq.iniを使用するとワーニングが出る為、設定ファイルを編集します。
cbq.iniの編集内容
# vi cbq.ini
変更行数576行目〜589行目cbq_init () { ### Get a list of configured classes CLASSLIST=`find $1 -maxdepth 1 \( -type f -or -type l \) -name 'cbq-*' \ -not -name '*~' -printf "%f\n"| sort` [ -z "$CLASSLIST" ] && cbq_failure "no configuration files found in $1!"■修正前CLASSLIST=`find $1 \( -type f -or -type l \) -name 'cbq-*' \ -not -name '*~'-maxdepth 1 -printf "%f\n"| sort`■修正後CLASSLIST=`find $1 -maxdepth 1 \( -type f -or -type l \) -name 'cbq-*' \ -not -name '*~' -printf "%f\n"| sort`■修正前DEVFIELDS=`find $1 \( -type f -or -type l \) -name 'cbq-*' \ -not -name '*~' -maxdepth 1 | xargs sed -n 's/#.*//; \■修正後DEVFIELDS=`find $1 -maxdepth 1 \( -type f -or -type l \) -name 'cbq-*' \ -not -name '*~' | xargs sed -n 's/#.*//; \ - /etcinit.d/cbq.iniをstartを実行してエラーが無くなっている事を確認します。
root@squeeze:/etc/init.d# /etc/init.d/cbq.ini start root@squeeze:/etc/init.d# /etc/init.d/cbq.ini stats ### eth0: queueing disciplines qdisc pfifo_fast 0: root bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1 Sent 1106305 bytes 14025 pkt (dropped 0, overlimits 0 requeues 0) rate 0bit 0pps backlog 0b 0p requeues 0 ### eth1: queueing disciplines qdisc pfifo_fast 0: root bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) rate 0bit 0pps backlog 0b 0p requeues 0 root@squeeze:/etc/init.d# /etc/init.d/cbq.ini list ### eth0: queueing disciplines qdisc pfifo_fast 0: root bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1 ### eth1: queueing disciplines qdisc pfifo_fast 0: root bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
これでcbq.iniのインストールが完了です - 設定ファイルの作成
トラフィックコントローラーで使用する設定ファイルは以下の様にします。
1. /etc/sysconfig/cbq 以下に設定ファイルを作成する。
2. ファイル名は cbq-クラスID.名前 とします。
クラスID
:
10進で2-65535の値(16進で0002-FFFF)で指定する。
他の設定ファイルと重複は不可。名前
:
自分でわかりやすいもの
(例 httpの場合は cbq-80.http )
3. 設定ファイルのパラメータは以下になります。
DEVICE=<インターフェース名>,<物理NICのリンク速度>,<ウェイト> RATE=<割り当ての帯域> PRIO=<プライオリティ1-8glt;(値が小さいほど優先的に処理) RULE=[[ソースアドレス[/prefix]][:port],][ディスティネーションアドレス [/prefix]][:port] TIME=[<dow>,<dow>, ...,<dow>/]<from>-<till>;<rate>/<weight> ※1
ここでいくつか設定例を記載しておきます。
【webの帯域を制御する設定例】
DEVICE=eth0,1000Mbit,100Mbit RATE=2Mbit WEIGHT=200Kbit PRIO=5 RULE=:80,
【ftpの帯域を制御する設定例】
DEVICE=eth0,1000Mbit,100Mbit RATE=50Mbit WEIGHT=5Mbit PRIO=5 RULE=:20, RULE=:4096/0xffe0,
【SFTPの帯域を制御する設定例】
DEVICE=eth1,1000Mbit,100Mbit RATE=300Mbit WEIGHT=30Mbit PRIO=1 RULE=:22,
備考
※1 : TIMEを使用する場合は、cronから定期的にcbq.ini timecheckを実行する必要があります。
【参考】cbq.ini のファイル内
# v0.3a - added TIME parameter. Example: TIME=00:00-19:00;64Kbit/6Kbit # So, between 00:00 and 19:00 the RATE will be 64Kbit. # Just start "cbq.init timecheck" periodically from cron # (every 10 minutes for example). DON'T FORGET though, to run # "cbq.init start" for CBQ to initialize.
- 自動起動の設定
起動時にcbq.iniを自動起動するようにするには以下を設定していきます。
# cd /etc/rc2.d # ln -s ../init.d/cbq.ini S90cbq.ini # ls -al S90cbq.ini lrwxrwxrwx 1 root root 17 Jan 6 13:09 S90cbq.ini -> ../init.d/cbq.ini
- ブリッジネットワークの設定
/etc/init.d/network/interfacesに以下を追加します。
auto br0 iface br0 inet static address xxx.xxx.xxx.xxx network xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx broadcast xxx.xxx.xxx.xxx bridge_ports all - 設定が全て終わったらflacfg -sを実行します。
# flashcfg -s FlashROM overwrites the current data. Are you ok? [y|N] y Archiving /etc config files... done (Approximately 20 KBytes) Erasing blocks: 1/1 (100%) Writing data: 0k/18k (100%) Verifying data: 0k/18k (100%)
- 稼働している事を確認します。
#/etc/init.d/cbq.ini stats ### eth0: queueing disciplines qdisc cbq 1: root rate 1000Mbit (bounded,isolated) prio no-transmit Sent 606 bytes 9 pkt (dropped 0, overlimits 0 requeues 0) rate 0bit 0pps backlog 0b 0p requeues 0 borrowed 0 overactions 0 avgidle 7 undertime 0 qdisc tbf 11: parent 1:11 rate 50000Kbit burst 10Kb lat 820us Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) rate 0bit 0pps backlog 0b 0p requeues 0 qdisc tbf 22: parent 1:22 rate 50000Kbit burst 10Kb lat 820us Sent 54 bytes 1 pkt (dropped 0, overlimits 0 requeues 0) rate 0bit 0pps backlog 0b 0p requeues 0 qdisc tbf 80: parent 1:80 rate 2000Kbit burst 10Kb lat 20.5ms Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) rate 0bit 0pps backlog 0b 0p requeues 0 ### eth0: traffic classes class cbq 1: root rate 1000Mbit (bounded,isolated) prio no-transmit Sent 606 bytes 9 pkt (dropped 0, overlimits 0 requeues 0) rate 0bit 0pps backlog 0b 0p requeues 0 borrowed 0 overactions 0 avgidle 7 undertime 0 class cbq 1:11 parent 1: leaf 11: rate 50000Kbit (bounded) prio 5 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) rate 0bit 0pps backlog 0b 0p requeues 0 borrowed 0 overactions 0 avgidle 4212 undertime 0 class cbq 1:22 parent 1: leaf 22: rate 50000Kbit (bounded) prio 5 Sent 54 bytes 1 pkt (dropped 0, overlimits 0 requeues 0) rate 0bit 0pps backlog 0b 0p requeues 0 borrowed 0 overactions 0 avgidle 4212 undertime 0 class cbq 1:80 parent 1: leaf 80: rate 2000Kbit (bounded) prio 5 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) rate 0bit 0pps backlog 0b 0p requeues 0 borrowed 0 overactions 0 avgidle 110649 undertime 0 class tbf 11:1 parent 11: class tbf 22:1 parent 22: class tbf 80:1 parent 80: ### eth0: filtering rules filter parent 1: protocol ip pref 100 u32 filter parent 1: protocol ip pref 100 u32 fh 800: ht divisor 1 filter parent 1: protocol ip pref 100 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:11 (rule hit 1 success 0) match 00000014/0000ffff at 20 (success 0 ) filter parent 1: protocol ip pref 100 u32 fh 800::801 order 2049 key ht 800 bkt 0 flowid 1:11 (rule hit 1 success 0) match 10000000/ffe00000 at 20 (success 0 ) filter parent 1: protocol ip pref 100 u32 fh 800::802 order 2050 key ht 800 bkt 0 flowid 1:22 (rule hit 1 success 0) match 00000014/0000ffff at 20 (success 0 ) filter parent 1: protocol ip pref 100 u32 fh 800::803 order 2051 key ht 800 bkt 0 flowid 1:22 (rule hit 1 success 1) match 00160000/ffff0000 at 20 (success 1 ) filter parent 1: protocol ip pref 100 u32 fh 800::804 order 2052 key ht 800 bkt 0 flowid 1:80 (rule hit 0 success 0) match 00500000/ffff0000 at 20 (success 0 ) ### eth1: queueing disciplines qdisc pfifo_fast 0: root bands 3 priomap 1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1 Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) rate 0bit 0pps backlog 0b 0p requeues 0
- クライアントからアクセスします。
クライアントからweb経由でデータのダウンロードや、ftpなどで実際に帯域が制限されている事を確認できれば完了です。
