2008年2月29日 星期五

LEAF Channel Bonding 筆記

Linux Bonding 的驅動程式最早是在 Lnux Kernel 2.0 由 Donald Becker 提供 Bonding 的核心修補檔案,至目前已逐漸成為 Linux Kernel 正式套件之一。

 

Channel Bonding 一般又稱呼為 Port Trunking,是將兩張以上的網路卡合併成為一張邏輯的網路界面來使用,主要功能有以下兩項:

頻寬輸入與輸出倍增:安裝兩張以上網路卡並搭配 Bonding 的配置,主機到 SWITCH 設備端的網路頻寬,可以倍增。

網路線路與設備備援:提供網路卡至 SWITCH 的備援,可以避免機器本身網路卡故障或者是網路線斷裂導致網路不通的問題。

 

Bonding 無法達成的功能:

無法提供不同網段的頻寬合併,網路卡必須在同一網段中。

SWITCH 當機,線路連接正常,指 SWITCH 及網路卡兩端 link 燈顯示正常,雖然網路中斷,但因 Bonding 驅動程式無法正確偵測到,網路線路與設備備援功能將失效,不會有切換動作。

 

LEAF 中設定 Channel Bonding 步驟

下載 ifenslav.lrp http://leaf.sourceforge.net/bering-uclibc/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=12&MMN_position=32:32

 

設定範例:

module 載入 bonding.o 位於 Bering-uClibc_modules_xxxx.tar\2.4.33\kernel\drivers\net\bonding\bonding.o

insmod bonding mode=1 miimon=50

ip addr add 192.168.1.1/24 dev bond0
ip link set bond0 up
ifenslave bond0 eth0 eth1



bonding 參數說明:

mode:Bonding 模式(1~6)

miimon:每隔多久 (milli-seconds) 偵測一次狀態


mode:Bonding 模式相關說明

mode=0 (balance-rr) Round-robin policy:交換器需設定 trunk 支援,具容錯功能,其中一張 Slave 網卡失效仍可持續運作。

Transmit packets in sequential order from the first available slave through the last. This mode provides load balancing and fault tolerance.


mode=1 (active-backup) Active-backup policy:不需交換器支援,同一時間只有單一 Slave 網卡運作,Active Slave 網卡失效時自動啟用次一順位 Slave 網卡。

Only one slave in the bond is active. A different slave becomes active if, and only if, the active slave fails. The bond's MAC address is externally visible on only one port (network adapter) to avoid confusing the switch. This mode provides fault tolerance. The primary option affects the behavior of this mode.

mode=2 (balance-xor) XOR policy:

Transmit based on [(source MAC address XOR'd with destination MAC address) modulo slave count]. This selects the same slave for each destination MAC address. This mode provides load balancing and fault tolerance.

mode=3 (broadcast) Broadcast policy: 具容錯功能,所有 Slave 網卡一齊收送網路封包,其中一張 Slave 網卡失效仍可持續運作

transmits everything on all slave interfaces. This mode provides fault tolerance.

mode=4 (802.3ad) IEEE 802.3ad Dynamic link aggregation.

Creates aggregation groups that share the same speed and duplex settings. Utilizes all slaves in the active aggregator according to the 802.3ad specification.

    Pre-requisites:
    1. Ethtool support in the base drivers for retrieving the speed and duplex of each slave.
    2. A switch that supports IEEE 802.3ad Dynamic link aggregation.
    Most switches will require some type of configuration to enable 802.3ad mode.

mode=5 (balance-tlb) Adaptive transmit load balancing(輸出自動負載平衡): 不需交換器支援及設定,具容錯功能,傳入由 Current Active Slave 負責,其中一張 Slave 網卡失效仍可持續運作

channel bonding that does not require any special switch support. The outgoing traffic is distributed according to the current load (computed relative to the speed) on each slave. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed receiving slave.

    Prerequisite:
    Ethtool support in the base drivers for retrieving the  speed of each slave.

mode=6 (balance-alb) Adaptive load balancing(輸出/入皆自動負載平衡): 具容錯功能,不需交換器支援及設定,Slave 網卡 driver 需支援 setting hardware address 功能,其中一張 Slave 網卡失效仍可持續運作。

includes balance-tlb plus receive load balancing (rlb) for IPV4 traffic, and does not require any special switch support. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the local system on their way out and overwrites the source hardware address with the unique hardware address of one of the slaves in the bond such that different peers use different hardware addresses for the server.


相關檔案:

/proc/net/bond0/info

/proc/net/bond1/info

….

/proc/net/bondn/info


/etc/modules.conf 設定範例
alias bond0 bonding
options bond0 -o bond0 mode=0 miimon=100
alias bond1 bonding
options bond1 -o bond1 mode=1 miimon=100

 

參考文件:

http://jaist.dl.sourceforge.net/sourceforge/bonding/bonding.txt



2008年2月20日 星期三

Perl CGI筆記

Perl CGI 讀取 FORM 變數方法
若是 FORM method 為 POST,由STDIN讀取傳入的變數值
read(STDIN, $finfo, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/,$finfo);
foreach $pair (@pairs)
{
($name,$value) = split(/=/,$pair);
$value =~ s/+/ /g;
$value =~ s/%([0-9a-fA-F][0-9a-fA-F])/
pack("C", hex($1))/eg;
$FORM{$name} = $value;
}

若是 FORM method 為 GET,由ENV剖析出傳入的變數值
$finfo = $ENV{'QUERY_STRING'}
@pairs = split(/&/,$finfo);
foreach $pair (@pairs)
{
($name,$value) = split(/=/,$pair);
$value =~ s/+/ /g;
$value =~ s/%([0-9a-fA-F][0-9a-fA-F])/
pack("C", hex($1))/eg;
$FORM{$name} = $value;
}

列印出所有環境變數方法
foreach $key (sort keys(%ENV)) {
print "$key = $ENV{$key}<p>";
}

已知中文字型在Big5的順序,反推出 Big5

由以下中文 Big5 順序公式可反推

//高位元區段 81-8D 8E-A0 A1-FE ---->126個
//低位元區段 40-7E A1-FE ---> 157 個
//先計算高位元的距離 公式:(高位元 - 0x81) * 157
//再計算低位元距離 分為兩組 40-7E A1-FE
//0x40=64 0x7E=126 63個
//0xA1=161 0xFE=254 94個
//落在 0x40-0x7E 直接加上 (低位元的值 - 0x40 + 1)
//落在 0xA1-0xFE 63 + (低位元的值 - 0xA1 + 1)

$big5order --> Big5順序

$temp1 = $big5order / 157 的餘數

$temp2 = $big5order / 157 的商

若餘數為 0 ==> Big5 高位元為 $temp2 -1 + 0x81 低位元為 0xFE

若餘數為 小於 64 ==> Big5 高位元為 $temp2 + 0x81 低位元為 $temp + 0x40 - 1

若餘數為 大於64 ==> Big5 高位元為 $temp2 + 0x81 低位元為 $temp -63 + 0xA1 - 1

<?php

$temp = ($big5order%157);
$hicode = (int)($big5order/157) + 0x81;
if($temp==0){
$hicode = $hicode - 1;
$locode = 0xFE;
} else if($temp < 64) $locode = $temp + 0x40 - 1;
else $locode = $temp - 63 + 0xA1 - 1;

?>

LEAF Bering-uClibc packages 3.x 使用 ULOG + MySQL

LEAF部份
1.安裝以下 LRP
ulogdsql.lrp
libmysql.lrp
libm.lrp
libz.lrp

2.設定Ulogd
/etc/ulogd.conf
#output plugins.
plugin="/usr/lib/ulogd/ulogd_MYSQL.so"

[MYSQL]部份
table="ulog"
pass="changeme"
user="laforge"
db="ulogd"
host="192.168.1.2"

3.修改 shorewall 規則,讓 fw 可以存取 Log MySQL Server

4.重新啟動 ulogd
/etc/init.d/ulogd startstoprestart



Log MySQL Server 部份
1.安裝好 MySQL
2.根據 /etc/ulogd.conf MySQL相關設定中建立資料庫叫及帳號
3.下載 ulogd 原始碼,解開後將 /ulogd-1.24/doc/mysql.table 匯入至 ulogd 資料庫

MySQL保留字

以下為MySQL保留字,不能使用下列名稱作為表格名稱或欄位名稱,其中大多數和ANSI SQL92相同,一些保留原因是因為MySQL中使用yacc的語法分析器,若使用函式名稱作為表格/欄位名稱,則函式後接著的"("中間不可空白。

ADD

ALL

ALTER

ANALYZE

AND

AS

ASC

AUTO_INCREMENT

BDB

BEFORE

BERKELEYDB

BETWEEN

BIGINT

BINARY

BLOB

BOTH

BTREE

BY

CASCADE

CASE

CHANGE

CHAR

CHARACTER

CHECK

COLLATE

COLUMN

COLUMNS

CONSTRAINT

CREATE

CROSS

CURRENT_DATE

CURRENT_TIME

CURRENT_TIMESTAMP

DATABASE

DATABASES

DAY_HOUR

DAY_MINUTE

DAY_SECOND

DEC

DECIMAL

DEFAULT

DELAYED

DELETE

DESC

DESCRIBE

DISTINCT

DISTINCTROW

DIV

DOUBLE

DROP

ELSE

ENCLOSED

ERRORS

ESCAPED

EXISTS

EXPLAIN

FALSE

FIELDS

FLOAT

FOR

FORCE

FOREIGN

FROM

FULLTEXT

FUNCTION

GRANT

GROUP

HASH

HAVING

HIGH_PRIORITY

HOUR_MINUTE

HOUR_SECOND

IF

IGNORE

IN

INDEX

INFILE

INNER

INNODB

INSERT

INT

INTEGER

INTERVAL

INTO

IS

JOIN

KEY

KEYS

KILL

LEADING

LEFT

LIKE

LIMIT

LINES

LOAD

LOCALTIME

LOCALTIMESTAMP

LOCK

LONG

LONGBLOB

LONGTEXT

LOW_PRIORITY

MASTER_SERVER_ID

MATCH

MEDIUMBLOB

MEDIUMINT

MEDIUMTEXT

MIDDLEINT

MINUTE_SECOND

MOD

MRG_MYISAM

NATURAL

NOT

NULL

NUMERIC

ON

OPTIMIZE

OPTION OPTIONALLY

OR

ORDER

OUTER

OUTFILE

PRECISION

PRIMARY

PRIVILEGES

PROCEDURE

PURGE

READ

REAL

REFERENCES

REGEXP

RENAME

REPLACE

REQUIRE

RESTRICT

RETURNS

REVOKE

RIGHT

RLIKE

RTREE

SELECT

SET

SHOW

SMALLINT

SOME

SONAME

SPATIAL

SQL_BIG_RESULT

SQL_CALC_FOUND_ROWS

SQL_SMALL_RESULT

SSL

STARTING

STRAIGHT_JOIN

STRIPED

TABLE

TABLES

TERMINATED

THEN

TINYBLOB

TINYINT

TINYTEXT

TO

TRAILING

TRUE

TYPES

UNION

UNIQUE

UNLOCK

UNSIGNED

UPDATE

USAGE

USE

USER_RESOURCES

USING

VALUES

VARBINARY

VARCHAR

VARCHARACTER

VARYING

WARNINGS

WHEN

WHERE

WITH

WRITE

XOR

YEAR_MONTH

ZEROFILL

以下的符號(來自上表)是被 ANSI SQL 禁止的,但是可以被 MySQL 用於列/表名

ACTION
BIT
DATE
ENUM
NO
TEXT
TIME
TIMESTAMP