Debian Book

วันพุธที่ 7 มกราคม พ.ศ. 2552

Ethernet Bonding Fedora Linux

พอร์ตแลน (Ethernet) ของเครื่องเซิร์ฟเวอร์ถือว่าเป็นสิ่งสำคัญอย่างยิ่ง เพราะเป็นส่วนที่จะรับส่งข้อมูลกับเคื่องอื่นๆ ถ้าเซิร์ฟเวอร์มีแค่พอร์ตเดียวเชื่อมต่อเข้าเน็ตเวิร์ก แล้วสายที่เชื่อมต่อหลุดไป หรือไม่สามารถรองรับปริมาณการรับส่งข้อมูลได้เพียงพอ ก็อาจทำให้เกิดปัญหาการใช้งานได้

ในบทความนี้ขอแนะนำการคอนฟิก Ethernet Bonding (หรือ Teaming) เพื่อแก้ปัญหาที่อาจเกิดขึ้น โดยจะมีการจัดกลุ่มพอร์ตแลนเข้าด้วยกัน เพื่อช่วยในการรับส่งข้อมูล รูปแบบการส่งจะมีสองแบบใหญ่ๆ คือ

Active-backup พอร์ตหนึ่งจะทำหน้าพอร์ตหลักเพื่อใช้รับส่งข้อมูล (Active) แต่อีกพอร์ตหนึ่งจะสำรอง (Backup) ไว้เฉยๆ ไม่มีการรับส่งข้อมูลใดๆ ผ่านทางพอร์ตสำรอง แต่เมื่อไรที่พอร์ตหลักมีปัญหาพอร์ตนี้จะรับส่งข้อมูลแทน สำหรับ Ethernet Bonding จะเป็นคอนฟิกใน mode 1
Load Balance พอร์ตทั้งหมดในกลุ่มจะช่วยกันรับส่งข้อมูล ส่วนเทคนิคในการรับส่งจะมีหลายแบบด้วยกันแล้วแต่ mode ที่คอนฟิก
ในตัวอย่างจะเป็นการคอนฟิกบน Fedora 9 ซึ่งน่าจะประยุกต์ใช้กับ Fedora เวอร์ชั่นอื่นๆ, CentOS, RedHat หรือลีนุกซ์ตัวอื่นๆ ได้

เตรียมพอร์ตแลนที่จะคอนฟิกเป็น Ethernet Bonding
ในตัวอย่างจะใช้พอร์ตแลน eth2 และ eth3 เพื่อคอนฟิกรวมเป็น bond0

เริ่มต้นสร้างไฟล์ /etc/sysconfig/network-scripts/ifcfg-bond0 ซึ่งจะเป็นไฟล์คอนฟิกของ bond0 เป็นพอร์ต bonding (ในเครื่องหนึ่งสามารถจัดกลุ่มทำได้หลาย bonding พอร์ตที่คอนฟิกก็จะเป็น bond1, bond2 เป็นต้น) ในไฟล์จะมีคอนฟิก IP Address, Netmask เหมือนที่คอนฟิกพอร์ต ethernet ทั่วไป

ตัวอย่างคอนฟิก ifcfg-bond0

[root@fc9-x1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=10.1.0.1
NETMASK=255.255.255.0
BROADCAST=10.1.0.255
ONBOOT=yes
BOOTPROTO=none
USERCTL=noคอนฟิกพอร์ต (Physical) ให้อยู่ในกลุ่ม bond0 ตามตัวอย่าง

[root@fc9-x1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USECTL=no[root@fc9-x1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth3
DEVICE=eth3
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USECTL=noแก้ไขไฟล์ /etc/modprobe.conf เพื่อให้โหลด kernel module สำหรับการทำ bonding ตอนที่มีการโหลดคอนฟิก bond0

[root@fc9-x1 ~]# cat /etc/modprobe.conf
alias bond0 bonding
options bonding miimon=100 mode=1สามารถระบุว่าจะทำ bonding เพื่อรับส่งข้อมูลแบบไหนได้จากคอนฟิก mode ดังนี้

mode=0 (balance-rr) เป็นการส่งข้อมูลแบบ round-robin (load balancing, fault tolerance)
mode=1 (active-backup) สถานการณ์ปกติจะมีพอร์ตเดียวเท่านั้นที่ใช้รับส่งข้อมูล (fault tolerance)
mode=2 (balance-xor) เป็นการส่งข้อมูลแบบใช้ XOR เพื่อหาพอร์ตที่จะส่ง เช่นคำนวณจาก MAC Address ต้นทางปลายทางเป็นต้น (load balancing, fault tolerance)
mode=3 (broadcast)
mode=4 (802.3ad) เป็นส่งข้อมูลแบบ Link Aggregation Control Protocol (LACP) / 802.3ad
mode=5 (balance-tlb) ส่งข้อมูลแบบ Adaptive transmit load balancing
mode=6 (balance-alb) ส่งข้อมูลแบบ Adaptive load balancing
หมายเหตุ รายละเอียดเพิ่มเติมดูได้จากไฟล์ /usr/share/doc/kernel-doc-2.6.25/Documentation/networking/bonding.txt จาก kernel-doc-2.6.25-14.fc9.noarch.rpm

ในเริ่มต้นแนะนำให้ทดสอบกับ mode=1 เพื่อทดลอง active-backup ก่อน

หลังจากสร้างไฟล์คอนฟิกทั้งหมดแล้ว รีบูตเครื่องหนึ่งครั้ง เผื่อให้ bond0 ถูกโหลดขึ้นมา

ตรวจสอบสถานะของ Ethernet Bonding
เมื่อเครื่องบูตเสร็จเรียบร้อย ถ้าถูกต้องเมื่อรันคำสั่ง ifconfig จะมีพอร์ต bond0 เพิ่มขึ้นมาตามตัวอย่าง

[root@server ~]# ifconfig
bond0 Link encap:Ethernet HWaddr 00:0C:22:FF:11:55
inet addr:10.1.0.1 Bcast:10.1.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:13 errors:0 dropped:0 overruns:0 frame:0
TX packets:19 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1160 (1.1 KiB) TX bytes:1574 (1.5 KiB)...eth2 Link encap:Ethernet HWaddr 00:0C:22:FF:11:55
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:19 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1100 (1.0 KiB) TX bytes:1574 (1.5 KiB)
Interrupt:16 Base address:0x1824eth3 Link encap:Ethernet HWaddr 00:0C:22:FF:11:55
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:1 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:60 (60.0 b) TX bytes:0 (0.0 b)
Interrupt:17 Base address:0x18a4ข้อสังเกตจากคำสั่ง ifconfig

HWaddr หรือ MAC Address ของแต่ละพอร์ตที่ทำ bonding ด้วยกันจะเป็นค่าเดียวกันหมด ทั้งนี้เพื่อประโยชน์ในการทำ fail over
ในโหมด active-backup ปกติจะมีพอร์ตเดียวทำหน้าที่เป็นหลักใช้ในการรับส่งข้อมูล ซึ่งดูได้จากค่า RX, TX packets
หากต้องการรู้ว่าพอร์ตไหนถูกใช้เป็นหลัก (active) ในการส่งข้อมูล สามารถดูได้จากไฟล์ /proc/net/bonding/bond0

ตัวอย่างไฟล์ /proc/net/bonding/bond0

[root@fc9-x1 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.5 (March 21, 2008)Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:22:ff:11:55Slave Interface: eth3
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:22:ff:11:56จากตัวอย่างพอร์ตหลักที่ถูกใช้ในโหมด (active-backup) คือพอร์ต eth2 ดูได้จาก Currently Active Slave: eth2

ทดสอบการ fail over
แนะนำว่าก่อนที่จะดึงสายแลนให้รันคำสั่ง ping ทิ้งไว้ เพื่อดูว่าเวลาที่มีการ fail over จะยังส่งข้อมูลต่อไปได้เลยไหม

ทดลองดึงสายออกจากพอร์ต eth2 แล้วตรวจสอบไฟล์ /proc/net/bonding/bond0 อีกครั้ง จะเห็นว่าพอร์ต eth3 จะถูกนำมาใช้เป็นหลักในการรับส่งข้อมูลแทน แล้วคำสั่ง ping ก็ยังคงทำงานอยู่ อาจมีสะดุดไปบ้างเล็กน้อย

[root@fc9-x1 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.5 (March 21, 2008)Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth3
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0Slave Interface: eth2
MII Status: down
Link Failure Count: 1
Permanent HW addr: 00:0c:22:ff:11:55Slave Interface: eth3
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:22:ff:11:56จากผลลัพธ์จะแสดงสถานะของ bonding ต่างๆ ดังนี้

Currently Active Slave: eth3 พอร์ตหลักที่ใช้รับส่งข้อมูลตอนนี้
Slave Interface: eth2, MII Status: down สถานะของพอร์ต eth2 down
Link Failur Count: 1 แสดงตัวเลขจำนวนครั้งที่พอร์ตมีปัญหา
สุดท้ายทดสอบด้วยการเสียบสายกลับเข้าไปที่พอร์ตที่ 2 จะเห็นว่าไม่มีการ fail over กลับมาที่พอร์ต eth2 พอร์ต eth3 จะยังคงเป็นหลักในการรับส่งข้อมูลอยู่

วันศุกร์ที่ 26 ธันวาคม พ.ศ. 2551

** ตั้งค่า IP. ที่การ์ดแลน **

** ตั้งค่า IP. ที่การ์ดแลน **

# alias ที่ไฟล์ /etc/rc.conf
ifconfig_rl0="inet 192.168.0.1 netmask 255.255.255.0"
ifconfig_rl0_alias0="inet 192.168.0.2 netmask 255.255.255.255"

เสร็จแล้วใช้คำสั่ง netstart ครับ

#/etc/netstart ; เพื่อ restart network configuration

ถ้าจะ set lan card ใบเดียวให้มี หลาย ๆ ip ให้ทำแบบนี้คับ
# ifconfig rl0 alias 192.168.1.1 netmask 255.255.255.0
# ifconfig
rl0: flags=8843 mtu 1500
inet 202.29.80.130 netmask 0xffffff80 broadcast 202.29.80.255
inet6 fe80::202:44ff:fe14:ba%rl0 prefixlen 64 scopeid 0x1
inet 192.168.1.1 netmask 0xffffff00 broadcast 192.168.0.255
ether 00:02:44:14:00:ba
media: Ethernet autoselect (100baseTX )
status: active

เพียงแค่นี้ก็จะสามารถใช้ได้ 2 ip คับผม

หรือถ้าต้องการให้ ip ที่เพิ่มเข้าไปใหม่นั้นทำงานทุกครั้งที่มีการ boot เครื่องให้เพิ่มบรรทัดนี้ ในไฟล์ /etc/rc.conf นะคับ

ifconfig_rl0_alias0="192.168.1.1 netmask 255.255.255.0"

สามารถทำได้หลายแบบนะครับ
รู้สึกว่าใน Slackware จะใช้แบบนี้นะครับ

# ifconfig rl0:0 inet xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx
# ifconfig rl0:1 inet xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx

ถ้า rl0 คือชื่อ lan card ใบที่ 1 กำหนดเป็น ip address ตัวที่ 1
ส่วน :0 และ :1 ก็เป็นหมายเลข ip address ตัวที่ 2 และ 3 ตามลำดับ

ส่วน BSD น่าจะอย่างงี้นะคับ

# ifconfig_rl0="xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx"
# ifconfig_rl0_alias1="xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx"
# ifconfig_rl0_alias0="xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx"

ถ้าทำผ่าน sysinstall ก็ขั้นตอนนี้นะครับ
/stand/sysinstall -> เลือก configure -> เลือก networking -> เลือก interface -> เลือก ชื่อ lancard ที่จะใส่ค่าไอพี -> จะขึ้นหน้าจอถามค่า IPV6 ตอบ NO -> หน้าจอถามว่าจะรับค่า DHCP หรือไม่ ถ้าไม่ตอบ NO -> จากนั้นจะขึ้นหน้าจอใส่ค่า host , domain ,ip gateway , dns , ip การ์ด , subnetmask ก็ใส่ให้ถูกต้องแล้วก็ OK -> จากนั้นจะกลับมาหน้า interface ใหม่ ให้ทำตามเดิมเลือกอีกการ์ดนึงนะครับ
หรือจะสั่งที่ command line เลยก็ได้ เช่น
ifconfig <ชื่อ interface> inet <เลขไอพี> netmask <เลข netmask> up แล้ว enter ตัวอย่างนะครับ ifconfig bge0 inet 203.185.98.99 netmask 255.255.255.248 up แบบนี้อะคับ ต้อง boot ใหม่ด้วย
แล้วลอง ifconfig ดู

เอาแบบ command line เลยครับง่ายดี

# ifconfig rl0 inet xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx
# ifconfig rl1 inet xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx

# ifconfig rl0 down / up
# ifconfig rl1 down / up

rl0 คือ ชื่อการ์ดแลนใบที่ 1
rl1 คือ ชื่อการ์ดแลนใบที่ 2

http://www.thaibsd.com/webboard/search.php?Category=thaibsd

วันพฤหัสบดีที่ 25 ธันวาคม พ.ศ. 2551

เพิ่ม HDD ใหม่ใน Linux

http://9max.icspace.net/readarticle.php?article_id=25
1. Shutdown เครื่อง
2. ต่อ HDD 4 G เข้าไปเป็นแบบ IDE กว่าจะไปหามาได้

[root@mail root]#
[root@mail root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 1.8G 1.7G 42M 98% /
none 62M 0 61M 0% /dev/shm
[root@mail root]#
[root@mail root]#
[root@mail root]# fdisk -l (ดูว่า HDD ที่ต่อไว้เห็นหรือเปล่า )

Disk /dev/sda: 255 heads, 63 sectors, 275 cylinders
Units = cylinders of 16065 * 512 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 242 1943833+ 83 Linux
/dev/sda2 243 275 265072+ 82 Linux swap
[root@mail root]#
[root@mail root]#

****** ทำไมไม่เห็น งั้น shutdown แล้ว ขยับสายใหม่อีกที

ลองอีกทีคำสั่งเดิม ....

[root@mail root]# fdisk -l

Disk /dev/sda: 255 heads, 63 sectors, 275 cylinders
Units = cylinders of 16065 * 512 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 242 1943833+ 83 Linux
/dev/sda2 243 275 265072+ 82 Linux swap

Disk /dev/hdc: 128 heads, 63 sectors, 1023 cylinders
Units = cylinders of 8064 * 512 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 * 1 1022 4120672+ b Win95 FAT32
[root@mail root]#
[root@mail root]#

ว่าแล้ว สายหลวมจริงๆ ได้ แร๊ะ.... อิ..อิ...

[root@mail root]# fdisk (ลืมคำสั่ง เพื่อความชัวร์ ให้คำสั่งนี้)

Usage: fdisk [-l] [-b SSZ] [-u] device
E.g.: fdisk /dev/hda (for the first IDE disk)
or: fdisk /dev/sdc (for the third SCSI disk)
or: fdisk /dev/eda (for the first PS/2 ESDI drive)
or: fdisk /dev/rd/c0d0 or: fdisk /dev/ida/c0d0 (for RAID devices)
...
[root@mail root]#
ตามตัวอย่างเลย....
[root@mail root]# fdisk /dev/hdc (เข้าไปจัดการ HDD ตัวที่เอามาต่อได้เลย)

Command (m for help): m (ลืมอีกแร๊ะ)
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): p (ดูซิ ว่าเป็นอะไรอยู่)

Disk /dev/hdc: 128 heads, 63 sectors, 1023 cylinders
Units = cylinders of 8064 * 512 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 * 1 1022 4120672+ b Win95 FAT32

Command (m for help): d (จัดการ ลบออกไปซะ)
Partition number (1-4): 1 (เลือกให้ถูก อันด้วยล่ะ)

Command (m for help): p (ดูอีกที ว่ายังอยู่อีก ป่ะ)

Disk /dev/hdc: 128 heads, 63 sectors, 1023 cylinders
Units = cylinders of 8064 * 512 bytes

Device Boot Start End Blocks Id System

Command (m for help): n (ถูกลบไปแร๊ะ สร้องใหม่ด้วย n )
Command action
e extended
p primary partition (1-4)
p (เลือก p)
Partition number (1-4): 1 (และ 1 )
First cylinder (1-1023, default 1): (Enter ได้เลย)
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1023, default 1023):
Using default value 1023

Command (m for help): p (ดูอีกที)

Disk /dev/hdc: 128 heads, 63 sectors, 1023 cylinders
Units = cylinders of 8064 * 512 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 1 1023 4124704+ 83 Linux

Command (m for help): w (อย่าลืมตัวนี้ด้วยไม่งั้นที่ทำมาก็ไม่มีผล)
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@mail root]# fdisk -l (ออกมาแล้วก็ชอบดู อีกแร๊ะ ได้ยัง)

Disk /dev/sda: 255 heads, 63 sectors, 275 cylinders
Units = cylinders of 16065 * 512 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 242 1943833+ 83 Linux
/dev/sda2 243 275 265072+ 82 Linux swap

Disk /dev/hdc: 128 heads, 63 sectors, 1023 cylinders
Units = cylinders of 8064 * 512 bytes

Device Boot Start End Blocks Id System
/dev/hdc1 1 1023 4124704+ 83 Linux
[root@mail root]# (ก็ได้เป็น Linux แล้วสมใจ)
[root@mail root]# mkfs -t ext3 -c /dev/hdc1 (ต้อง format ด้วยคำสั่งนี้)
mke2fs 1.27 (8-Mar-2002)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
516096 inodes, 1031176 blocks
51558 blocks (5.00%) reserved for the super user
First data block=0
32 block groups
32768 blocks per group, 32768 fragments per group
16128 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736

Checking for bad blocks (read-only test): done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done (ช่วงนี้ตัวเลขวิ่งอยู่ ครู่ใหญ่ ตามขนาด HDD ล่ะ)

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@mail root]#
[root@mail root]#
[root@mail root]# mount (mount ดูยังไม่เห็น จะเอาไว้ไหนดีน้าาา)
/dev/sda1 on / type ext3 (rw)
none on /proc type proc (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
none on /dev/shm type tmpfs (rw)
[root@mail root]# mkdir /data2 (สร้าง Folder ไว้ที่นี่ ก็แล้วกัน /data2)
[root@mail root]#
[root@mail root]# mount -t ext3 /dev/hdc1 /data2 (แล้วก็ mount มันไว้ที่นี่ล่ะ /data2)
[root@mail root]#
[root@mail root]# mount (ดู อีกแร๊ะ ได้ยัง)
/dev/sda1 on / type ext3 (rw)
none on /proc type proc (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
none on /dev/shm type tmpfs (rw)
/dev/hdc1 on /data2 type ext3 (rw) <=== มาแย้ว นี่ไง
[root@mail root]#
[root@mail root]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 1.8G 1.7G 42M 98% /
none 62M 0 61M 0% /dev/shm
/dev/hdc1 3.9G 33M 3.6G 1% /data2
[root@mail root]#

เหมือนว่าจะเรียบร้อยแต่ยังไม่เรียบร้อยดี

ถ้า Reboot ใหม่ มันจะไม่ยอม Mount ให้ สามารถทำได้ 2 วิธีเท่าที่ผมรู้
1. เพิ่มที่ /etc/fstab (ไม่แน่ใจว่า รูปแบบการเพิ่มจะใส่ยังไงไม่กล้า เคยทำ ครั้งนึ่ง แล้ว Boot ไม่ได้เลย ใครพอแนะนำได้ก็เรียนเชิญครับ)
2. ตามด้านล่าง คล้าย Autoexec.bat ของ windows คนรุ่นเก่า

[root@mail root]#
[root@mail root]# vi /root/auto-mount-new-hdd
ข้างในใส่แต่นี้
mount -t ext3 /dev/hdc1 /data2

จากนั้น ต้อง chmod เพื่อให้มัน run ได้ด้วยโดย
[root@mail root]# chmod 755 auto-mount-new-hdd

ต่อไปก็เอาไปใส่ใน /etc/rc.local หรือ จริงๆ ก็มาเขียนไว้ที่นีเลยก็ได้นะ แล้วแต่
[root@mail root]#vi /etc/rc.local
เพิ่ม
/root/auto-mount-new-hdd

ก็ลอง reboot แล้วใช้คำสั่ง mount ดูว่า มัน mount ให้เราหรืเปล่า
โชคดีครับผม

วันพุธที่ 15 ตุลาคม พ.ศ. 2551

เพิ่ม traffic ด้วย card lan 2 ใบ

http://spalinux.com/2008/09/configure_ethernet_bonding_on_fedora_linux

คอนฟิก Ethernet Bonding บน Fedora Linux
Filed under: Networking — editor @ 12:42 am
พอร์ตแลน (Ethernet) ของเครื่องเซิร์ฟเวอร์ถือว่าเป็นสิ่งสำคัญอย่างยิ่ง เพราะเป็นส่วนที่จะรับส่งข้อมูลกับเคื่องอื่นๆ ถ้าเซิร์ฟเวอร์มีแค่พอร์ตเดียวเชื่อมต่อเข้าเน็ตเวิร์ก แล้วสายที่เชื่อมต่อหลุดไป หรือไม่สามารถรองรับปริมาณการรับส่งข้อมูลได้เพียงพอ ก็อาจทำให้เกิดปัญหาการใช้งานได้

ในบทความนี้ขอแนะนำการคอนฟิก Ethernet Bonding (หรือ Teaming) เพื่อแก้ปัญหาที่อาจเกิดขึ้น โดยจะมีการจัดกลุ่มพอร์ตแลนเข้าด้วยกัน เพื่อช่วยในการรับส่งข้อมูล รูปแบบการส่งจะมีสองแบบใหญ่ๆ คือ


Active-backup พอร์ตหนึ่งจะทำหน้าพอร์ตหลักเพื่อใช้รับส่งข้อมูล (Active) แต่อีกพอร์ตหนึ่งจะสำรอง (Backup) ไว้เฉยๆ ไม่มีการรับส่งข้อมูลใดๆ ผ่านทางพอร์ตสำรอง แต่เมื่อไรที่พอร์ตหลักมีปัญหาพอร์ตนี้จะรับส่งข้อมูลแทน สำหรับ Ethernet Bonding จะเป็นคอนฟิกใน mode 1
Load Balance พอร์ตทั้งหมดในกลุ่มจะช่วยกันรับส่งข้อมูล ส่วนเทคนิคในการรับส่งจะมีหลายแบบด้วยกันแล้วแต่ mode ที่คอนฟิก
ในตัวอย่างจะเป็นการคอนฟิกบน Fedora 9 ซึ่งน่าจะประยุกต์ใช้กับ Fedora เวอร์ชั่นอื่นๆ, CentOS, RedHat หรือลีนุกซ์ตัวอื่นๆ ได้

เตรียมพอร์ตแลนที่จะคอนฟิกเป็น Ethernet Bonding
ในตัวอย่างจะใช้พอร์ตแลน eth2 และ eth3 เพื่อคอนฟิกรวมเป็น bond0

เริ่มต้นสร้างไฟล์ /etc/sysconfig/network-scripts/ifcfg-bond0 ซึ่งจะเป็นไฟล์คอนฟิกของ bond0 เป็นพอร์ต bonding (ในเครื่องหนึ่งสามารถจัดกลุ่มทำได้หลาย bonding พอร์ตที่คอนฟิกก็จะเป็น bond1, bond2 เป็นต้น) ในไฟล์จะมีคอนฟิก IP Address, Netmask เหมือนที่คอนฟิกพอร์ต ethernet ทั่วไป

ตัวอย่างคอนฟิก ifcfg-bond0

[root@fc9-x1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=10.1.0.1
NETMASK=255.255.255.0
BROADCAST=10.1.0.255
ONBOOT=yes
BOOTPROTO=none
USERCTL=noคอนฟิกพอร์ต (Physical) ให้อยู่ในกลุ่ม bond0 ตามตัวอย่าง

[root@fc9-x1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USECTL=no[root@fc9-x1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth3
DEVICE=eth3
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USECTL=noแก้ไขไฟล์ /etc/modprobe.conf เพื่อให้โหลด kernel module สำหรับการทำ bonding ตอนที่มีการโหลดคอนฟิก bond0

[root@fc9-x1 ~]# cat /etc/modprobe.conf
alias bond0 bonding
options bonding miimon=100 mode=1สามารถระบุว่าจะทำ bonding เพื่อรับส่งข้อมูลแบบไหนได้จากคอนฟิก mode ดังนี้

mode=0 (balance-rr) เป็นการส่งข้อมูลแบบ round-robin (load balancing, fault tolerance)
mode=1 (active-backup) สถานการณ์ปกติจะมีพอร์ตเดียวเท่านั้นที่ใช้รับส่งข้อมูล (fault tolerance)
mode=2 (balance-xor) เป็นการส่งข้อมูลแบบใช้ XOR เพื่อหาพอร์ตที่จะส่ง เช่นคำนวณจาก MAC Address ต้นทางปลายทางเป็นต้น (load balancing, fault tolerance)
mode=3 (broadcast)
mode=4 (802.3ad) เป็นส่งข้อมูลแบบ Link Aggregation Control Protocol (LACP) / 802.3ad
mode=5 (balance-tlb) ส่งข้อมูลแบบ Adaptive transmit load balancing
mode=6 (balance-alb) ส่งข้อมูลแบบ Adaptive load balancing
หมายเหตุ รายละเอียดเพิ่มเติมดูได้จากไฟล์ /usr/share/doc/kernel-doc-2.6.25/Documentation/networking/bonding.txt จาก kernel-doc-2.6.25-14.fc9.noarch.rpm

ในเริ่มต้นแนะนำให้ทดสอบกับ mode=1 เพื่อทดลอง active-backup ก่อน

หลังจากสร้างไฟล์คอนฟิกทั้งหมดแล้ว รีบูตเครื่องหนึ่งครั้ง เผื่อให้ bond0 ถูกโหลดขึ้นมา

ตรวจสอบสถานะของ Ethernet Bonding
เมื่อเครื่องบูตเสร็จเรียบร้อย ถ้าถูกต้องเมื่อรันคำสั่ง ifconfig จะมีพอร์ต bond0 เพิ่มขึ้นมาตามตัวอย่าง

[root@server ~]# ifconfig
bond0 Link encap:Ethernet HWaddr 00:0C:22:FF:11:55
inet addr:10.1.0.1 Bcast:10.1.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:13 errors:0 dropped:0 overruns:0 frame:0
TX packets:19 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1160 (1.1 KiB) TX bytes:1574 (1.5 KiB)...eth2 Link encap:Ethernet HWaddr 00:0C:22:FF:11:55
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:19 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1100 (1.0 KiB) TX bytes:1574 (1.5 KiB)
Interrupt:16 Base address:0x1824eth3 Link encap:Ethernet HWaddr 00:0C:22:FF:11:55
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:1 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:60 (60.0 b) TX bytes:0 (0.0 b)
Interrupt:17 Base address:0x18a4ข้อสังเกตจากคำสั่ง ifconfig

HWaddr หรือ MAC Address ของแต่ละพอร์ตที่ทำ bonding ด้วยกันจะเป็นค่าเดียวกันหมด ทั้งนี้เพื่อประโยชน์ในการทำ fail over
ในโหมด active-backup ปกติจะมีพอร์ตเดียวทำหน้าที่เป็นหลักใช้ในการรับส่งข้อมูล ซึ่งดูได้จากค่า RX, TX packets
หากต้องการรู้ว่าพอร์ตไหนถูกใช้เป็นหลัก (active) ในการส่งข้อมูล สามารถดูได้จากไฟล์ /proc/net/bonding/bond0

ตัวอย่างไฟล์ /proc/net/bonding/bond0

[root@fc9-x1 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.5 (March 21, 2008)Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth2
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0Slave Interface: eth2
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:22:ff:11:55Slave Interface: eth3
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:22:ff:11:56จากตัวอย่างพอร์ตหลักที่ถูกใช้ในโหมด (active-backup) คือพอร์ต eth2 ดูได้จาก Currently Active Slave: eth2

ทดสอบการ fail over
แนะนำว่าก่อนที่จะดึงสายแลนให้รันคำสั่ง ping ทิ้งไว้ เพื่อดูว่าเวลาที่มีการ fail over จะยังส่งข้อมูลต่อไปได้เลยไหม

ทดลองดึงสายออกจากพอร์ต eth2 แล้วตรวจสอบไฟล์ /proc/net/bonding/bond0 อีกครั้ง จะเห็นว่าพอร์ต eth3 จะถูกนำมาใช้เป็นหลักในการรับส่งข้อมูลแทน แล้วคำสั่ง ping ก็ยังคงทำงานอยู่ อาจมีสะดุดไปบ้างเล็กน้อย

[root@fc9-x1 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.5 (March 21, 2008)Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth3
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0Slave Interface: eth2
MII Status: down
Link Failure Count: 1
Permanent HW addr: 00:0c:22:ff:11:55Slave Interface: eth3
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:22:ff:11:56จากผลลัพธ์จะแสดงสถานะของ bonding ต่างๆ ดังนี้

Currently Active Slave: eth3 พอร์ตหลักที่ใช้รับส่งข้อมูลตอนนี้
Slave Interface: eth2, MII Status: down สถานะของพอร์ต eth2 down
Link Failur Count: 1 แสดงตัวเลขจำนวนครั้งที่พอร์ตมีปัญหา
สุดท้ายทดสอบด้วยการเสียบสายกลับเข้าไปที่พอร์ตที่ 2 จะเห็นว่าไม่มีการ fail over กลับมาที่พอร์ต eth2 พอร์ต eth3 จะยังคงเป็นหลักในการรับส่งข้อมูลอยู่

*******************************************************************
Debian
Ethernet bonding on Debian
โดย: โสทร รอดคงที่ srk@hospital-os.com
วันที่: วันที่เขียน 22 สิงหาคม 2548
ปรังปรุงจาก: -
ปรับปรุงล่าสุด: -
แหล่งข้อมูล:
http://glasnost.beeznest.org/articles/179
http://www.jebus.ca/Linux/ethernet_bonding.php
http://lists.debian.org/debian-user-spanish/2004/05/msg00220.html

เกริ่นนำ:

หลังจากที่ได้ทำลองทำ Ethernet Bonding บน Red Hat สำเร็จ ก็ได้ทดลองทำ บน Debian บ้าง
ปรากฏว่ามีอะไรหลายอย่างที่ไม่เหมือน Red Hat เอกสารบางอย่างที่ค้นมาทำไม่สำเร็จก็มี
ที่ทดลองทำสำเร็จ มี 2 วิธีซึ่งไม่ทราบเหมือนกันว่าอันไหนจะดีกว่ากัน ที่เขียนไม่ได้หวัง ว่าจะให้ทำ bonding ได้นะครับ
คิดว่ามาเริ่มต้นเรียนรู้ Debian กันดีกว่า

สิ่งจำเป็น:
คอมพิวเตอร์ ใส่ Lan Card 2 อัน ติดตั้ง linux Debian

ขั้นตอนการทำ

ทั้งสองวิธีมีวิธีการทำที่เหมือนกันคือ

ติดตั้ง package ifenslave-2.4 (kernel 2.4) ifenslave-2.6 (kernel 2.6)
ใครใช้ kernel ไหนอยู่ก็ติดตั้ง ตาม Kernel นั้นนะครับ
การติดตั้ง เครื่องที่จะติดตั้งต้องสามารถใช้ งาน Internet ได้

แก้ไฟล์ /etc/apt/sources.list เพื่อระบุที่ที่เราจะไปดาวน์โหลดโปรแกรม
vi /etc/apt/sources.list
เพิ่ม
deb http://ftp.au.debian.org/debian/ stable main
deb-src http://ftp.au.debian.org/debian/ stable main

deb http://security.debian.org/ stable/updates main

#ผมชอบดาวน์โหลดจากออสเตรเลีย รู้สึกว่าเร็วกว่า

apt-get update

apt-get install ifenslave-2.4
หรือ
apt-get install ifenslave-2.6

แค่นี้ก็ติดตั้งเสร็จแล้ว
การใช้งาน apt-get ดูรายละเอียดจากของพี่อุทัยนะครับ


แก้ไฟล์ /etc/modules.conf
เพิ่มบรรทัดนี้เข้าไป
alias bond0 bonding
options bonding maxbonds=4 mode=6 miimon=100 หรือ
/etc/modprobe.d/arch/i386
alias bond0 bonding
options bonding mode=1 miimon=100 downdelay=200 updelay=200

option ต่างๆ ดูได้จาก

http://www.kernel.org/pub/linux/kernel/people/marcelo/linux-2.4/Documentation/networking/bonding.txt
ยังไม่ชำนาญ Debian นะครับ ไม่สามารถอะธิบายได้ว่า
/etc/modules.conf และ /etc/modprobe.d/arch/i386 มีหน้าที่ยังไง
ดูๆ แล้วก็เหมือน ๆ กัน ใครเซียน Debian ก็บอกมาหน่อยก็แล้วกันนะครับ


วิธีการทำ Bonding 2 วิธีนี้ อันนี้เป็นตัวอย่าง
ประยุกต์ใช้งานเอาเองนะครับ

วิธีที่ 1
สร้างไฟล์ rc.local ใน /etc/init.d
cd /etc/init.d
touch rc.local
แล้วก็ทำ link
ln -s /etc/init.d/rc.local /etc/rc2.d/S99rc.local
chmod 755 rc.local

แก้ไฟล์ /etc/init.d/rc.local
อาจจะใช้ VI หรือ Text Editor ที่ ท่านถนัด
vi rc.local

โดยเพิ่มข้อคความเหล่านี้

/etc/init.d/networking stop
modprobe bonding max_bonds=2
ifconfig bond0 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 up
ifconfig eth0 up
ifconfig eth1 up
ifenslave bond0 eth0 eth1
route add default gw 192.168.1.254

วิธีที่ 2

แก้ไฟล์ /etc/network/interface


auto bond0
iface bond0 inet static
address 192.168.1.1
netmask 255.255.255.0
gateway 192.168.1.254
pre-up ifconfig eth0 up
pre-up ifconfig eth1 up
up ifenslave bond0 eth0 eth1
down ifenslave -d bond0 eth0 eth1
post-down ifconfig eth0 down
post-down ifconfig eth1 down

เสร็จแล้วครับทั้งสองวิธีนี้สามารถใช้งานได้
ตามที่ได้ทดลองมา วิธีไหนดีกว่า
หรือวิธีไหนถูกต้องที่สุดก็ไม่อาจทราบได้

วันศุกร์ที่ 5 กันยายน พ.ศ. 2551

ipset เบื้องต้น

ตามที่มีคนถามเข้ามา ด้วยส่วนตัวใช้ ipset มาบ้างพอสมควร จึงจะลองเล่าให้ฟังละกันครับ

ipset เป็นชุดโปรแกรมที่ทำงานทั้งในส่วน kernelspace และ userspace และจากที่มีการทำงานในส่วน kernelspace จึงต้องมี module สำหรับ kernel ที่เรากำลังใช้งานอยู่ด้วย ดังนั้น การใช้งาน ipset จะต้องเตรียม 2 ส่วน ดังนี้

1. เตรียม kernel

# aptitude install netfilter-extensions module-assistant

เริ่ม build module ด้วยการเตรียมความพร้อมก่อน

# m-a prepare

build จริง

# m-a a-i netfilter-extensions

หลังจากทำการ build สำเร็จ ระบบจะติดตั้ง module ให้โดยอัตโนมัติ
2. เตรียม userspace

ขั้นตอนนี้ไม่มีอะไรมาก เนื่องจากมีคนเตรียมไว้ให้แล้วใน Debian

# aptitude install ipset

ต่อไปลองทดสอบ

# iptables -m set
iptables v1.4.1.1: You must specify `--set' with proper arguments
Try `iptables -h' or 'iptables --help' for more information.

ขึ้นลักษณะนี้ น่าจะใช้ได้แล้วครับ

วิธีใช้งาน

1. สร้าง set ก่อน ในที่นี้จะแนะนำการใช้ macipmap

# ipset -N [setnam] [settype] --from [ip1] --to [ip2]
# ipset -N myset macipmap --from 192.168.0.10 --to 192.168.0.250

2. ดู set

# ipset -nL
Name: myset
Type: macipmap
References: 0
Default binding:
Header: from: 192.168.0.10 to: 192.168.0.250
Members:
Bindings:

3. เพิ่ม ip+mac เข้าไปใน set

# ipset -A myset 192.168.0.11:AA:BB:CC:DD:EE:FF
# ipset -nL
Name: myset
Type: macipmap
References: 0
Default binding:
Header: from: 192.168.0.10 to: 192.168.0.250
Members:
192.168.0.11:AA:BB:CC:DD:EE:FF
Bindings:

จะเห็นว่ามี IP และ MAC เพิ่มเข้ามาใน set แล้ว :P
4. ใช้งานร่วมกับ iptables

# iptables -A FORWARD -m set --set myset src -j ACCEPT

ผลที่ได้คือ ถ้า packet ไหนที่ผ่านเข้ามา แล้วพบใน set ก็จะยอมให้ผ่านไปได้ครับ
5. ถ้าจะลบ ip+mac ออกจาก set ก็ทำได้ง่าย คือ

# ipset -D myset 192.168.0.11:AA:BB:CC:DD:EE:FF

เท่านี้ ก็ถูกลบออกจาก set แล้วครับ

ข้อดี ของ ipset คือ "ความเร็ว" เพราะในการตรวจสอบ ทำผ่าน iptables rule แค่ที่เดียว และอีกอย่างคือ สามารถ ควบคุม rule ได้แบบ dynamic โดยที่ไม่ต้องโหลด iptables rule ใหม่ แก้ ip+mac ผ่านทาง ipset ได้โดยตรง

ipset เป็นอีกหนึ่งชุดโปรแกรม ที่ผมใช้แล้วชอบ โดยขณะนี้ได้นำมาดัดแปลงทำเป็น NAS (Network Access Service) คือทำลักษณะเดียวกับ CoovaChilli ถ้าผ่านช่วง alpha เมื่อไร จะเปิดโปรเจกต์ให้ผู้ที่สนใจ นำไปทดสอบครับ

เก็บ IP Traffic Log ด้วย ulogd (Debian Admin Style)

จริง ๆ ก็ครบกำหนดการเก็บข้อมูลการจราจร (IP Traffic) ตั้งแต่วันที่ 23 สิงหาคม 2551 (1 ปี ให้หลัง จากประกาศ) แต่ด้วยวุ่น ๆ กับหลายเรื่อง (ลูกสาวก็อายุ 3 เดือนแล้วครับ :P) ก็ลองหาการเก็บ log ในแบบที่เราคุ้นเคย และพยายามไม่ให้กระทบกับ performance ของระบบ ก็เลยได้ลงเอยกับ ulogd กับ ulogd-pcap (ตอนนี้ เป็น version 1.24 ส่วน version 2 ยังเป็นรุ่นทดสอบ ที่พยายาม build แล้ว ยังไม่สำเร็จ :P)

เริ่มเลยละกันครับ

1. ติดตั้ง packages ที่จำเป็น

# aptitude install ulogd ulogd-pcap tshark

2. เขียน script มาจัดการเกี่ยวกับ log

# vi /usr/local/bin/traffic-ulogd.sh

#!/bin/sh

ULOGD_CONF_TPL=/etc/ulogd.conf.tpl
ULOGD_CONF=/etc/ulogd.conf
LOG_DIR=/home/log/ip-traffic

PARENT_DIR=`date +%Y-%m`
PARENT_DIR="$LOG_DIR/$PARENT_DIR"

DAILY_LOG=`date +%Y-%m-%d`
DAILY_LOG="$PARENT_DIR/$DAILY_LOG.pcap"


# Copy original debian ulogd.conf file to be
# the future config template.
if [ ! -f $ULOGD_CONF_TPL ]; then
echo "Copying default $ULOGD_CONF to $ULOGD_CONF_TPL"
cp $ULOGD_CONF $ULOGD_CONF_TPL
fi

# Create the directory structure for logging
if [ ! -d $PARENT_DIR ]; then
echo "Make directory $PARENT_DIR"
mkdir -p $PARENT_DIR
fi

# Edit template config file
cat $ULOGD_CONF_TPL | \
sed -e 's:^#\(plugin="/usr/lib/ulogd/ulogd_PCAP.so"\):\1:g' | \
sed -e "s:/var/log/ulog/pcap.log:$DAILY_LOG:g" > /tmp/ulogd.conf

mv /tmp/ulogd.conf $ULOGD_CONF

# Restarting to reload config file
/etc/init.d/ulogd restart

เป็น script ที่จะคอยจัดการเกี่ยวกับ directory สำหรับจัดเก็บ ในรูปแบบ 2008-08, 2008-09 และจัดเก็บ log file ในรูปแบบ 2008-08-26.pcap,...

# chmod u+x /usr/local/bin/traffic-ulogd.sh
# /usr/local/bin/traffic-ulogd.sh

สั่งให้ script จัด config ให้ และเริ่มรอการ log
3. กำหนด iptables rule ให้ทำการ log

# iptables -I FORWARD -j ULOG --ulog-cprange 100 --ulog-qthreshold 50

4. ลองดูคร่าว ๆ ว่ามี packet ผ่านเข้า log ไหม

# iptables -nvL FORWARD
Chain FORWARD (policy ACCEPT 211M packets, 106G bytes)
pkts bytes target prot opt in out source destination
14M 7502M ULOG all -- * * 0.0.0.0/0 0.0.0.0/0 ULOG copy_range 100 nlgroup 1 queue_threshold 50

จะเห็นว่ามี Packet วิ่งเข้า rule นี้ด้วย :P
5. ดูแฟ้มที่จัดเก็บ log (ผมเก็บไว้ที่ /home เพราะแบ่งพื้นที่ไว้เยอะที่นี่)

# cd /home/log/ip-traffic/2008-08
# ls
2008-08-26.pcap
# file 2008-08-26.pcap
2008-08-26.pcap: tcpdump capture file (little-endian) - version 2.4 (raw IP, capture length 65535)

อ้า... ใช่แล้วครับ เป็น ลักษณะ tcpdump capture file :P (binary ด้วย ... เห็นเขาบอกให้เก็บในรูปแบบที่น่าเชื่อถือได้ ไม่รู้ตัวนี้น่าเชื่อถือพอหรือเปล่า :P)
6. ลองดู log ข้างในแฟ้มนี้ดู

# tshark -r 2008-08-26.pcap -tad -c 5
Running as user "root" and group "root". This could be dangerous.
1 2008-08-26 03:31:34.464265 172.30.10.18 -> 80.252.110.146 TCP acter > kar2ouche [SYN] Seq=0 Win=16384 Len=0 MSS=1452
2 2008-08-26 03:31:34.537428 172.30.10.102 -> 64.71.134.246 TCP ft-role > https [SYN] Seq=0 Win=16384 Len=0 MSS=1452
3 2008-08-26 03:31:34.565095 172.30.10.18 -> 66.199.250.170 TCP appiq-mgmt > manyone-xml [SYN] Seq=0 Win=16384 Len=0 MSS=1452
4 2008-08-26 03:31:34.568396 172.30.10.18 -> 219.239.90.172 TCP rfa > 28221 [SYN] Seq=0 Win=16384 Len=0 MSS=1452
5 2008-08-26 03:31:34.571477 172.30.10.18 -> 72.51.37.237 TCP cxws > ospf-lite [SYN] Seq=0 Win=16384 Len=0 MSS=145

ขอดูแค่ 5 packets ก่อนละกัน

-r 2008-08-26.pcap (read from file)
-tad (Absolute date)
-c 5 (5 packets count and exit)

7. เป็นอันว่า เก็บได้ ก็น่าจะเรียบร้อย ตอนนี้ก็เหลือให้ script เราทำงานเป็นช่วง ๆ เพื่อจัดการเรื่องชื่อไฟล์ให้ถูกต้อง

# vi /etc/cron.d/traffic-log

0 */1 * * * root /usr/local/bin/traffic-ulogd.sh >/dev/null 2>&1

# /etc/init.d/cron restart

เป็นการกำหนดให้ระบบ run script นี้ ทุก ๆ ชั่วโมง (กันพลาด เดี๋ยว log ในแฟ้ม จะไม่ตรงกับวันเวลาจริง แต่ถ้าเครื่องเปิดตลอดเวลาไม่น่ามีปัญหา) เท่านี้ก็น่าจะเรียบร้อยแล้วครับผม ตอนนี้ก็เหลือดูผลว่าไฟล์ใหญ่แค่ไหน อาจจะต้องมีการมาทำ archive อีกที เดี๋ยวค่อยมาว่ากันต่อคราวหน้าละกันครับ

How to install Cacti in Debian Etch

http://www.cahilig.org/how-install-cacti-debian-etch

Cacti has a nice user interface. It is easy to install and easy to setup, don't need too much customization.
Downloading Cacti

You can download the newest version of Cacti from its website http://cacti.net/.
wget http://www.cacti.net/downloads/cacti-0.8.7b.tar.gz
Installing Cacti

Install apache webserver with php support, mysql database server, snmp, some php modules and rrdtool.
apt-get install apache2 libapache2-mod-php5 php5 php5-cli php5-mysql php5-gd php5-snmp mysql-client mysql-server libmysqlclient15-dev snmp snmpd rrdtool

Add a user account for cacti.
groupadd cacti
useradd -g cacti cacti

Untar the cacti source file and move to /var/www.
tar -zxvf cacti-0.8.7b.tar.gz
mv cacti-0.8.7b /var/www

Login to your mysql database
mysql -u root

Create a password for your mysql root account and create cacti database and user.
SET PASSWORD FOR root@localhost = PASSWORD ('your_password_here');
CREATE DATABASE cacti;
GRANT ALL ON cacti.* TO cacti_user@localhost IDENTIFIED BY 'your_password';
quit

and import the database tables
cd /var/www/cacti-0.8.7b/
mysql -u root -p cacti < cacti.sql

Change the owner of rra and log directory to your cacti account.
chown -R cacti rra/ log/

Edit the config.php file located in include directory.
vi include/config.php

Enter your mysql host, user, password and database name.

/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "your_password";
$database_port = "3306";

As a cacti user
su - cacti
crontab -e

add this line to your crontab

*/5 * * * * /usr/bin/php /var/www/cacti-0.8.7b/poller.php > /dev/null 2>&1

Open up your web browser and point to http://localhost/cacti-0.8.7b/, this will start cacti installation. Click Next then select NEW INSTALL and accept the default installation value. If you don't see any errors, click Finish to install.

Login to cacti, the default username and password is admin. After login, it will prompt you change your password for security reasons.
Checking

Check your syslog if the cacti's poller is running every 5 minutes.
If you will see something like this in your syslog, your cacti should work perfectly.

Jul 5 06:50:01 server1 /USR/SBIN/CRON[6543]: (cacti) CMD (/usr/bin/php /var/www/cacti/poller.php > /dev/null 2>&1)

You can start monitoring your servers, routers and other networking devices with cacti