<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SpaLinux.com &#187; Filesystem</title>
	<atom:link href="http://spalinux.com/category/filesystem/feed" rel="self" type="application/rss+xml" />
	<link>http://spalinux.com</link>
	<description>Resources for Relaxing Linux System Administrators</description>
	<lastBuildDate>Mon, 26 Jul 2010 09:51:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>เพิ่มดิสก์ใหม่บน Solaris 10</title>
		<link>http://spalinux.com/2010/03/add_new_disk_on_solaris_10</link>
		<comments>http://spalinux.com/2010/03/add_new_disk_on_solaris_10#comments</comments>
		<pubDate>Sun, 07 Mar 2010 16:02:40 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Disk]]></category>
		<category><![CDATA[Filesystem]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[solaris 10]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1100</guid>
		<description><![CDATA[เช่นเดียวกับระบบปฏิบัติการ OS อื่นๆ เมื่อมีการเพิ่มดิสก์ก้อนใหม่เข้าไปในเครื่องที่ติดตั้ง Solaris 10 ต้องมีกระบวนการ หรือต้องรันคำสั่งก่อนที่จะเริ่มใช้ดิสก์ก้อนใหม่ได้ ในบทความนี้ทดสอบการเพิ่มดิสก์ก้อนใหม่ 1 ก้อน บน Solaris 10 (x86) ใช้คำสั่ง format เพื่อดูว่า Solaris มองเห็นดิสก์อะไรบ้าง # format Searching for disks...done AVAILABLE DISK SELECTIONS:        0. c1t0d0 &#60;DEFAULT cyl 4866 alt 2 hd 255 sec 63&#62;           /pci@0,0/pci1000,30@10/sd@0,0        1. c1t1d0 &#60;DEFAULT cyl 4867 alt 2 hd 255 sec 63&#62;           [...]]]></description>
			<content:encoded><![CDATA[<p>เช่นเดียวกับระบบปฏิบัติการ OS อื่นๆ เมื่อมีการเพิ่มดิสก์ก้อนใหม่เข้าไปในเครื่องที่ติดตั้ง Solaris 10 ต้องมีกระบวนการ หรือต้องรันคำสั่งก่อนที่จะเริ่มใช้ดิสก์ก้อนใหม่ได้</p>
<p><span id="more-1100"></span></p>
<p>ในบทความนี้ทดสอบการเพิ่มดิสก์ก้อนใหม่ 1 ก้อน บน Solaris 10 (x86)</p>
<p>ใช้คำสั่ง format เพื่อดูว่า Solaris มองเห็นดิสก์อะไรบ้าง</p>
<pre># <strong>format</strong>
Searching for disks...done</pre>
<pre>AVAILABLE DISK SELECTIONS:
       0. c1t0d0 &lt;DEFAULT cyl 4866 alt 2 hd 255 sec 63&gt;
          <a>/pci@0,0/pci1000,30@10/sd@0,0</a>
       <span style="color: #0000ff;"><strong>1. c1t1d0</strong></span> &lt;DEFAULT cyl 4867 alt 2 hd 255 sec 63&gt;
          <a>/pci@0,0/pci1000,30@10/sd@1,0</a>
Specify disk (enter its number):</pre>
<p>ดิสก์ก้อนใหม่ที่เพิ่มเข้ามาคือดิสก์หมายเลข 1 &#8220;c1t1d0&#8243;</p>
<p>พิมพ์หมายเลขของดิสก์แล้วกด [Enter] เพื่อเข้าสู่โหมดจัดการของดิสก์ก้อนที่ระบุ</p>
<pre>Specify disk (enter its number): <strong>1</strong>
selecting c1t1d0
[disk formatted]</pre>
<pre>FORMAT MENU:
        disk       - select a disk
        type       - select (define) a disk type
        partition  - select (define) a partition table
        current    - describe the current disk
        format     - format and analyze the disk
        fdisk      - run the fdisk program
        repair     - repair a defective sector
        label      - write label to the disk
        analyze    - surface analysis
        defect     - defect list management
        backup     - search for backup labels
        verify     - read and display labels
        save       - save new disk/partition definitions
        inquiry    - show vendor, product and revision
        volname    - set 8-character volume name
        !&lt;cmd&gt;     - execute &lt;cmd&gt;, then return
        quit</pre>
<p>พิมพ์คำสั่ง partition เพื่อเข้าสู่โหมดการแบ่ง partition</p>
<pre>format&gt; <strong>partition</strong>
<span style="color: #ff0000;">WARNING - This disk may be in use by an application that has
          modified the fdisk table. Ensure that this disk is
          not currently in use before proceeding to use fdisk.</span></pre>
<p>หากเจอข้อความ WARNING แบบด้านบน ให้พิมพ์คำสั่ง fdisk เพื่อแก้ไข</p>
<pre>format&gt; <strong>fdisk</strong>
No fdisk table exists. The default partition for the disk is:</pre>
<pre>  a 100% "SOLARIS System" partition</pre>
<pre>Type "y" to accept the default partition,  otherwise type "n" to edit the
 partition table.
<strong>y</strong>
format&gt;</pre>
<p>พิมพ์คำสั่ง partition อีกครั้ง</p>
<pre>format&gt; <strong>partition</strong></pre>
<pre>PARTITION MENU:
        0      - change `0' partition
        1      - change `1' partition
        2      - change `2' partition
        3      - change `3' partition
        4      - change `4' partition
        5      - change `5' partition
        6      - change `6' partition
        7      - change `7' partition
        select - select a predefined table
        modify - modify a predefined partition table
        name   - name the current table
        print  - display the current table
        label  - write partition map and label to the disk
        !&lt;cmd&gt; - execute &lt;cmd&gt;, then return
        quit
partition&gt;</pre>
<p>พิมพ์คำสั่ง print เพื่อแสดงการแบ่ง partition</p>
<pre>partition&gt; <strong>print</strong>
Current partition table (original):
Total disk cylinders available: 4866 + 2 (reserved cylinders)</pre>
<pre>Part      Tag    Flag     Cylinders        Size            Blocks
<span style="color: #0000ff;">  0 unassigned    wm       0               0         (0/0/0)           0
</span>  1 unassigned    wm       0               0         (0/0/0)           0
  2     backup    wu       0 - 4865       37.28GB    (4866/0/0) 78172290
  3 unassigned    wm       0               0         (0/0/0)           0
  4 unassigned    wm       0               0         (0/0/0)           0
  5 unassigned    wm       0               0         (0/0/0)           0
  6 unassigned    wm       0               0         (0/0/0)           0
  7 unassigned    wm       0               0         (0/0/0)           0
  8       boot    wu       0 -    0        7.84MB    (1/0/0)       16065
  9 unassigned    wm       0               0         (0/0/0)           0</pre>
<pre>partition&gt;</pre>
<p>เริ่มต้น ทดลองสร้าง partition 0 มีขนาด 10 GB</p>
<pre>partition&gt; <strong>0</strong>
Part      Tag    Flag     Cylinders        Size            Blocks
  0 unassigned    wm       0               0         (0/0/0)           0</pre>
<pre>Enter partition id tag[unassigned]:
Enter partition permission flags[wm]:
Enter new starting cyl[0]:
Enter partition size[0b, 0c, 0e, 0.00mb, 0.00gb]: <strong>10gb</strong></pre>
<p>ใช้คำสั่ง print เพื่อแสดง partition</p>
<pre>partition&gt; <strong>print</strong>
Current partition table (unnamed):
Total disk cylinders available: 4866 + 2 (reserved cylinders)</pre>
<pre>Part      Tag    Flag     Cylinders        Size            Blocks
<span style="color: #0000ff;">  0 unassigned    wm       0 - 1305       10.00GB    (1306/0/0) 20980890
</span>  1 unassigned    wm       0               0         (0/0/0)           0
  2     backup    wu       0 - 4865       37.28GB    (4866/0/0) 78172290
  3 unassigned    wm       0               0         (0/0/0)           0
  4 unassigned    wm       0               0         (0/0/0)           0
  5 unassigned    wm       0               0         (0/0/0)           0
  6 unassigned    wm       0               0         (0/0/0)           0
  7 unassigned    wm       0               0         (0/0/0)           0
  8       boot    wu       0 -    0        7.84MB    (1/0/0)       16065
  9 unassigned    wm       0               0         (0/0/0)           0</pre>
<p>หลังจากแก้ไข partition พิมพ์คำสั่ง label เพื่อบันทึกข้อมูลลงดิสก์</p>
<pre>partition&gt; <strong>label</strong>
Ready to label disk, continue? <strong>y</strong></pre>
<pre>partition&gt; <strong>^D</strong></pre>
<p>กดปุ่ม [Ctrl]+[D] เพื่อออกจากคำสั่ง format</p>
<p>ใช้คำสั่ง newfs เพื่อสร้าง filesystem บน partition ที่เพิ่งสร้างขึ้น</p>
<p>หมายเหตุ ชื่อไฟล์ device ของดิสก์ c1t1d0 &#8211; partition 0 คือ /dev/rdsk/c1t1d0s0</p>
<pre># <strong>newfs /dev/rdsk/c1t1d0s0
</strong>newfs: construct a new file system /dev/rdsk/c1t1d0s0: (y/n)? y
Warning: 870 sector(s) in last cylinder unallocated
/dev/rdsk/c1t1d0s0:     20980890 sectors in 3415 cylinders of 48 tracks, 128 sectors
        10244.6MB in 214 cyl groups (16 c/g, 48.00MB/g, 5824 i/g)
super-block backups (for fsck -F ufs -o b=#) at:
 32, 98464, 196896, 295328, 393760, 492192, 590624, 689056, 787488, 885920,
 20055584, 20154016, 20252448, 20350880, 20449312, 20547744, 20646176,
 20744608, 20843040, 20941472</pre>
<p>แนะนำให้ใช้คำสั่ง fsck เพื่อตรวจสอบความถูกต้องของ filesystem ที่สร้างขึ้น ต้องไม่มีข้อความ error ใดๆ</p>
<pre># <strong>fsck -y /dev/rdsk/c1t1d0s0
</strong>** /dev/rdsk/c1t1d0s0
** Last Mounted on
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3a - Check Connectivity
** Phase 3b - Verify Shadows/ACLs
** Phase 4 - Check Reference Counts
** Phase 5 - Check Cylinder Groups
2 files, 9 used, 10331200 free (16 frags, 1291398 blocks, 0.0% fragmentation)</pre>
<p>สร้าง mount point สำหรับ partition ใหม่</p>
<pre># <strong>mkdir /mnt/new-disk0
</strong># <strong>mount /dev/rdsk/c1t1d0s0 /mnt/new-disk0
</strong><span style="color: #ff0000;">mount: /dev/rdsk/c1t1d0s0 not a block device</span></pre>
<p>สำหรับ Solaris เวลาใช้คำสั่ง newfs หรือ fsck ชื่อ device ที่ระบุคือ /dev/rdsk/&#8230; แต่เวลาใช้คำสั่ง mount ต้องระบุชื่อ device เป็น /dev/dsk/&#8230;</p>
<pre># <strong>mount /dev/dsk/c1t1d0s0 /mnt/new-disk0</strong></pre>
<p>ใช้คำสั่ง df เพื่อตรวจสอบ mount point</p>
<pre># <strong>df -h
</strong>Filesystem             size   used  avail capacity  Mounted on
/dev/dsk/c1t0d0s0       34G   3.7G    30G    11%    /
/devices                 0K     0K     0K     0%    /devices
ctfs                     0K     0K     0K     0%    /system/contract
proc                     0K     0K     0K     0%    /proc
mnttab                   0K     0K     0K     0%    /etc/mnttab
swap                   1.6G   932K   1.6G     1%    /etc/svc/volatile
objfs                    0K     0K     0K     0%    /system/object
sharefs                  0K     0K     0K     0%    /etc/dfs/sharetab
/usr/lib/libc/libc_hwcap1.so.1
                        34G   3.7G    30G    11%    /lib/libc.so.1
fd                       0K     0K     0K     0%    /dev/fd
swap                   1.6G     8K   1.6G     1%    /tmp
swap                   1.6G    20K   1.6G     1%    /var/run
/dev/dsk/c1t0d0s7      1.9G   210M   1.6G    12%    /export/home
<span style="color: #0000ff;">/dev/dsk/c1t1d0s0      9.9G    10M   9.7G     1%    /mnt/new-disk0</span></pre>
<p>หากใช้งาน partition ใหม่ได้ถูกต้องเรียบร้อยแล้ว ต้องเพิ่มคอนฟิกเข้าไปในไฟล์ /etc/vfstab เพื่อให้เวลาบู๊ตเครื่องใหม่ มีการ mount partition ใหม่นี้โดยอัตโมมัติ</p>
<pre># <strong>cat /etc/vfstab
</strong>#device         device          mount           FS      fsck    mount   mount
#to mount       to fsck         point           type    pass    at boot options
#
fd      -       /dev/fd fd      -       no      -
/proc   -       /proc   proc    -       no      -
/dev/dsk/c1t0d0s1       -       -       swap    -       no      -
/dev/dsk/c1t0d0s0       /dev/rdsk/c1t0d0s0      /       ufs     1       no      -
/dev/dsk/c1t0d0s7       /dev/rdsk/c1t0d0s7      /export/home    ufs     2       yes     -
/devices        -       /devices        devfs   -       no      -
sharefs -       /etc/dfs/sharetab       sharefs -       no      -
ctfs    -       /system/contract        ctfs    -       no      -
objfs   -       /system/object  objfs   -       no      -
swap    -       /tmp    tmpfs   -       yes     -
# new disk
<span style="color: #0000ff;">/dev/dsk/c1t1d0s0       /dev/rdsk/c1t1d0s0      /mnt/new-disk0  ufs     2       yes     -</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2010/03/add_new_disk_on_solaris_10/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>การใช้งาน DRBD เบื้องต้น</title>
		<link>http://spalinux.com/2010/02/basic_using_drbd</link>
		<comments>http://spalinux.com/2010/02/basic_using_drbd#comments</comments>
		<pubDate>Sat, 06 Feb 2010 11:09:40 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Backup]]></category>
		<category><![CDATA[Cluster]]></category>
		<category><![CDATA[Disk]]></category>
		<category><![CDATA[Filesystem]]></category>
		<category><![CDATA[Kernel]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[drbd]]></category>
		<category><![CDATA[linux ha]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1072</guid>
		<description><![CDATA[จากบทความ ติดตั้งและคอนฟิก DRBD  เราได้คอนฟิกเป็นแบบ Single-primary mode คือ ณ เวลาใดเวลาหนึ่ง มีเครื่องเดียวเท่านั้นที่สามารถ อ่าน เขียน ข้อมูลได้ ดังนั้นขณะที่เครื่องที่ 1 (centos54-a) ทำหน้าที่เป็น primary ของดิสก์ drbd0 อยู่  เครื่องที่ 2 (centos54-b) จะไม่สามารถ mount ดิสก์ drbd0 นี้ขึ้นมาใช้งานได้ ในบทความนี้จะแสดงการทดสอบใช้คำสั่งเพื่อเปลี่ยนโหมด Primary, Secondary ระหว่างเครื่องทั้งสอง ตรวจสอบสถานะบนเครื่อง centos54-a [root@centos54-a ~]# service drbd status drbd driver loaded OK; device status: version: 8.3.2 (api:88/proto:86-90) GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 [...]]]></description>
			<content:encoded><![CDATA[<p>จากบทความ <a href="http://spalinux.com/2010/02/install_and_configure_drbd">ติดตั้งและคอนฟิก DRBD </a> เราได้คอนฟิกเป็นแบบ Single-primary mode คือ ณ เวลาใดเวลาหนึ่ง มีเครื่องเดียวเท่านั้นที่สามารถ อ่าน เขียน ข้อมูลได้</p>
<p>ดังนั้นขณะที่เครื่องที่ 1 (centos54-a) ทำหน้าที่เป็น primary ของดิสก์ drbd0 อยู่  เครื่องที่ 2 (centos54-b) จะไม่สามารถ mount ดิสก์ drbd0 นี้ขึ้นมาใช้งานได้</p>
<p>ในบทความนี้จะแสดงการทดสอบใช้คำสั่งเพื่อเปลี่ยนโหมด Primary, Secondary ระหว่างเครื่องทั้งสอง</p>
<p>ตรวจสอบสถานะบนเครื่อง centos54-a</p>
<pre>[root@centos54-a ~]# <strong>service drbd status
</strong>drbd driver loaded OK; device status:
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:07:55
m:res  cs         ro                 ds                 p  mounted  fstype
0:r0   Connected  Primary/Secondary  UpToDate/UpToDate  C  /export  ext3</pre>
<pre>[root@centos54-a ~]# df -h /export
Filesystem            Size  Used Avail Use% Mounted on
/dev/drbd0            950M   18M  885M   2% /export</pre>
<p>ทดสอบ mount ดิสก์บนเครื่อง centos54-b</p>
<pre>[root@centos54-b ~]# <strong>service drbd status
</strong>drbd driver loaded OK; device status:
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:07:55
m:res  cs         ro                 ds                 p  mounted  fstype
0:r0   Connected  Secondary/Primary  UpToDate/UpToDate  C</pre>
<pre>[root@centos54-b ~]# mount /dev/drbd0 /export
mount: block device /dev/drbd0 is write-protected, mounting read-only
mount: Wrong medium type</pre>
<p>ในกรณีที่ต้องการเปลี่ยนให้เครื่องที่ 2 (centos54-b) ทำหน้าที่เป็น primary  เช่นในกรณีที่ต้องการซ่อมบำรุงเครื่องที่ 1 สามารถทำได้ดังนี้</p>
<p>บนเครื่องที่ 1 ปิดเซอร์วิส DRBD</p>
<pre>[root@centos54-a ~]# <strong>service drbd stop
</strong>Stopping all DRBD resources:
.
[root@centos54-a ~]# <strong>service drbd status
</strong>drbd not loaded</pre>
<p>ตรวจสอบสถานะบนเครื่องที่ 2 หลังจากปิดเซอร์วิสบนเครื่องที่ 1</p>
<pre>[root@centos54-b ~]# <strong>service drbd status
</strong>drbd driver loaded OK; device status:
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:07:55
m:res  cs            ro                 ds                 p  mounted  fstype
0:r0   WFConnection  <strong><span style="color: #0000ff;">Secondary</span></strong>/Unknown  UpToDate/DUnknown  C</pre>
<p>แม้เครื่อง Primary ปิดไปแล้ว บนเครื่องที่ 2 ที่ยังอยู่ในโหมด Secondary ก็ยัง mount ดิสก์ ไม่ได้</p>
<pre>[root@centos54-b ~]# <strong>mount /dev/drbd0 /export
</strong>mount: block device /dev/drbd0 is write-protected, mounting read-only
mount: Wrong medium type</pre>
<p>ต้องเปลี่ยนสถานะบนเครื่องที่ 2 ให้เป็น primary ด้วยคำสั่ง drbdadm primary</p>
<pre>[root@centos54-b ~]# <strong>drbdadm primary all</strong></pre>
<p>ตรวจสอบสถานะบนเครื่องที่ 2</p>
<pre>[root@centos54-b ~]# <strong>service drbd status
</strong>drbd driver loaded OK; device status:
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:07:55
m:res  cs            ro               ds                 p  mounted  fstype
0:r0   WFConnection  <span style="color: #0000ff;"><strong>Primary</strong></span>/Unknown  UpToDate/DUnknown  C</pre>
<p>เมื่ออยู่ในโหมด primary แล้ว ก็สามารถ mount ดิสก์ขึ้นมาใช้งานได้</p>
<pre>[root@centos54-b ~]# <strong>mount /dev/drbd0 /export
</strong>[root@centos54-b ~]# <strong>df -h /export
</strong>Filesystem            Size  Used Avail Use% Mounted on
/dev/drbd0            950M   18M  885M   2% /export</pre>
<p>ทดลองสร้างไฟล์ในดิสก์ drbd0</p>
<pre>[root@centos54-b ~]# <strong>cd /export/
</strong>[root@centos54-b export]# <strong>ls
</strong>lost+found
[root@centos54-b export]# <strong>echo "hello world from node 2" &gt; test-file-on-node-2.txt
</strong>[root@centos54-b export]# <strong>ls -l
</strong>total 20
drwx------ 2 root root 16384 Feb  6 15:46 lost+found
-rw-r--r-- 1 root root    24 Feb  6 17:17 <span style="color: #0000ff;"><strong>test-file-on-node-2.txt</strong></span></pre>
<p>รันเซอร์วิส DRBD บนเครื่องที่ 1 ขึ้นมาอีกครั้ง ตอนนี้เครื่องที่ 1 จะทำหน้าที่เป็น Secondary และจะทำการ replicate ข้อมูลมาจากเครื่องที่ 2 (Primary) โดยอัตโนมัติ</p>
<pre>[root@centos54-a ~]# <strong>service drbd start
</strong>Starting DRBD resources: [ d(r0) s(r0) n(r0) ].</pre>
<pre>[root@centos54-a ~]# <strong>service drbd status
</strong>drbd driver loaded OK; device status:
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:07:55
m:res  cs         ro                 ds                 p  mounted  fstype
0:r0   Connected  <strong><span style="color: #0000ff;">Secondary</span></strong>/Primary  UpToDate/UpToDate  C</pre>
<p>บนเครื่องที่ 2 เปลี่ยนให้เป็นโหมด Secondary</p>
<pre>[root@centos54-b ~]# <strong>drbdadm secondary all
</strong><span style="color: #ff0000;">0: State change failed: (-12) Device is held open by someone</span>
Command 'drbdsetup 0 secondary' terminated with exit code 11</pre>
<p>หากมีการเรียกใช้ดิสก์ drbd อยู่ จะไม่สามารถเปลี่ยนโหมดจาก Primary ไปเป็น Secondary ได้ ต้อง umount ดิสก์ออกไปก่อนถึงจะเปลี่ยนโหมดได้</p>
<pre>[root@centos54-b ~]# <strong>umount /export
</strong>[root@centos54-b ~]# <strong>drbdadm secondary all</strong></pre>
<p>ตรวจสอบสถานะบนเครื่องที่ 2</p>
<pre>[root@centos54-b ~]# <strong>service drbd status
</strong>drbd driver loaded OK; device status:
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:07:55
m:res  cs         ro                   ds                 p  mounted  fstype
0:r0   Connected  <span style="color: #0000ff;"><strong>Secondary</strong></span>/Secondary  UpToDate/UpToDate  C</pre>
<p>เปลี่ยนโหมดบนเครื่องที่ 1 ให้เป็น Primary เพื่อเรียกใช้ดิสก์ได้</p>
<pre>[root@centos54-a ~]# <strong>drbdadm primary all
</strong>[root@centos54-a ~]# <strong>service drbd status
</strong>drbd driver loaded OK; device status:
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:07:55
m:res  cs         ro                 ds                 p  mounted  fstype
0:r0   Connected  <strong><span style="color: #0000ff;">Primary</span></strong>/Secondary  UpToDate/UpToDate  C</pre>
<p>mount ดิสก์ และตรวจสอบไฟล์ที่อยู่ใน drbd0 จะเห็นไฟล์ที่สร้างจากเครื่องที่ 2</p>
<pre>[root@centos54-a ~]# <strong>mount /dev/drbd0 /export
</strong>[root@centos54-a ~]# <strong>cd /export/
</strong>[root@centos54-a export]# ls -l
total 20
drwx------ 2 root root 16384 Feb  6 15:46 lost+found
-rw-r--r-- 1 root root    24 Feb  6 17:17 <strong><span style="color: #0000ff;">test-file-on-node-2.txt
</span></strong>[root@centos54-a export]# <strong>cat test-file-on-node-2.txt
</strong>hello world from node 2</pre>
<h4>ตรวจสอบไฟล์ /var/log/messages</h4>
<p>เมื่อมีปัญหาเกี่ยวกับการใช้ DBRD นอกจากการใช้คำสั่ง service เพื่อตรวจสอบสถานะแล้ว ไฟล์ /var/log/messages จะแสดงการเปลี่ยนแปลงทั้งหมดของ DRBD ที่เกิดขึ้น ซึ่งสามารถนำมาใช้ช่วยในการแก้ปัญหาได้</p>
<p>ตัวอย่างข้อความในไฟล์ /var/log/messages ที่เกิดขึ้น เมื่อมีการเปลี่ยนโหมด</p>
<pre>[root@centos54-a ~]# <strong>tail /var/log/messages
</strong>...
Feb  6 17:19:38 centos54-a kernel: block drbd0: peer( Primary -&gt; Secondary )
Feb  6 17:21:04 centos54-a kernel: block drbd0: role( Secondary -&gt; Primary )
...</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2010/02/install_and_configure_drbd">ติดตั้งและคอนฟิก DRBD</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2010/02/basic_using_drbd/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ติดตั้งและคอนฟิก DRBD</title>
		<link>http://spalinux.com/2010/02/install_and_configure_drbd</link>
		<comments>http://spalinux.com/2010/02/install_and_configure_drbd#comments</comments>
		<pubDate>Sat, 06 Feb 2010 09:40:46 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Backup]]></category>
		<category><![CDATA[Cluster]]></category>
		<category><![CDATA[Disk]]></category>
		<category><![CDATA[Filesystem]]></category>
		<category><![CDATA[Kernel]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[drbd]]></category>
		<category><![CDATA[linux ha]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1068</guid>
		<description><![CDATA[DRBD (Distributed Replicated Block Device) เป็นโปรแกรมเพื่อใช้ในการ replicate ข้อมูลดิสก์ที่อยู่คนละเครื่องกัน ผ่านทางเน็ตเวิร์ก โดยจะทำในระดับ block ของดิสก์ เมื่อมีการเปลี่ยนแปลงข้อมูลที่อยูในดิสก์เครื่องหนึ่ง (primary) การเปลี่ยนแปลงนั้นจะถูก replicate ไปยังอีกเครื่อง (secondary) โดยอัตโนมัติ DRBD ประกอบด้วยสองส่วนคือ 1. Kernel module &#8211; DRBD ทำหน้าที่ใน kernel โดยจะสร้าง virtual block device คั่นกลางระหว่าง physical disk กับ filesystem ที่สร้างอยู่ ไม่ว่าจะเป็น ext3, ext4, xfs 2. User space administration tools &#8211; เป็นโปรแกรมที่ช่วยในการจัดการ DRBD ได้ง่ายขึ้น หลักๆ จะเป็น drbdadm ในบทความนี้จะแสดงการติดตั้งโปรแกรม [...]]]></description>
			<content:encoded><![CDATA[<p>DRBD (Distributed Replicated Block Device) เป็นโปรแกรมเพื่อใช้ในการ replicate ข้อมูลดิสก์ที่อยู่คนละเครื่องกัน ผ่านทางเน็ตเวิร์ก โดยจะทำในระดับ block ของดิสก์</p>
<p>เมื่อมีการเปลี่ยนแปลงข้อมูลที่อยูในดิสก์เครื่องหนึ่ง (primary) การเปลี่ยนแปลงนั้นจะถูก replicate ไปยังอีกเครื่อง (secondary) โดยอัตโนมัติ</p>
<p>DRBD ประกอบด้วยสองส่วนคือ</p>
<p>1. Kernel module &#8211; DRBD ทำหน้าที่ใน kernel โดยจะสร้าง virtual block device คั่นกลางระหว่าง physical disk กับ filesystem ที่สร้างอยู่ ไม่ว่าจะเป็น ext3, ext4, xfs<br />
2. User space administration tools &#8211; เป็นโปรแกรมที่ช่วยในการจัดการ DRBD ได้ง่ายขึ้น หลักๆ จะเป็น drbdadm</p>
<p>ในบทความนี้จะแสดงการติดตั้งโปรแกรม DRBD และคอนฟิกเป็นแบบ Single-primary mode คือ ณ เวลาใดเวลาหนึ่ง มีเครื่องเดียวเท่านั้นที่สามารถ อ่าน เขียน ข้อมูลได้</p>
<p><span style="color: #ff0000;"><strong>คำเตือน ติดตั้งและคอนฟิก DRBD บนเครื่องทดสอบให้เข้าใจก่อน เพราะบางคำสั่งอาจกระทบข้อมูลดิสก์หรือ partition ที่มีอยู่ในเครื่องได้ ทำให้ข้อมูลเสียหายได้</strong></span></p>
<p><span id="more-1068"></span></p>
<h4>ระบบสำหรับการทดสอบ</h4>
<p>ในที่นี้จะติดตั้ง CentOS 5.4 พร้อมคอนฟิกให้สองเครื่องติดต่อ ping กันได้ และปิดคุณสมบัติ firewall ทั้งหมด</p>
<p><strong>เครื่องที่ 1</strong></p>
<ul>
<li>Hostname:   centos54-a.spalinux.com</li>
<li>IP Address: 10.3.3.51</li>
</ul>
<p><strong>เครื่องที่ 2</strong></p>
<ul>
<li>Hostname:   centos54-b.spalinux.com</li>
<li>IP Address: 10.3.3.52</li>
</ul>
<p>แก้ไขไฟล์ /etc/hosts เพื่อให้ทั้งสองเครื่องอ้างอิงจากชื่อเครื่องได้</p>
<p>ตัวอย่างคอนฟิกของเครื่องที่ 1</p>
<pre>[root@centos54-a ~]# <strong>hostname</strong>
centos54-a.spalinux.com</pre>
<pre>[root@centos54-a ~]# <strong>cat /etc/hosts
</strong># Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1       localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6</pre>
<pre>10.3.3.51       centos54-a centos54-a.spalinux.com
10.3.3.52       centos54-b centos54-b.spalinux.com</pre>
<p>ตัวอย่างคอนฟิกของเครื่องที่ 2</p>
<pre>[root@centos54-b ~]# <strong>hostname</strong>
centos54-b.spalinux.com</pre>
<pre>[root@centos54-b ~]# <strong>cat /etc/hosts
</strong># Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1       localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6</pre>
<pre>10.3.3.51       centos54-a centos54-a.spalinux.com
10.3.3.52       centos54-b centos54-b.spalinux.com</pre>
<p>ทั้งสองเครื่อง ต้องสร้าง partition สำหรับใช้เป็นดิสก์ DRBD โดยไม่ต้องสร้าง filesystem ใดๆ ทั้งสิ้นบน partition นี้ สมมติว่าเป็น /dev/sda5 บนทั้งสองเครื่อง</p>
<p>หมายเหตุ</p>
<ul>
<li>แนะนำให้สร้าง partition ทั้งสองเครื่องให้เหมือนกัน ขนาดเท่ากัน จะได้ง่ายต่อการคอนฟิก</li>
<li>สำหรับการทดสอบเริ่มต้น แนะนำให้สร้างขนาด partition เล็กๆ ก่อน จะได้ใช้เวลาในการ sync ข้อมูลไม่นานมากนัก ในบทความนี้สร้างประมาณ 1 GBytes</li>
</ul>
<h4>ติดตั้งโปรแกรม DRBD</h4>
<p>ไฟล์ติดตั้ง DRBD ในรูปแบบ rpm ของ CentOS 5.4 นั้น ไม่อยู่ในแผ่นดีวีดีติดตั้ง แต่จะอยู่ในส่วนของ extras สำหรับในเมืองไทยสามารถดาวน์โหลดได้จาก <a href="http://www.mirror.in.th/osarchive/centos/5.4/extras/">http://www.mirror.in.th/osarchive/centos/5.4/extras/</a></p>
<p>ดาวน์โหล์ด และติดตั้งไฟล์ rpm สองไฟล์ บนเครื่องทั้งสอง</p>
<ul>
<li>drbd83-8.3.2-6.el5_3.x86_64.rpm  &#8211; &#8220;User space administration tools&#8221;</li>
<li>kmod-drbd83-8.3.2-6.el5_3.x86_64.rpm  &#8211; &#8220;Kernel Module&#8221;</li>
</ul>
<p>ใช้คำสั่ง rpm เพื่อติดตั้ง</p>
<pre>[root@centos54-a ~]# <strong>rpm -ivh drbd83-8.3.2-6.el5_3.x86_64.rpm
</strong>Preparing...                ########################################### [100%]
   1:drbd83                 ########################################### [100%]
[root@centos54-a ~]# <strong>rpm -ivh kmod-drbd83-8.3.2-6.el5_3.x86_64.rpm
</strong>Preparing...                ########################################### [100%]
   1:kmod-drbd83            ########################################### [100%]</pre>
<h4>คอนฟิก DRBD บนเครื่องที่ 1 (primary)</h4>
<p>ไฟล์คอนฟิกหลักของ DRBD คือไฟล์ /etc/drbd.conf ต้องมีการแก้ไขไฟล์นี้ก่อนถึงจะเริ่มใช้งานได้ โดยมีไฟล์ตัวอย่างคอนฟิกอยู่ใน /usr/share/doc/drbd83/drbd.conf</p>
<p>ไฟล์คอนฟิก /etc/drbd.conf จากการติดตั้ง</p>
<pre>[root@centos54-a ~]# <strong>cat /etc/drbd.conf
</strong>#
# please have a a look at the example configuration file in
# /usr/share/doc/drbd83/drbd.conf
#</pre>
<p>สร้างไฟล์คอนฟิก /etc/drbd.conf บนเครื่องที่ 1 &#8220;centos54-a.spalinux.com&#8221; ดังนี้</p>
<pre>[root@centos54-a ~]# <strong>cat /etc/drbd.conf
</strong>global {
    usage-count no;
}</pre>
<pre>common {
    syncer { rate 10M; }
}</pre>
<pre>resource <strong><span style="color: #0000ff;">r0</span> </strong>{
    protocol C;</pre>
<pre>    net {
        cram-hmac-alg "sha1";
        shared-secret "<span style="color: #0000ff;"><strong>test1234</strong></span>";
    }</pre>
<pre>    on <strong><span style="color: #0000ff;">centos54-a.spalinux.com</span></strong> {
        device /dev/drbd0;
        <strong><span style="color: #0000ff;">disk /dev/sda5</span></strong>;
        <strong><span style="color: #0000ff;">address 10.3.3.51:8888</span></strong>;
        meta-disk internal;
    }</pre>
<pre>    on <strong><span style="color: #0000ff;">centos54-b.spalinux.com</span></strong> {
        device /dev/drbd0;
        <strong><span style="color: #0000ff;">disk /dev/sda5</span></strong>;
        <strong><span style="color: #0000ff;">address 10.3.3.52:8888</span></strong>;
        meta-disk internal;
    }
}</pre>
<p>คำอธิบายเบื้องต้น</p>
<ul>
<li>shared-secret เป็นการกำหนดรหัสของเครื่องที่สามารถ replicate ข้อมูลกันได้ </li>
<li>r0 เป็นชื่อ resource ของ DRBD สามารถตั้งเป็นชื่อใดๆ ก็ได้ เพื่อสื่อความหมาย</li>
<li>on ตามด้วยชื่อ hostname ที่ต้องการ replicate ข้อมูลกัน ส่วนในวงเล็บ { เป็นการกำหนดคอนฟิกของแต่ละเครื่อง</li>
<li>disk คือชื่อ partition ที่สร้างไว้สำหรับการทำ DRBD ในที่นี้คือ /dev/sda5</li>
</ul>
<p>ใช้คำสั่ง drbadm create-md เพื่อสร้าง meta data บน partition ที่จะทำเป็น DRBD</p>
<pre>[root@centos54-a ~]# <strong>drbdadm create-md all
</strong>Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.</pre>
<p>หาก partition ที่คอนฟิกเป็น DRBD มี filesystem อยู่ก่อนแล้ว จะไม่สามารถสร้าง DRBD ได้</p>
<pre>[root@centos54-a ~]# <strong>drbdadm create-md all
</strong>md_offset 1011671040
al_offset 1011638272
bm_offset 1011605504</pre>
<pre><span style="color: #ff0000;">Found ext3 filesystem</span> which uses 987964 kB
current configuration leaves usable 987896 kB</pre>
<pre>Device size would be truncated, which
would corrupt data and result in
'access beyond end of device' errors.
You need to either
   * use external meta data (recommended)
   * shrink that filesystem first
   * zero out the device (destroy the filesystem)
<span style="color: #ff0000;">Operation refused.</span></pre>
<pre>Command 'drbdmeta 0 v08 /dev/sda5 internal create-md' terminated with exit code 40
<span style="color: #ff0000;">drbdadm create-md r0: exited with code 40</span></pre>
<p>วิธีการแก้ไขคือต้องลบข้อมูลของ filesystem บน partition /dev/sda5 นี้ออก วิธีการง่ายสุดคือใช้คำสั่ง dd</p>
<p><span style="color: #ff0000;"><strong>คำเตือน คำสั่ง dd จะลบข้อมูลทั้งหมดบน partition ที่ระบุ</strong></span></p>
<pre>[root@centos54-a ~]# <strong>dd if=/dev/zero of=/dev/sda5
</strong>dd: writing to `/dev/sda5': No space left on device
1975933+0 records in
1975932+0 records out
1011677184 bytes (1.0 GB) copied, 87.2749 seconds, 11.6 MB/s</pre>
<p>แล้วถึงสามารถสร้าง meta data ของ DRBD ได้</p>
<pre>[root@centos54-a ~]# <strong>drbdadm create-md all
</strong>Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.</pre>
<p>ใช้คำสั่ง service เพื่อรันเซอร์วิส DRBD</p>
<pre>[root@centos54-a ~]# <strong>service drbd start
</strong>Starting DRBD resources: [ d(r0) s(r0) n(r0) ]..........
***************************************************************
 DRBD's startup script waits for the peer node(s) to appear.
 - In case this node was already a degraded cluster before the
   reboot the timeout is 0 seconds. [degr-wfc-timeout]
 - If the peer was available before the reboot the timeout will
   expire after 0 seconds. [wfc-timeout]
   (These values are for resource 'r0'; 0 sec -&gt; wait forever)
 To abort waiting enter 'yes' [  20]:<span style="color: #3366ff;"><strong><span style="color: #0000ff;">yes</span></strong></span></pre>
<p>ในครั้งแรกที่รันเซอร์วิส บนเครื่อง primary โปรแกรมจะรอให้เครื่อง peer (secondary) เข้ามาเชื่อมต่อ หากไม่ต้องการให้รอ ให้พิมพ์คำว่า &#8220;yes&#8221; แล้ว [Enter]</p>
<p>ใช้คำสั่ง service status เพื่อตรวจสอบสถานะของ DRBD</p>
<pre>[root@centos54-a ~]# <strong>service drbd status
</strong>drbd driver loaded OK; device status:
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:07:55
m:res  cs            ro                 ds                     p  mounted  fstype
0:r0   WFConnection  <span style="color: #0000ff;"><strong>Secondary</strong></span>/Unknown  <span style="color: #0000ff;"><strong>Inconsistent</strong></span>/DUnknown  C</pre>
<p>หรืออ่านจากไฟล์ /proc/drbd โดยตรง</p>
<pre>[root@centos54-a ~]# <strong>cat /proc/drbd</strong>
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:07:55
 0: cs:WFConnection ro:Secondary/Unknown ds:Inconsistent/DUnknown C r----
    ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:987896</pre>
<p>สร้างไดเรคทอรี /export สำหรับทดสอบ mount เพื่อใช้ดิสก์ drbd ที่สร้างขึ้น</p>
<pre>[root@centos54-a ~]# <strong>mount /dev/drbd0 /export
</strong>mount: block device /dev/drbd0 is write-protected, mounting read-only
mount: Wrong medium type</pre>
<p>ดิสก์นี้ยังไม่สามารถใช้ได้ ต้องใช้คำสั่ง drbdadm primary คอนฟิกให้ดิสก์ drbd บนเครื่องนี้ทำหน้าที่เป็น primary เพื่อให้สามารถ อ่าน เขียน ข้อมูลจากดิสก์ได้</p>
<pre>[root@centos54-a ~]# <strong>drbdadm primary all
</strong><span style="color: #ff0000;">0: State change failed: (-2) Refusing to be Primary without at least one UpToDate disk
</span>Command 'drbdsetup 0 primary' terminated with exit code 17</pre>
<p>หากเป็นการเรียกใช้ครั้งแรก ต้องระบุออปชั่นดังนี้</p>
<pre>[root@centos54-a ~]# <strong>drbdadm -- --overwrite-data-of-peer primary all
</strong>[root@centos54-a ~]#</pre>
<p>ตรวจสอบสถานะ drbd อีกครั้ง สังเกตว่า ฟิลด์ ro จะเปลี่ยนจาก Seconday เป็น Primary และฟิลด์ ds จะเปลี่ยนจาก Inconsistent เป็น UpToDate</p>
<pre>[root@centos54-a ~]# <strong>service drbd status
</strong>drbd driver loaded OK; device status:
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:07:55
m:res  cs            ro               ds                 p  mounted  fstype
0:r0   WFConnection  <span style="color: #0000ff;"><strong>Primary</strong></span>/Unknown  <strong><span style="color: #0000ff;">UpToDate</span></strong>/DUnknown  C</pre>
<p>ทดสอบการ mount ดิสก์อีกครั้ง</p>
<pre>[root@centos54-a ~]# <strong>mount /dev/drbd0 /export
</strong>mount: you must specify the filesystem type</pre>
<p>ก็ยังไม่สามารถ mount ได้ เพราะยังไม่มี filesystem บน /dev/drbd0</p>
<p>รันคำสั่ง mkfs.ext3 เพื่อสร้าง filesystem แบบ ext3</p>
<pre>[root@centos54-a ~]# <strong>mkfs.ext3 /dev/drbd0
</strong>mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
123648 inodes, 246974 blocks
12348 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=255852544
8 block groups
32768 blocks per group, 32768 fragments per group
15456 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376</pre>
<pre>Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done</pre>
<pre>This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.</pre>
<p>ทดสอบการ mount อีกครั้ง จะสามารถใช้งานได้แล้ว</p>
<pre>[root@centos54-a ~]# <strong>mount /dev/drbd0 /export</strong></pre>
<p>ตรวจสอบสถานะ DRBD</p>
<pre>[root@centos54-a ~]# <strong>service drbd status
</strong>drbd driver loaded OK; device status:
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:07:55
m:res  cs            ro               ds                 p  mounted  fstype
0:r0   WFConnection  Primary/Unknown  UpToDate/DUnknown  C  <span style="color: #0000ff;"><strong>/export  ext3</strong></span></pre>
<h4>คอนฟิก DRBD บนเครื่องที่ 2 (secondary)</h4>
<p>สร้างไฟล์คอนฟิก /etc/drbd.conf บนเครื่องที่ 2 เหมือนกับไฟล์ในเครื่องที่ 1</p>
<pre>[root@centos54-b ~]# <strong>cat /etc/drbd.conf
</strong>global {
    usage-count no;
}</pre>
<pre>common {
    syncer { rate 10M; }
}</pre>
<pre>resource r0 {
    protocol C;</pre>
<pre>    net {
        cram-hmac-alg "sha1";
        shared-secret "test1234";
    }</pre>
<pre>    on centos54-a.spalinux.com {
        device /dev/drbd0;
        disk /dev/sda5;
        address 10.3.3.51:8888;
        meta-disk internal;
    }</pre>
<pre>    on centos54-b.spalinux.com {
        device /dev/drbd0;
        disk /dev/sda5;
        address 10.3.3.52:8888;
        meta-disk internal;
    }
}</pre>
<p>ใช้คำสั่ง drbadm create-md เพื่อสร้าง meta data บน partition ที่จะทำเป็น DRBD</p>
<pre>[root@centos54-b ~]# <strong>drbdadm create-md all
</strong>Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.</pre>
<p>เช่นเดียวกัน หากมี filesystem อยู่บน partition ก่อนแล้ว ต้องใช้คำสั่ง dd เพื่อลบข้อมูลออก</p>
<p>ใช้คำสั่ง service เพื่อรันเซอร์วิส DRBD</p>
<pre>[root@centos54-b ~]# <strong>service drbd start
</strong>Starting DRBD resources: [ d(r0) s(r0) n(r0) ].</pre>
<p>เมื่อเริ่มต้นรันเซอร์วิส DRBD บนเครื่องที่ 2 จะเป็นการเริ่ม replicate ข้อมูลจากเครื่องที่ 1</p>
<p>ตรวจสอบสถานะ DRBD บนเครื่องที่ 2</p>
<pre>[root@centos54-b ~]# <strong>service drbd status
</strong>drbd driver loaded OK; device status:
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:07:55
m:res  cs          ro                 ds                     p  mounted  fstype
...    <strong><span style="color: #0000ff;">sync'ed:    42.2%</span> </strong>             (576248/987896)K
0:r0   <strong><span style="color: #0000ff;">SyncTarget</span></strong>  <strong><span style="color: #0000ff;">Secondary</span></strong>/Primary  <span style="color: #0000ff;"><strong>Inconsistent</strong></span>/UpToDate  C</pre>
<p>ตรวจสอบสถานะ DRBD บนเครื่องที่ 1</p>
<pre>[root@centos54-a ~]# <strong>service drbd status
</strong>drbd driver loaded OK; device status:
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:07:55
m:res  cs          ro                 ds                     p  mounted  fstype
...    <strong><span style="color: #0000ff;">sync'ed:    43.0%</span></strong>              (567032/987896)K
0:r0   <strong><span style="color: #0000ff;">SyncSource</span></strong>  Primary/<strong><span style="color: #0000ff;">Secondary</span>  </strong>UpToDate/<strong><span style="color: #0000ff;">Inconsistent</span></strong>  C  /export  ext3</pre>
<p>เมื่อ replicate ข้อมูลเรียบร้อย (synced) ข้อมูลแล้ว สถานะจะเป็นดังนี้</p>
<p>ตรวจสอบสถานะ DRBD บนเครื่องที่ 2 เมื่อ synced ข้อมูลเรียบร้อย</p>
<pre>[root@centos54-b ~]# <strong>service drbd status
</strong>drbd driver loaded OK; device status:
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:07:55
m:res  cs         ro                 ds                 p  mounted  fstype
0:r0   <strong><span style="color: #0000ff;">Connected</span>  <span style="color: #0000ff;">Secondary</span></strong>/Primary  <strong><span style="color: #0000ff;">UpToDate</span></strong>/UpToDate  C</pre>
<p>ตรวจสอบสถานะ DRBD บนเครื่องที่ 1 เมื่อ synced ข้อมูลเรียบร้อย</p>
<pre>[root@centos54-a ~]# <strong>service drbd status
</strong>drbd driver loaded OK; device status:
version: 8.3.2 (api:88/proto:86-90)
GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:07:55
m:res  cs         ro                 ds                 p  mounted  fstype
0:r0   <strong><span style="color: #0000ff;">Connected</span></strong>  Primary/<strong><span style="color: #0000ff;">Secondary</span></strong>  UpToDate/<strong><span style="color: #0000ff;">UpToDate</span></strong>  C  /export  ext3</pre>
<p>หลังจาก synced ข้อมูลระหว่างเครื่องเรียบร้อย เมื่อมีการเปลี่ยนแปลงข้อมูลในดิสก์บนเครื่องที่ 1 (primary) การเปลี่ยนแปลงนั้นจะถูก replicate ไปยังเครื่องที่ 2 (secondary) โดยอัตโนมัติ</p>
<p>ตัวอย่างการใช้คำสั่ง tcpdump  ตรวจสอบ packet ที่ส่งระหว่างเครื่องเพื่อการ replicate ข้อมูลของ DRBD</p>
<pre>[root@centos54-b ~]# <strong>tcpdump -i eth0 -l -nn | grep 8888
</strong>tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
15:51:39.815802 IP 10.3.3.52.8888 &gt; 10.3.3.51.42180: P 2834377596:2834377604(8) ack 2893184807 win 46 &lt;nop,nop,timestamp 1772852 1818781&gt;
15:51:39.816356 IP 10.3.3.51.42180 &gt; 10.3.3.52.8888: P 1:9(8) ack 8 win 3216 &lt;nop,nop,timestamp 1828655 1772852&gt;
15:51:39.816394 IP 10.3.3.52.8888 &gt; 10.3.3.51.42180: . ack 9 win 46 &lt;nop,nop,timestamp 1772852 1828655&gt;
15:51:44.888876 IP 10.3.3.1.4117 &gt; 10.3.3.51.22: P 1560:1612(52) ack 1629 win 64271
15:51:49.815252 IP 10.3.3.51.42180 &gt; 10.3.3.52.8888: P 9:17(8) ack 8 win 3216 &lt;nop,nop,timestamp 1838655 1772852&gt;
15:51:49.815330 IP 10.3.3.52.8888 &gt; 10.3.3.51.42180: . ack 17 win 46 &lt;nop,nop,timestamp 1782853 1838655&gt;
15:51:49.815666 IP 10.3.3.52.8888 &gt; 10.3.3.51.42180: P 8:16(8) ack 17 win 46 &lt;nop,nop,timestamp 1782853 1838655&gt;
15:51:49.847300 IP 10.3.3.51.42180 &gt; 10.3.3.52.8888: . ack 16 win 3216 &lt;nop,nop,timestamp 1838696 1782853&gt;
15:51:50.937877 IP 10.3.3.51.8888 &gt; 10.3.3.52.40284: . 3903780263:3903781711(1448) ack 2834246899 win 501 &lt;nop,nop,timestamp 1839875 1683335&gt;
...
<strong><span style="color: #0000ff;">[Ctrl-C]</span></strong></pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://www.drbd.org/" target="_blank">DRBD</a></li>
<li><a href="http://www.mirror.in.th/osarchive/centos/5.4/extras/" target="_blank">CentOS 5.4 extras</a></li>
<li><a href="http://spalinux.com/2010/02/basic_using_drbd">การใช้งาน DRBD เบื้องต้น</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2010/02/install_and_configure_drbd/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>คอนฟิก iSCSI target บน Linux</title>
		<link>http://spalinux.com/2009/11/configure_iscsi_target_on_linux</link>
		<comments>http://spalinux.com/2009/11/configure_iscsi_target_on_linux#comments</comments>
		<pubDate>Fri, 20 Nov 2009 08:49:56 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Disk]]></category>
		<category><![CDATA[Filesystem]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[iSCSI]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=968</guid>
		<description><![CDATA[บทความนี้กล่าวถึงการติดตั้งโปรแกรม iSCSI target และการคอนฟิกเพื่อให้เครืองอื่นๆ ที่ทำหน้าที่ initiator สามารถมาเรียกใช้ storage ได้ ติดตั้งไฟล์ rpm ไฟล์ rpm ที่ต้องใช้ เพื่อคอนฟิกเครื่องให้ทำหน้าที่เป็น iSCSI target ได้ คือ &#8220;scsi-target-utils&#8221; ตัวอย่างการติดตั้งไฟล์ rpm สำหรับ Fedora 11 [root@fc11-server ~]# rpm -i scsi-target-utils-0.9.5-1.fc11.x86_64.rpm error: Failed dependencies:         perl(Config::General) is needed by scsi-target-utils-0.9.5-1.fc11.x86_64 หากเจอ error แบบนี้ ต้องลงไฟล์ rpm ชื่อ perl-Config-General ก่อน [root@fc11-server ~]# rpm -i perl-Config-General-2.42-2.fc11.noarch.rpm [root@fc11-server ~]# rpm [...]]]></description>
			<content:encoded><![CDATA[<p>บทความนี้กล่าวถึงการติดตั้งโปรแกรม iSCSI target และการคอนฟิกเพื่อให้เครืองอื่นๆ ที่ทำหน้าที่ initiator สามารถมาเรียกใช้ storage ได้</p>
<p><span id="more-968"></span></p>
<h4>ติดตั้งไฟล์ rpm</h4>
<p>ไฟล์ rpm ที่ต้องใช้ เพื่อคอนฟิกเครื่องให้ทำหน้าที่เป็น iSCSI target ได้ คือ &#8220;scsi-target-utils&#8221;</p>
<p>ตัวอย่างการติดตั้งไฟล์ rpm สำหรับ Fedora 11</p>
<pre>[root@fc11-server ~]# <strong>rpm -i scsi-target-utils-0.9.5-1.fc11.x86_64.rpm
</strong><span style="color: #ff0000;">error: Failed dependencies:
        perl(Config::General) is needed by scsi-target-utils-0.9.5-1.fc11.x86_64</span></pre>
<p>หากเจอ error แบบนี้ ต้องลงไฟล์ rpm ชื่อ perl-Config-General ก่อน</p>
<pre>[root@fc11-server ~]# <strong>rpm -i perl-Config-General-2.42-2.fc11.noarch.rpm
</strong>[root@fc11-server ~]# <strong>rpm -i scsi-target-utils-0.9.5-1.fc11.x86_64.rpm</strong></pre>
<h4>รันเซอร์วิส tgtd</h4>
<p>รันเซอร์วิส tgtd (The Generic storage Target Daemon) ก่อน โดยใช้คำสั่ง service</p>
<pre>[root@fc11-server ~]# <strong>/etc/init.d/tgtd start
</strong>Starting SCSI target daemon:                               [  OK  ]</pre>
<h4>สร้าง target ใหม่</h4>
<p>ใช้คำสั่ง tgtadm เพื่อสร้าง target ใหม่ โดยพารามิเตอร์ที่ต้องระบุคือ target id (&#8211;tid) และชื่อ target (-T)</p>
<p>เราสามารถสร้างได้หลาย target ในเซิร์ฟเวอร์เครื่องหนึ่ง แต่ต้องมี id และชื่อแตกต่างกัน สำหรับ  id เราสามารถรันตัวเลขเริ่มจาก 1 ได้ ส่วนชื่อ target ที่นิยมกันจะตั้งชื่อในรูปแบบ iqn (iSCSI Qualified Name)</p>
<p>รูปแบบชื่อแบบ iqn</p>
<pre>iqn.yyyy-mm.{reversed domain name}:resource_name</pre>
<p>ในบทความนี้ตั้งชื่อเป็น iqn.2001-04.com.example:storage.test.disk-01</p>
<p>ตัวอย่างการสร้าง target ใหม่</p>
<pre>[root@fc11-server ~]# <strong>tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2001-04.com.example:storage.test.disk-01</strong></pre>
<p>หลังจากที่สร้างแล้ว สามารถใช้คำสั่ง tgtadm &#8211;op show เพื่อตรวจสอบคอนฟิก target ที่ทำงานอยู่ได้</p>
<pre>[root@fc11-server ~]# <strong>tgtadm --lld iscsi --op show --mode target
</strong><span style="color: #0000ff;">Target 1: iqn.2001-04.com.example:storage.test.disk-01
</span>    System information:
        Driver: <span style="color: #0000ff;">iscsi</span>
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB
            Online: Yes
            Removable media: No
            Backing store: No backing store
    Account information:
    ACL information:</pre>
<h4>เพิ่ม logical unit เข้า target</h4>
<p>เมื่อสร้าง target แล้ว จะยังไม่สามารถใช้งานได้ทันที ต้องเพิ่ม logical unit ที่จะทำหน้าที่เป็น storage ของ target นี้ก่อน</p>
<p>เราสามารถใช้ disk partition หรือ LVM logical volume เพื่อทำหน้าที่เป็น logical unit ได้ ในที่นี้จะใช้ disk partition /dev/sdb1</p>
<p><span style="color: #ff0000;">คำเตือน!!! ข้อมูลใน disk ที่จะใช้เป็น logical unit จะถูกทำลายทั้งหมด จาก initiator</span></p>
<p>ตัวอย่างการเพิ่ม logical unit เข้า target</p>
<pre>[root@fc11-server ~]# <strong>tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/sdb1</strong></pre>
<p>ตรวจสอบหลังจากการเพิ่ม logical unit</p>
<pre>[root@fc11-server ~]# <strong>tgtadm --lld iscsi --op show --mode target
</strong>Target 1: iqn.2001-04.com.example:storage.test.disk-01
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB
            Online: Yes
            Removable media: No
            Backing store: No backing store
<span style="color: #0000ff;">        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 40049 MB
            Online: Yes
            Removable media: No
            Backing store: /dev/sdb1
</span>    Account information:
    ACL information:</pre>
<h4>คอนฟิก bind target</h4>
<p>สุดท้ายต้องระบุการ bind เพื่อเป็นการอนุญาตให้เครื่อง client หรือ initiator สามารถเข้ามาใช้ (access) target ได้</p>
<p>เบื้องต้น เราจะอนุญาตทั้งหมดให้เข้ามาใช้ได้ ด้วยการระบบออปชั่น &#8220;-I ALL&#8221;</p>
<pre>[root@fc11-server ~]# <strong>tgtadm --lld iscsi --op bind --mode target --tid 1 -I ALL</strong></pre>
<p>ตรวจสอบหลังจากคอนฟิก</p>
<pre>[root@fc11-server ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2001-04.com.example:storage.test.disk-01
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB
            Online: Yes
            Removable media: No
            Backing store: No backing store
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 40049 MB
            Online: Yes
            Removable media: No
            Backing store: /dev/sdb1
    Account information:
    ACL information:
        <span style="color: #0000ff;"><strong>ALL</strong></span></pre>
<h4>ทดสอบจาก iSCSI initiator</h4>
<p>ทดสอบรันคำสั่ง iscsiadm -m discovery จากเครื่องอื่น เพื่อทดสอบการค้นหา target ที่เพิ่งสร้างขึ้น  สมมติว่าเคื่อง server ที่ทำหน้าที่ target มี ip address เป็น 192.168.1.1</p>
<pre>[root@fc11-client ~]# <strong>iscsiadm -m discovery -t sendtargets -p 192.168.1.1
</strong>192.168.1.1:3260,1 iqn.2001-04.com.example:storage.test.disk-01</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2009/11/configure_iscsi_initiator_on_linux">คอนฟิก iSCSI initiator บน Linux</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/11/configure_iscsi_target_on_linux/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>copy ไฟล์ให้เหมือนเดิม</title>
		<link>http://spalinux.com/2009/10/copy_preserve_file_information</link>
		<comments>http://spalinux.com/2009/10/copy_preserve_file_information#comments</comments>
		<pubDate>Sat, 03 Oct 2009 11:02:44 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Filesystem]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[cp preserve]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=956</guid>
		<description><![CDATA[ในบทความนี้ขอแสดงตัวอย่างและเปรียบเทียบผลลัพธ์การใช้คำสั่ง cp ด้วยออปชั่นต่างๆ ว่าข้อมูลของไฟล์ (file perrmission, owner, group, timestamps, attributes) ว่าแตกต่างกันอย่างไร หมายเหตุ ตัวอย่างในบทความนี้ทดสอบบน Fedora 11 สร้างไฟล์ทดสอบด้วย user1 [user1@fc11-64a tmp]$ echo "Hello World, this is test file." &#62; user1-file.0 [user1@fc11-64a tmp]$ ls -l total 4 -rw-rw-r-- 1 user1 user1 32 2009-10-03 17:03 user1-file.0 คำสั่ง cp ไม่มีออปชั่น ทดสอบด้วย root เพื่อ copy ไฟล์ โดยไม่มีการระบุออปชั่น [root@fc11-64a tmp]# date Sat [...]]]></description>
			<content:encoded><![CDATA[<p>ในบทความนี้ขอแสดงตัวอย่างและเปรียบเทียบผลลัพธ์การใช้คำสั่ง cp ด้วยออปชั่นต่างๆ ว่าข้อมูลของไฟล์ (file perrmission, owner, group, timestamps, attributes) ว่าแตกต่างกันอย่างไร</p>
<p><span id="more-956"></span></p>
<p>หมายเหตุ ตัวอย่างในบทความนี้ทดสอบบน Fedora 11</p>
<h4>สร้างไฟล์ทดสอบด้วย user1</h4>
<pre>[user1@fc11-64a tmp]$ <strong>echo "Hello World, this is test file." &gt; user1-file.0</strong></pre>
<pre>[user1@fc11-64a tmp]$ <strong>ls -l</strong>
total 4
-rw-rw-r-- 1 user1 user1 32 2009-10-03 17:03 user1-file.0</pre>
<h4>คำสั่ง cp ไม่มีออปชั่น</h4>
<p>ทดสอบด้วย root เพื่อ copy ไฟล์ โดยไม่มีการระบุออปชั่น</p>
<pre>[root@fc11-64a tmp]# <strong>date
</strong>Sat Oct  3 17:06:52 ICT 2009</pre>
<pre>[root@fc11-64a tmp]# <strong>cp user1-file.0 user1-file.1</strong></pre>
<pre>[root@fc11-64a tmp]# ls -l
-rw-rw-r-- 1 user1 user1 32 2009-10-03 17:03 user1-file.0
<span style="color: #ff0000;"><strong>-rw-r--r--</strong></span> 1 <strong><span style="color: #ff0000;">root  root</span></strong>  32 2009-10-03 <strong><span style="color: #ff0000;">17:06</span></strong> user1-file.1</pre>
<p>ไฟล์ที่ copy ได้มา จะมี permission, owner, group, timestamp ไม่ตรงกับไฟล์ต้นฉบับ เพราะดีฟอลต์ คำสั่ง cp จะไม่ preserve ข้อมูลของไฟล์เลย</p>
<h4>cp -p เก็บข้อมูลของไฟล์</h4>
<p>หากต้องการ preserve ข้อมูลของไฟล์ด้วย ต้องระบุออปชั่น &#8216;-p&#8217;</p>
<p>คำอธิบาย ออปชั่น &#8216;-p&#8217; จาก man cp(1)</p>
<pre>    -p    same as --preserve=mode,ownership,timestamps</pre>
<p>ทดสอบ cp ด้วยออปชั่น &#8216;-p&#8217;</p>
<pre>[root@fc11-64a tmp]# <strong>date
</strong>Sat Oct  3 17:08:01 ICT 2009</pre>
<pre>[root@fc11-64a tmp]# <strong>cp -p user1-file.0 user1-file.2</strong></pre>
<pre>[root@fc11-64a tmp]# <strong>ls -l
</strong>-rw-rw-r-- 1 user1 user1 32 2009-10-03 17:03 user1-file.0
-rw-r--r-- 1 root  root  32 2009-10-03 17:06 user1-file.1
-rw-rw-r-- 1 user1 user1 32 2009-10-03 17:03 user1-file.2</pre>
<p>หมายเหตุ หากใช้ user อื่น ที่ไม่ใช่ root เช่น user2 จะไม่สามารถคงข้อมูล owner, group ของไฟล์ได้</p>
<pre>[user2@fc11-64a tmp]$ <strong>cp -p user1-file.0 user1-file.3
</strong>[user2@fc11-64a tmp]$ <strong>ls -l
</strong>-rw-rw-r-- 1 user1 user1 32 2009-10-03 17:03 user1-file.0
-rw-rw-r-- 1 <span style="color: #ff0000;"><strong>user2 user2</strong></span> 32 2009-10-03 17:03 user1-file.3</pre>
<h4>ทดสอบ preserve ข้อมูล ACL</h4>
<p>ใช้ user1 คอนฟิก ACL เพิ่มเติมในไฟล์</p>
<pre>[user1@fc11-64a tmp]$ <strong>getfacl user1-file.0
</strong># file: user1-file.0
# owner: user1
# group: user1
user::rw-
group::rw-
other::r--</pre>
<pre>[user1@fc11-64a tmp]$ <strong>setfacl -m user:user2:rwx user1-file.0</strong></pre>
<pre>[user1@fc11-64a tmp]$ <strong>getfacl user1-file.0
</strong># file: user1-file.0
# owner: user1
# group: user1
user::rw-
user:user2:rwx
group::rw-
mask::rwx
other::r--</pre>
<p>การใช้ออปชั่น &#8216;-p&#8217; สามารถ preserve File ACL ที่คอนฟิกไว้ได้ด้วย</p>
<pre>[root@fc11-64a tmp]# <strong>cp -p user1-file.0 user1-file.3
</strong>[root@fc11-64a tmp]# <strong>ls -l
</strong>-rw-rwxr--+ 1 user1 user1 32 2009-10-03 17:03 user1-file.0
-rw-rwxr--+ 1 user1 user1 32 2009-10-03 17:03 user1-file.3</pre>
<pre>[root@fc11-64a tmp]# <strong>getfacl user1-file.3
</strong># file: user1-file.3
# owner: user1
# group: user1
user::rw-
<span style="color: #0000ff;"><strong>user:user2:rwx</strong>
</span>group::rw-
mask::rwx
other::r--</pre>
<h4>cp -v แสดงไฟล์ที่กำลัง copy</h4>
<p>หากต้องการดูไฟล์ที่กำลัง copy อยู่ สามารถใช้ ออปชั่น &#8216;-v&#8217;</p>
<p>คำอธิบาย ออปชั่น &#8216;-p&#8217; จาก man cp(1)</p>
<pre>    -v, --verbose    explain what is being done</pre>
<pre>[root@fc11-64a tmp]# <strong>cp -pv user1-file.0 user1-file.4
</strong>`user1-file.0' -&gt; `user1-file.4'</pre>
<h4>soft link file</h4>
<p>ใช้ user1 สร้าง soft link ชื่อ user1-link.0 เพื่อ link ไฟล์ไปยัง user1-file.0</p>
<pre>[user1@fc11-64a tmp]$ <strong>ln -s user1-file.0 user1-link.0
</strong>[user1@fc11-64a tmp]$ <strong>ls -l
</strong>-rw-rwxr--+ 1 user1 user1 32 2009-10-03 17:03 user1-file.0
lrwxrwxrwx  1 user1 user1 12 2009-10-03 17:15 user1-link.0 -&gt; user1-file.0</pre>
<p>ใช้คำสั่ง cp -p เพื่อ copy ไฟล์ soft link</p>
<pre>[root@fc11-64a tmp]# <strong>cp -p user1-link.0 user1-link.1</strong></pre>
<pre>[root@fc11-64a tmp]# <strong>ls -l
</strong>-rw-rwxr--+ 1 user1 user1 32 2009-10-03 17:03 user1-file.0
lrwxrwxrwx  1 user1 user1 12 2009-10-03 17:15 user1-link.0 -&gt; user1-file.0
-rw-rwxr--+ 1 user1 user1 <span style="color: #ff0000;">32</span> 2009-10-03 17:03 user1-link.1</pre>
<p>ผลลัพธ์กลับเป็นการ copy ไฟล์ต้นฉบับ user1-file.0 ไม่ใช่ link file</p>
<h4>cp -d เก็บสถานะ link file</h4>
<p>หากต้องการ copy ไฟล์แล้วยังคงสถานะ link file ไว้ ต้องใช้ ออปชั่น &#8216;-d&#8217;</p>
<p>คำอธิบาย ออปชั่น &#8216;-p&#8217; จาก man cp(1)</p>
<pre>    -d    same as --no-dereference --preserve=links</pre>
<pre>[root@fc11-64a tmp]# <strong>cp -pd user1-link.0 user1-link.2</strong></pre>
<pre>[root@fc11-64a tmp]# <strong>ls -l
</strong>total 8
-rw-rwxr--+ 1 user1 user1 32 2009-10-03 17:03 user1-file.0
lrwxrwxrwx  1 user1 user1 12 2009-10-03 17:15 user1-link.0 -&gt; user1-file.0
-rw-rwxr--+ 1 user1 user1 32 2009-10-03 17:03 user1-link.1
lrwxrwxrwx  1 user1 user1 12 2009-10-03 17:18 user1-link.2 -&gt; user1-file.0</pre>
<h4>copy ทั้งไดเร็คทอรี</h4>
<p>ใช้ user1 สร้างไดเร็คทอรี และไฟล์ย่อยๆ ข้างใน</p>
<pre>[user1@fc11-64a tmp]$ <strong>mkdir user1-dir.0
</strong>[user1@fc11-64a tmp]$ <strong>touch user1-dir.0/sub-file1.txt
</strong>[user1@fc11-64a tmp]$ <strong>touch user1-dir.0/sub-file2.txt
</strong>[user1@fc11-64a tmp]$ <strong>touch user1-dir.0/sub-file3.txt
</strong>[user1@fc11-64a tmp]$ <strong>touch user1-dir.0/sub-file4.txt
</strong>[user1@fc11-64a tmp]$ <strong>ls -l
</strong>total 0
drwxrwxr-x 2 user1 user1 86 2009-10-03 17:24 user1-dir.0
[user1@fc11-64a tmp]$ <strong>ls -l user1-dir.0/
</strong>total 0
-rw-rw-r-- 1 user1 user1 0 2009-10-03 17:24 sub-file1.txt
-rw-rw-r-- 1 user1 user1 0 2009-10-03 17:24 sub-file2.txt
-rw-rw-r-- 1 user1 user1 0 2009-10-03 17:24 sub-file3.txt
-rw-rw-r-- 1 user1 user1 0 2009-10-03 17:24 sub-file4.txt</pre>
<p>ทดลองใช้ root เพื่อ copy ไฟล์ทั้งไดเร็คทอรี</p>
<pre>[root@fc11-64a tmp]# <strong>cp -pd user1-dir.0/ user1-dir.1
</strong>cp: omitting directory `user1-dir.0/'</pre>
<pre>[root@fc11-64a tmp]# <strong>ls -l
</strong>total 0
drwxrwxr-x 2 user1 user1 86 2009-10-03 17:24 user1-dir.0</pre>
<p>ออปชั่นแค่นี้ ไม่สามารถ copy ไดเร็คทอรี ได้</p>
<h4>cp -R ทั้งไดเร็คทอรี</h4>
<p>หากต้องการ copy ทั้งไดเร็คทอรี ต้องใช้ออปชั่น &#8216;-R&#8217; หรือ &#8216;-r&#8217;</p>
<p>คำอธิบาย ออปชั่น &#8216;-p&#8217; จาก man cp(1)</p>
<pre>    -R, -r, --recursive    copy directories recursively</pre>
<pre>[root@fc11-64a tmp]# <strong>cp -pvdR user1-dir.0/ user1-dir.1
</strong>`user1-dir.0/' -&gt; `user1-dir.1'
`user1-dir.0/sub-file1.txt' -&gt; `user1-dir.1/sub-file1.txt'
`user1-dir.0/sub-file2.txt' -&gt; `user1-dir.1/sub-file2.txt'
`user1-dir.0/sub-file3.txt' -&gt; `user1-dir.1/sub-file3.txt'
`user1-dir.0/sub-file4.txt' -&gt; `user1-dir.1/sub-file4.txt'</pre>
<p>ตรวจสอบไดเร็คทอรี และไฟล์ที่อยู่ข้างใน</p>
<pre>[root@fc11-64a tmp]# <strong>ls -l
</strong>total 0
drwxrwxr-x 2 user1 user1 86 2009-10-03 17:24 user1-dir.0
drwxrwxr-x 2 user1 user1 86 2009-10-03 17:24 user1-dir.1
[root@fc11-64a tmp]# <strong>ls -l user1-dir.1/
</strong>total 0
-rw-rw-r-- 1 user1 user1 0 2009-10-03 17:24 sub-file1.txt
-rw-rw-r-- 1 user1 user1 0 2009-10-03 17:24 sub-file2.txt
-rw-rw-r-- 1 user1 user1 0 2009-10-03 17:24 sub-file3.txt
-rw-rw-r-- 1 user1 user1 0 2009-10-03 17:24 sub-file4.txt</pre>
<h4>cp -a ออปชั่นเดียวทำทุกอย่าง</h4>
<p>ออปชั่นที่ยกตัวอย่างข้างบนมาทั้งหมด (ยกเว้น -v) สามารถเปลี่ยนเป็นออปชั่นเดียวได้คือ &#8216;-a&#8217; เพื่อการ copy ไฟล์แล้วคงข้อมูลของไฟล์ไว้ทั้งหมด รวมทั้ง copy ไดเร็คทอรี ไฟล์ย่อยๆ ได้ทั้งหมด</p>
<p>คำอธิบาย ออปชั่น &#8216;-p&#8217; จาก man cp(1)</p>
<pre>    -a, --archive    same as -dR --preserve=all</pre>
<pre>[root@fc11-64a tmp]# <strong>cp -av user1-dir.0/ user1-dir.2
</strong>`user1-dir.0/' -&gt; `user1-dir.2'
`user1-dir.0/sub-file1.txt' -&gt; `user1-dir.2/sub-file1.txt'
`user1-dir.0/sub-file2.txt' -&gt; `user1-dir.2/sub-file2.txt'
`user1-dir.0/sub-file3.txt' -&gt; `user1-dir.2/sub-file3.txt'
`user1-dir.0/sub-file4.txt' -&gt; `user1-dir.2/sub-file4.txt'</pre>
<pre>[root@fc11-64a tmp]# <strong>ls -l
</strong>total 0
drwxrwxr-x 2 user1 user1 86 2009-10-03 17:24 user1-dir.0
drwxrwxr-x 2 user1 user1 86 2009-10-03 17:24 user1-dir.1
<span style="color: #0000ff;">drwxrwxr-x 2 user1 user1 86 2009-10-03 17:24 user1-dir.2
</span>[root@fc11-64a tmp]# <strong>ls -l user1-dir.2/
</strong>total 0
-rw-rw-r-- 1 user1 user1 0 2009-10-03 17:24 sub-file1.txt
-rw-rw-r-- 1 user1 user1 0 2009-10-03 17:24 sub-file2.txt
-rw-rw-r-- 1 user1 user1 0 2009-10-03 17:24 sub-file3.txt
-rw-rw-r-- 1 user1 user1 0 2009-10-03 17:24 sub-file4.txt</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li>man cp(1)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/10/copy_preserve_file_information/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>คอนฟิก XFS Filesystem</title>
		<link>http://spalinux.com/2009/10/configure_xfs_filesystem</link>
		<comments>http://spalinux.com/2009/10/configure_xfs_filesystem#comments</comments>
		<pubDate>Sat, 03 Oct 2009 09:39:01 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Filesystem]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[xfs filesystem]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=952</guid>
		<description><![CDATA[โดยดีฟอลต์การติดตั้ง Fedora ไม่ว่าจะเป็นเวอร์ชั่นเก่าหรือใหม่ Filesystem ที่ถูกเลือกเป็นดีฟอลต์จะเป็นแบบ ext ตั้งแต่ ext2, ext3 และล่าสุดเป็น ext4 ที่จริงตอนติดตั้ง มีให้เลือก Filesystem แบบอื่นอยู่ด้วยเช่น xfs แต่ถ้าตอนติดตั้งไม่ได้เลือก แล้วเราติดตั้ง ลงโปรแกรมต่างๆ คอนฟิก และระบบใช้งานไปแล้ว ไม่อยากเสียเวลาติดตั้งใหม่ทั้งหมด วันหนึ่งมี disk ก้อนใหม่เพิ่มขึ้นมา แล้วอยากจะใช้ Filesystem แบบ xfs บ้าง บทความนี้จะอธิบายการติดตั้งโปรแกรมเพิ่มเติม เพื่อให้เครื่องเราสามารถเรียกใช้ Filesystem แบบ xfs ได้ สองส่วนที่ต้องคอนฟิกเพิ่มเติม คือลงไฟล์ rpm สำหรับโปรแกรมจัดการ xfs filesystem และอีกส่วนคือคำสั่งในการสร้าง filesystem ในที่นี้จะสมมตว่าเราเพิ่มดิสก์ ก้อนที่ 2 ชื่อ /dev/sdb เข้าไปในเครื่อง ทดสอบกับ Fedora 11 ติดตั้งโปรแกรม xfsprogs [...]]]></description>
			<content:encoded><![CDATA[<p>โดยดีฟอลต์การติดตั้ง Fedora ไม่ว่าจะเป็นเวอร์ชั่นเก่าหรือใหม่ Filesystem ที่ถูกเลือกเป็นดีฟอลต์จะเป็นแบบ ext ตั้งแต่ ext2, ext3 และล่าสุดเป็น ext4</p>
<p>ที่จริงตอนติดตั้ง มีให้เลือก Filesystem แบบอื่นอยู่ด้วยเช่น xfs แต่ถ้าตอนติดตั้งไม่ได้เลือก แล้วเราติดตั้ง ลงโปรแกรมต่างๆ คอนฟิก และระบบใช้งานไปแล้ว ไม่อยากเสียเวลาติดตั้งใหม่ทั้งหมด วันหนึ่งมี disk ก้อนใหม่เพิ่มขึ้นมา แล้วอยากจะใช้ Filesystem แบบ xfs บ้าง</p>
<p>บทความนี้จะอธิบายการติดตั้งโปรแกรมเพิ่มเติม เพื่อให้เครื่องเราสามารถเรียกใช้ Filesystem แบบ xfs ได้</p>
<p><span id="more-952"></span></p>
<p>สองส่วนที่ต้องคอนฟิกเพิ่มเติม คือลงไฟล์ rpm สำหรับโปรแกรมจัดการ xfs filesystem และอีกส่วนคือคำสั่งในการสร้าง filesystem</p>
<p>ในที่นี้จะสมมตว่าเราเพิ่มดิสก์ ก้อนที่ 2 ชื่อ /dev/sdb เข้าไปในเครื่อง ทดสอบกับ Fedora 11</p>
<h4>ติดตั้งโปรแกรม xfsprogs</h4>
<p>โปรแกรม xfsprogs มีอยู่ในแผ่นดีวีดีติดตี้ง Fedora อยู่แล้ว ใส่แผ่นแล้วใช้คำสั่ง mount เพื่อติดตั้งโปรแกรม</p>
<pre>[root@fc11-64a ~]# <strong>mount /dev/scd0 /media/
</strong>mount: block device /dev/sr0 is write-protected, mounting read-only</pre>
<pre>[root@fc11-64a ~]# <strong>cd /media/Packages/
</strong>[root@fc11-64a Packages]#</pre>
<pre>[root@fc11-64a Packages]# <strong>rpm -ivh xfsprogs-3.0.0-2.fc11.x86_64.rpm
</strong>Preparing...                ########################################### [100%]
   1:xfsprogs               ########################################### [100%]</pre>
<p>จากการติดตั้งโปรแกรม xfsprogs เราจะได้คำสั่งที่ใช้ในการจัดการ คอนฟิก xfs filesystem</p>
<pre>[root@fc11-64a ~]# <strong>rpm -ql xfsprogs
</strong>/lib64/libhandle.so.1
/lib64/libhandle.so.1.0.3
/sbin/fsck.xfs
/sbin/mkfs.xfs
/sbin/xfs_repair
/usr/sbin/xfs_admin
/usr/sbin/xfs_bmap
/usr/sbin/xfs_check
/usr/sbin/xfs_copy
/usr/sbin/xfs_db
/usr/sbin/xfs_estimate
/usr/sbin/xfs_freeze
/usr/sbin/xfs_fsr
/usr/sbin/xfs_growfs
/usr/sbin/xfs_info
/usr/sbin/xfs_io
/usr/sbin/xfs_logprint
/usr/sbin/xfs_mdrestore
/usr/sbin/xfs_metadump
/usr/sbin/xfs_mkfile
/usr/sbin/xfs_ncheck
/usr/sbin/xfs_quota
/usr/sbin/xfs_rtcp
...</pre>
<h4>สร้าง xfs filesystem</h4>
<p>สร้าง partition บนดิสก์ก้อนใหม่ แล้วใช้คำสั่ง mkfs.xfs เพื่อสร้าง xfs filesystem (format) บน partition</p>
<p>หมายเหตุ หากใช้คำสั่ง mkfs.xfs แล้วเจอข้อความ error แบบนี้ คือ partition นี้มี filesystem แบบอื่นอยู่แล้ว (ในที่นี้คือ ext3) หากต้องการสร้าง filesystem แบบ xfs ทับลงไปจริงๆ ต้องระบุออปชั่น &#8216;-f&#8217; ด้วย</p>
<pre>[root@fc11-64a ~]# <strong>mkfs.xfs /dev/sdb1
</strong>mkfs.xfs: /dev/sdb1 appears to contain an existing filesystem (ext3).
mkfs.xfs: Use the -f option to force overwrite.</pre>
<pre>[root@fc11-64a ~]# <strong>mkfs.xfs -f /dev/sdb1</strong>
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=2444388 blks
         =                       sectsz=512   attr=2
data     =                       bsize=4096   blocks=9777552, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal log           bsize=4096   blocks=4774, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=0
realtime =none                   extsz=4096   blocks=0, rtextents=0</pre>
<p>สร้างไดเร็คทอรี (mount point) สำหรับ mount partition ที่สร้างใหม่</p>
<pre>[root@fc11-64a ~]# <strong>mkdir /export</strong></pre>
<pre>[root@fc11-64a ~]# <strong>mount /dev/sdb1 /export</strong></pre>
<pre>[root@fc11-64a ~]# <strong>mount</strong>
...
/dev/sdb1 on /export type xfs (rw)</pre>
<pre>[root@fc11-64a ~]# <strong>df -h
</strong>Filesystem            Size  Used Avail Use% Mounted on
...
/dev/sdb1              38G  4.2M   38G   1% /export</pre>
<p>หากทดสอบจนแน่ใจว่าใช้งานได้ตามปกติ ถ้าต้องการให้ mount partition นี้ ตอนบู๊ตเครื่องโดยอัตโนมัติ สามารถทำได้โดยเพิ่มคอนฟิกในไฟล์ /etc/fstab</p>
<pre>[root@fc11-64a ~]# <strong>cat /etc/fstab
</strong>...
/dev/sdb1               /export                 xfs     defaults        1 2</pre>
<h4>การเปลี่ยน filesystem จากแบบอื่น ให้เป็น xfs</h4>
<p>การเปลี่ยน filesystem จากแบบอื่น ให้เป็น xfs ต้องทำการ backup ข้อมูลที่อยู่เดิม ก่อน แล้วใช้คำสั่ง mkfs.xfs เพื่อสร้าง filesystem แบบ xfs ขึ้นมาใหม่ แล้วค่อย restore ข้อมูลกลับลงไป เท่าที่ทราบ ไม่มีคำสั่งหรือโปรแกรมไหน สามารถเปลี่ยนแปลง filesystem ให้เป็น xfs ได้โดยตรง</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2008/12/compare_ext3_ext4_xfs_on_fedora_10">เปรียบเทียบ ext3, ext4 และ xfs บน Fedora 10</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/10/configure_xfs_filesystem/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เปรียบเทียบ RAID-0 จากคำสั่ง mdadm และ lvm ตอนที่ 3</title>
		<link>http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_3</link>
		<comments>http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_3#comments</comments>
		<pubDate>Sun, 07 Jun 2009 10:12:40 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Benchmark]]></category>
		<category><![CDATA[Disk]]></category>
		<category><![CDATA[Filesystem]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[RAID]]></category>
		<category><![CDATA[linear]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[stripe]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=774</guid>
		<description><![CDATA[ในตอนสุรปนี้ จะเพิ่มผลลัพธ์จากการรันคำสั่ง sysbench เพื่อทดสอบ fileio ทั้งการอ่านและเขียนไฟล์แบบ sequential, random ก่อนการรัน sysbench เพื่อทดสอบ ต้องสร้างไฟล์ (prepare) ใน mount point ของ filesystem ที่ต้องการทดสอบ เช่นถ้า mount ไว้ที่ /mnt/lv0/ ต้อง cd เข้าไปในพาธนี้แล้วรันคำสั่ง [root@fc10-disk ~]# cd /mnt/lv0/ [root@fc10-disk lv0]# sysbench --test=fileio prepare Sequential Read test (seqrd) รันคำสั่ง [root@fc10-disk ~]# sysbench --test=fileio --file-test-mode=seqrd run Sequential Write test (seqwr) รันคำสั่ง [root@fc10-disk ~]# sysbench --test=fileio [...]]]></description>
			<content:encoded><![CDATA[<p>ในตอนสุรปนี้ จะเพิ่มผลลัพธ์จากการรันคำสั่ง sysbench เพื่อทดสอบ fileio ทั้งการอ่านและเขียนไฟล์แบบ sequential, random</p>
<p><span id="more-774"></span></p>
<p>ก่อนการรัน sysbench เพื่อทดสอบ ต้องสร้างไฟล์ (prepare) ใน mount point ของ filesystem ที่ต้องการทดสอบ เช่นถ้า mount ไว้ที่ /mnt/lv0/ ต้อง cd เข้าไปในพาธนี้แล้วรันคำสั่ง</p>
<pre>[root@fc10-disk ~]# c<strong>d /mnt/lv0/
</strong>[root@fc10-disk lv0]# <strong>sysbench --test=fileio prepare</strong></pre>
<p><strong>Sequential Read test (seqrd) </strong>รันคำสั่ง</p>
<pre>[root@fc10-disk ~]# <strong>sysbench --test=fileio --file-test-mode=seqrd run</strong></pre>
<p><strong>Sequential Write test (seqwr) </strong>รันคำสั่ง</p>
<pre>[root@fc10-disk ~]# <strong>sysbench --test=fileio --file-test-mode=seqwr run</strong></pre>
<p><strong>Random Read test (rndrd)</strong> รันคำสั่ง</p>
<pre>[root@fc10-disk ~]# <strong>sysbench --test=fileio --file-test-mode=rndrd run</strong></pre>
<p><strong>Random Write test (rndwr)</strong> รันคำสั่ง</p>
<pre>[root@fc10-disk ~]# s<strong>ysbench --test=fileio --file-test-mode=rndwr run</strong></pre>
<p>ผลลัพธ์การรันคำสั่ง dd ในตอนที่ผ่านมา จะใกล้เคียงกับการรัน Sequential Write test</p>
<p>ตารางสรุปผลการทดสอบ</p>
<table style="width: 581pt; border-collapse: collapse;" border="0" cellspacing="0" cellpadding="0" width="777">
<colgroup span="1">
<col style="width: 83pt;" span="7" width="111"></col>
</colgroup>
<tbody>
<tr style="height: 16.05pt;" height="21">
<td class="xl24" style="border: 0.5pt none #ece9d8; background-color: #003300; width: 83pt; height: 16.05pt;" width="111" height="21"></td>
<td class="xl25" style="background-color: #003300; width: 83pt; border: 0.5pt 0.5pt 0.5pt medium none #ece9d8;" width="111" align="right"><strong><span style="color: #ffffff; font-size: x-small;">/dev/sdc1</span></strong></td>
<td class="xl25" style="background-color: #003300; width: 83pt; border: 0.5pt 0.5pt 0.5pt medium none #ece9d8;" width="111" align="right"><strong><span style="color: #ffffff; font-size: x-small;">/dev/sdd1</span></strong></td>
<td class="xl25" style="background-color: #003300; width: 83pt; border: 0.5pt 0.5pt 0.5pt medium none #ece9d8;" width="111" align="right"><strong><span style="color: #ffffff; font-size: x-small;">mdadm linear</span></strong></td>
<td class="xl25" style="background-color: #003300; width: 83pt; border: 0.5pt 0.5pt 0.5pt medium none #ece9d8;" width="111" align="right"><strong><span style="color: #ffffff; font-size: x-small;">mdadm stripe</span></strong></td>
<td class="xl25" style="background-color: #003300; width: 83pt; border: 0.5pt 0.5pt 0.5pt medium none #ece9d8;" width="111" align="right"><strong><span style="color: #ffffff; font-size: x-small;">LVM linear</span></strong></td>
<td class="xl25" style="background-color: #003300; width: 83pt; border: 0.5pt 0.5pt 0.5pt medium none #ece9d8;" width="111" align="right"><strong><span style="color: #ffffff; font-size: x-small;">LVM stripe</span></strong></td>
</tr>
<tr style="height: 16.05pt;" height="21">
<td class="xl26" style="background-color: #ccffcc; height: 16.05pt; border: medium 0.5pt 0.5pt none #ece9d8;" height="21"><span style="font-size: x-small;">xfs (blocks)</span></td>
<td class="xl27" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">195,263,012</span></td>
<td class="xl27" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">195,263,012</span></td>
<td class="xl27" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">390,585,600</span></td>
<td class="xl27" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">390,585,344</span></td>
<td class="xl27" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">390,578,176</span></td>
<td class="xl27" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">390,577,152</span></td>
</tr>
<tr style="height: 16.05pt;" height="21">
<td class="xl26" style="background-color: #ccffcc; height: 16.05pt; border: medium 0.5pt 0.5pt none #ece9d8;" height="21"><span style="font-size: x-small;">dd (MB/s)</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">52.00</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">47.10</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">52.70</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">96.50</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">51.80</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">94.80</span></td>
</tr>
<tr style="height: 16.05pt;" height="21">
<td class="xl26" style="background-color: #ccffcc; height: 16.05pt; border: medium 0.5pt 0.5pt none #ece9d8;" height="21"><span style="font-size: x-small;">seqrd (MB/s)</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">58.08</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">60.71</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">57.71</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">115.78</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">58.22</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">104.64</span></td>
</tr>
<tr style="height: 16.05pt;" height="21">
<td class="xl26" style="background-color: #ccffcc; height: 16.05pt; border: medium 0.5pt 0.5pt none #ece9d8;" height="21"><span style="font-size: x-small;">seqrw (MB/s)</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">43.76</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">38.96</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">46.89</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">85.04</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">47.92</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">84.15</span></td>
</tr>
<tr style="height: 16.05pt;" height="21">
<td class="xl26" style="background-color: #ccffcc; height: 16.05pt; border: medium 0.5pt 0.5pt none #ece9d8;" height="21"><span style="font-size: x-small;">rndrd (MB/s)</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">3.92</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">3.96</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">3.92</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">4.34</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">3.97</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">4.31</span></td>
</tr>
<tr style="height: 16.05pt;" height="21">
<td class="xl26" style="background-color: #ccffcc; height: 16.05pt; border: medium 0.5pt 0.5pt none #ece9d8;" height="21"><span style="font-size: x-small;">rndwr (MB/s)</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">0.61</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">0.69</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">2.88</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">2.08</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">2.91</span></td>
<td class="xl28" style="BORDER-BOTTOM: #ece9d8 0.5pt; BORDER-LEFT: #ece9d8; BACKGROUND-COLOR: #ccffcc; BORDER-TOP: #ece9d8; BORDER-RIGHT: #ece9d8 0.5pt" align="right"><span style="font-size: x-small;">2.08</span></td>
</tr>
</tbody>
</table>
<p>คงไม่สรุปใดๆ ทั้งสิ้น เกี่ยวกับผลลัพธ์ที่ได้ ว่าคอนฟิก mdadm หรือ lvm เร็วกว่ากัน เพราะตัวเลขออกมาใกล้เคียงกัน อีกทั้งการทดสอบนี้ อาจไม่ตรงกับหลักการทางสถิติ เช่น ทดลองรันไม่กี่ครั้ง หรือในขณะที่รันทดสอบอาจมี process อื่นๆ ในเครื่องรันขึ้นมาทำงาน (ทั้งๆ ที่พยายามลดให้เหลือน้อยที่สุดแล้ว) และด้วยคุณสมบัติของ mdadm และ LVM ที่แตกต่างกัน ทางเลือกคงขึ้นอยู่กับลักษณะการใช้งานของแต่ละเครื่องว่าเป็นอย่างไร &#8230;</p>
<p>แต่&#8230;ถ้าให้เลือก ความเห็นส่วนตัว ผมเลือก LVM ครับ <img src='http://spalinux.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_1">เปรียบเทียบ RAID-0 จากคำสั่ง mdadm และ lvm ตอนที่ 1</a></li>
<li><a href="http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_2">เปรียบเทียบ RAID-0 จากคำสั่ง mdadm และ lvm ตอนที่ 2</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_3/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>เปรียบเทียบ RAID-0 จากคำสั่ง mdadm และ lvm ตอนที่ 2</title>
		<link>http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_2</link>
		<comments>http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_2#comments</comments>
		<pubDate>Sun, 07 Jun 2009 08:29:07 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Benchmark]]></category>
		<category><![CDATA[Disk]]></category>
		<category><![CDATA[Filesystem]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[RAID]]></category>
		<category><![CDATA[linear]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[stripe]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=762</guid>
		<description><![CDATA[ในตอนแรก เปรียบเทียบ RAID-0 จากคำสั่ง mdadm และ lvm ตอนที่ 1 เราได้ทดลองใช้คำสั่ง mdadm เพื่อคอนฟิกดิสก์เป็นแบบ linear และ stripe ซึ่งให้ผลลัพธ์ความเร็วในการเขียนข้อมูลแตกต่างกัน ในตอนนี้จะลองใช้คำสั่ง LVM บ้าง เพื่อสร้างคอนฟิกแบบ linear และ stripe เพื่อเป็นการเปรียบเทียบกัน สร้าง LVM Physical Volume และ Volume Group ก่อนอื่นเราต้องคอนฟิกดิสก์แต่ละพารทิชั่น ทำเป็น Physical Volume และ Volume Group สุดท้ายค่อยเลือกว่าจะสร้าง Logical Volume เป็นแบบ linear หรือ stripe [root@fc10-disk ~]# pvcreate /dev/sdc1 /dev/sdd1   Wiping software RAID md [...]]]></description>
			<content:encoded><![CDATA[<p>ในตอนแรก <a href="http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_1">เปรียบเทียบ RAID-0 จากคำสั่ง mdadm และ lvm ตอนที่ 1</a> เราได้ทดลองใช้คำสั่ง mdadm เพื่อคอนฟิกดิสก์เป็นแบบ linear และ stripe ซึ่งให้ผลลัพธ์ความเร็วในการเขียนข้อมูลแตกต่างกัน ในตอนนี้จะลองใช้คำสั่ง LVM บ้าง เพื่อสร้างคอนฟิกแบบ linear และ stripe เพื่อเป็นการเปรียบเทียบกัน</p>
<p><span id="more-762"></span></p>
<h4>สร้าง LVM Physical Volume และ Volume Group</h4>
<p>ก่อนอื่นเราต้องคอนฟิกดิสก์แต่ละพารทิชั่น ทำเป็น Physical Volume และ Volume Group สุดท้ายค่อยเลือกว่าจะสร้าง Logical Volume เป็นแบบ linear หรือ stripe</p>
<pre>[root@fc10-disk ~]# <strong>pvcreate /dev/sdc1 /dev/sdd1
</strong>  Wiping software RAID md superblock on /dev/sdc1
  Physical volume "/dev/sdc1" successfully created
  Wiping software RAID md superblock on /dev/sdd1
  Physical volume "/dev/sdd1" successfully created</pre>
<p>ตรวจสอบสถานะของ physical volume</p>
<pre>[root@fc10-disk ~]# <strong>pvdisplay
</strong>  "/dev/sdc1" is a new physical volume of "186.31 GB"
  --- NEW Physical volume ---
  PV Name               /dev/sdc1
  VG Name
  PV Size               186.31 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               ...</pre>
<pre>  "/dev/sdd1" is a new physical volume of "186.31 GB"
  --- NEW Physical volume ---
  PV Name               /dev/sdd1
  VG Name
  PV Size               186.31 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               ...</pre>
<p>คอนฟิกรวมทั้งสอง physical volume สร้างเป็น volume group เดียวกัน</p>
<pre>[root@fc10-disk ~]# <strong>vgcreate VG_1 /dev/sdc1 /dev/sdd1
</strong>  Volume group "VG_1" successfully created</pre>
<p>ตรวจสอบสถานะของ volume group</p>
<pre>[root@fc10-disk ~]# <strong>vgdisplay
</strong>  --- Volume group ---
  VG Name               VG_1
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               372.61 GB
  PE Size               4.00 MB
  Total PE              95388
  Alloc PE / Size       0 / 0
  Free  PE / Size       95388 / 372.61 GB
  VG UUID               ...</pre>
<h4>คำสั่ง lvcreate สร้าง logical volume แบบ linear</h4>
<p>คอนฟิกนี้จะใช้คำสั่ง lvcreate เพื่อสร้างดิสก์สองก้อนเป็นแบบ linear ซึ่งหลักการเขียนข้อมูลจะเหมือนกันคือ ข้อมูลจะถูกเขียนลงบนตัวแรกให้เต็มก่อนแล้วค่อยเขียนตัวถัดไป</p>
<p>การระบุออปชั่น &#8211;extents 100%free คือให้ใช้พื้นที่ทั้งหมดของ volume group สร้างเป็น logical volume</p>
<pre>[root@fc10-disk ~]# <strong>lvcreate --extents 100%free VG_1 --name LV_0
</strong>  Logical volume "LV_0" created</pre>
<p>ผลลัพธ์ที่ได้จะสร้าง logical volume ชื่อ /dev/VG_1/LV_0 ขึ้นมา ซึ่งเรานำมาสร้าง filesystem แล้วมา mount ใช้งานได้</p>
<p>รันคำสั่ง lvdisplay ตรวจสอบสถานะของดิสก์</p>
<pre>[root@fc10-disk ~]# <strong>lvdisplay --maps
</strong>  --- Logical volume ---
  LV Name                <span style="color: #0000ff;">/dev/VG_1/LV_0</span>
  VG Name                VG_1
  LV UUID                eOdh1C-nSw3-wLjd-fuPz-Y6HA-rNvU-nWaOfY
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                372.61 GB
  Current LE             95388
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0</pre>
<pre>  --- Segments ---
  Logical extent 0 to 47693:
    Type                <span style="color: #0000ff;">linear</span>
    Physical volume     <span style="color: #0000ff;">/dev/sdc1
</span>    Physical extents    0 to 47693</pre>
<pre>  Logical extent 47694 to 95387:
    Type                <span style="color: #0000ff;">linear</span>
    Physical volume     <span style="color: #0000ff;">/dev/sdd1
</span>    Physical extents    0 to 47693</pre>
<p>สร้าง filesystem เป็นแบบ xfs และ mount เข้ากับพาธที่สร้าง</p>
<pre>[root@fc10-disk ~]# <strong>mkfs.xfs -f /dev/VG_1/LV_0
</strong>[root@fc10-disk ~]# <strong>mkdir /mnt/lv0
</strong>[root@fc10-disk ~]# <strong>mount /dev/VG_1/LV_0 /mnt/lv0</strong></pre>
<p>ดูขนาดของ filesystem ที่สร้างได้</p>
<pre>[root@fc10-disk ~]# <strong>cd /mnt/lv0/
</strong>[root@fc10-disk lv0]# <strong>df -k .
</strong>Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VG_1-LV_0
                     <span style="color: #0000ff;">390578176</span>      4256 390573920   1% /mnt/lv0</pre>
<p>ทดสอบการเขียนไฟล์ขนาด 2 GB บนคอนฟิก &#8220;linear&#8221;</p>
<pre>[root@fc10-disk lv0]# <strong>dd if=/dev/zero of=file-2g.bin bs=1000000 count=2000
</strong>2000+0 records in
2000+0 records out
2000000000 bytes (2.0 GB) copied, 38.6144 s, <span style="color: #0000ff;">51.8 MB/s</span></pre>
<p>ความเร็วที่ได้จะใกล้เคียงกับการเขียนไฟล์ลงดิสก์ก้อนเดียว</p>
<p>ยกเลิกการ mount ดิสก์ และลบ logical volume แบบ linear</p>
<pre>[root@fc10-disk lv0]# <strong>cd
</strong>[root@fc10-disk ~]# <strong>umount /mnt/lv0
</strong>[root@fc10-disk ~]# <strong>lvremove /dev/VG_1/LV_0
</strong>Do you really want to remove active logical volume "LV_0"? [y/n]: <strong>y</strong>
  Logical volume "LV_0" successfully removed</pre>
<h4>คำสั่ง lvcreate สร้าง logical volume แบบ stripe</h4>
<p>คอนฟิกนี้จะใช้คำสั่ง lvcreate เพื่อสร้าง logical volume เป็นแบบ stripe เพื่อให้เวลาเขียนข้อมูลแยกการเขียนลงดิสก์ทั้งสองก้อนพร้อมๆ กัน ทำให้ความเร็วที่ได้เพิ่มขึ้น</p>
<p>ในที่นี้เราต้องระบุจำนวน stripe หรือจำนวนดิกส์ที่จะเขียนข้อมูลพร้อมๆ กัน ในที่นี้เรามี physical volume อยู่ 2 ก้อน ก็ระบุเป็นตัวเลข 2</p>
<pre>[root@fc10-disk ~]# <strong>lvcreate --extents 100%free <span style="color: #0000ff;">--stripes 2</span> VG_1 --name LV_0
</strong>  Using default stripesize 64.00 KB
  Logical volume "LV_0" created</pre>
<p>ตรวจสอบสถานะของ logical volume แบบ stripe</p>
<pre>[root@fc10-disk ~]# l<strong>vdisplay --maps
</strong>  --- Logical volume ---
  LV Name                <span style="color: #0000ff;">/dev/VG_1/LV_0
</span>  VG Name                VG_1
  LV UUID                JJuw2a-4C6O-4DED-jqCO-qTRF-iDw0-VPeatg
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                372.61 GB
  Current LE             95388
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     512
  Block device           253:0</pre>
<pre>  --- Segments ---
  Logical extent 0 to 95387:
    Type                <span style="color: #0000ff;">striped</span>
    Stripes             <span style="color: #0000ff;">2</span>
    Stripe size         64 KB
    Stripe 0:
      Physical volume   <span style="color: #0000ff;">/dev/sdc1
</span>      Physical extents  0 to 47693
    Stripe 1:
      Physical volume   <span style="color: #0000ff;">/dev/sdd1
</span>      Physical extents  0 to 47693</pre>
<p>สร้าง filesystem เป็นแบบ xfs และ mount เข้ากับพาธที่สร้างไว้</p>
<pre>[root@fc10-disk ~]# <strong>mkfs.xfs -f /dev/VG_1/LV_0
</strong>[root@fc10-disk ~]# <strong>mount /dev/VG_1/LV_0 /mnt/lv0</strong></pre>
<p>ดูขนาดของ filesystem ที่สร้างได้</p>
<pre>[root@fc10-disk ~]# <strong>cd /mnt/lv0/
</strong>[root@fc10-disk lv0]# <strong>df -k .
</strong>Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VG_1-LV_0
                     <span style="color: #0000ff;">390577152</span>      4640 390572512   1% /mnt/lv0</pre>
<p>ทดสอบการเขียนไฟล์ขนาด 2 GB บนคอนฟิก &#8220;linear&#8221;</p>
<pre>[root@fc10-disk lv0]# <strong>dd if=/dev/zero of=file-2g.bin bs=1000000 count=2000
</strong>2000+0 records in
2000+0 records out
2000000000 bytes (2.0 GB) copied, 21.0913 s, <span style="color: #0000ff;">94.8 MB/s</span></pre>
<p>ความเร็วที่ได้ใกล้เคียงกับผลรวมของความเร็วในการเขียนข้อมูลลงดิสก์แต่ละก้อน</p>
<p>ยกเลิกการ mount ดิสก์ และลบ logical volume แบบ &#8220;stripe&#8221;</p>
<pre>[root@fc10-disk lv0]# <strong>cd
</strong>[root@fc10-disk ~]# <strong>umount /mnt/lv0
</strong>[root@fc10-disk ~]# <strong>lvremove /dev/VG_1/LV_0
</strong>Do you really want to remove active logical volume "LV_0"? [y/n]: <strong>y</strong>
  Logical volume "LV_0" successfully removed</pre>
<h4>ลบ LVM Volume Group, Physical Volume</h4>
<p>หลังจากทดสอบเรียบร้อย ถ้าต้องการลบคอนฟิก LVM ออกสามารถทำได้ดังนี้</p>
<p>ใช้คำสั่ง vgremove เพื่อลบ Volume Group</p>
<pre>[root@fc10-disk ~]# <strong>vgremove /dev/VG_1
</strong>  Volume group "VG_1" successfully removed</pre>
<p>ใช้คำสั่ง pvremove เพื่อลบ physical volume</p>
<pre>[root@fc10-disk ~]# <strong>pvremove /dev/sdc1 /dev/sdd1
</strong>  Labels on physical volume "/dev/sdc1" successfully wiped
  Labels on physical volume "/dev/sdd1" successfully wiped</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_1">เปรียบเทียบ RAID-0 จากคำสั่ง mdadm และ lvm ตอนที่ 1</a></li>
<li><a href="http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_3">เปรียบเทียบ RAID-0 จากคำสั่ง mdadm และ lvm ตอนที่ 3<br />
</a></li>
<li><a href="http://spalinux.com/2008/05/use_lvm_to_manage_disk_part1">การใช้งาน LVM เพื่อจัดการพื้นที่ฮาร์ดดิสก์ ตอนที่ 1</a></li>
<li><a href="http://spalinux.com/2008/05/use_lvm_to_manage_disk_part2">การใช้งาน LVM เพื่อจัดการพื้นที่ฮาร์ดดิสก์ ตอนที่ 2</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เปรียบเทียบ RAID-0 จากคำสั่ง mdadm และ lvm ตอนที่ 1</title>
		<link>http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_1</link>
		<comments>http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_1#comments</comments>
		<pubDate>Sun, 07 Jun 2009 07:08:15 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Benchmark]]></category>
		<category><![CDATA[Disk]]></category>
		<category><![CDATA[Filesystem]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[RAID]]></category>
		<category><![CDATA[linear]]></category>
		<category><![CDATA[raid-0]]></category>
		<category><![CDATA[stripe]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=755</guid>
		<description><![CDATA[เกิดความสงสัยขึ้นมา ขณะคอนฟิกเซิร์ฟเวอร์ที่มีดิสก์หลายๆ ก้อน เพื่อทำหน้าที่เป็น file server ว่า ระหว่างการใช้ mdadm และ lvm เพื่อรวมดิสก์แต่ละก้อนเข้าด้วยกันทำเป็น RAID-0 อย่างไหนจะเร็วกว่ากัน เลยทดสอบและนำผลลัพธ์แต่ละคอนฟิกมาเปรียบเทียบกัน และเพื่อความครบถ้วนของการเปรียบเทียบ เลยทดสอบคอนฟิกทั้งเป็นแบบ linear และ stripe (RAID-0) จากการใช้คำสั่งทั้งสองด้วย โดยแยกเป็นสองบทความ ในตอนแรกจะใช้คำสั่ง mdadm ก่อน หมายเหตุ โดยทั่วไป คำว่า RAID-0 หมายถึงการคอนฟิกแบบ stripe ข้อควรระวังการเลือกใช้คอนฟิก RAID-0 เพียงอย่างเดียว ถ้าดิสก์ก้อนใดก้อนนึงเสียไป มีโอกาสทำให้ข้อมูลบางส่วนหรือทั้งหมดเสียหายได้ โดยทั่วไปนิยมคอนฟิก RAID-0 ทับไปบนคอนฟิก RAID-1 หรือ RAID-5 เพื่อทำเป็น RAID-10, หรือ RAID-50 ความเสียหายของข้อมูลเมื่อดิสก์ก้อนหนึ่งเสีย ในการคอนฟิกแต่ละแบบจะไม่เหมือนกันเช่น ถ้าคอนฟิกเป็นแบบ &#8220;linear&#8221; การกู้ข้อมูลกลับคืนมาจะมีโอกาสมากกว่า เพราะข้อมูลส่วนใหญ่จะถูกเขียนลงบนดิสก์ก้อนเดียว แต่ข้อเสียของ &#8220;linear&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>เกิดความสงสัยขึ้นมา ขณะคอนฟิกเซิร์ฟเวอร์ที่มีดิสก์หลายๆ ก้อน เพื่อทำหน้าที่เป็น file server ว่า ระหว่างการใช้ mdadm และ lvm เพื่อรวมดิสก์แต่ละก้อนเข้าด้วยกันทำเป็น RAID-0 อย่างไหนจะเร็วกว่ากัน เลยทดสอบและนำผลลัพธ์แต่ละคอนฟิกมาเปรียบเทียบกัน</p>
<p>และเพื่อความครบถ้วนของการเปรียบเทียบ เลยทดสอบคอนฟิกทั้งเป็นแบบ linear และ stripe (RAID-0) จากการใช้คำสั่งทั้งสองด้วย โดยแยกเป็นสองบทความ ในตอนแรกจะใช้คำสั่ง mdadm ก่อน</p>
<p><span id="more-755"></span></p>
<p>หมายเหตุ</p>
<ul>
<li>โดยทั่วไป คำว่า RAID-0 หมายถึงการคอนฟิกแบบ stripe</li>
<li><span style="color: #ff0000;">ข้อควรระวังการเลือกใช้คอนฟิก RAID-0 เพียงอย่างเดียว ถ้าดิสก์ก้อนใดก้อนนึงเสียไป มีโอกาสทำให้ข้อมูลบางส่วนหรือทั้งหมดเสียหายได้</span> โดยทั่วไปนิยมคอนฟิก RAID-0 ทับไปบนคอนฟิก RAID-1 หรือ RAID-5 เพื่อทำเป็น RAID-10, หรือ RAID-50</li>
<li>ความเสียหายของข้อมูลเมื่อดิสก์ก้อนหนึ่งเสีย ในการคอนฟิกแต่ละแบบจะไม่เหมือนกันเช่น ถ้าคอนฟิกเป็นแบบ &#8220;linear&#8221; การกู้ข้อมูลกลับคืนมาจะมีโอกาสมากกว่า เพราะข้อมูลส่วนใหญ่จะถูกเขียนลงบนดิสก์ก้อนเดียว แต่ข้อเสียของ &#8220;linear&#8221; คือความเร็วในการเขียนข้อมูลจะน้อยกว่าแบบ &#8220;stripe&#8221;</li>
</ul>
<h4>ทดสอบดิสก์แต่ละก้อน</h4>
<p>ก่อนจะเริ่มคอนฟิก RAID-0 ขอเริ่มทดสอบดิสก์ทีละตัว เพื่อดูความเร็วคร่าวๆ ในการเขียนข้อมูล</p>
<p>ตัวอย่างการสร้างพาร์ทิชั่นของดิสก์แต่ละก้อน</p>
<pre>[root@fc10-disk ~]# <strong>fdisk -l /dev/sdc
</strong>...
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1       24321   195358401   83  Linux</pre>
<pre>[root@fc10-disk ~]# <strong>fdisk -l /dev/sdd
</strong>...
   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1       24321   195358401   83  Linux</pre>
<p>สร้าง filesystem เป็นแบบ xfs ในแต่ละพาร์ทิชั่น และ mount เข้ากับพาธที่สร้าง</p>
<pre>[root@fc10-disk ~]# <strong>mkfs.xfs -f /dev/sdc1
</strong>[root@fc10-disk ~]# <strong>mkfs.xfs -f /dev/sdd1</strong></pre>
<pre>[root@fc10-disk ~]# <strong>mkdir /mnt/sdc1
</strong>[root@fc10-disk ~]# <strong>mkdir /mnt/sdd1
</strong>[root@fc10-disk ~]# <strong>mount /dev/sdc1 /mnt/sdc1
</strong>[root@fc10-disk ~]# <strong>mount /dev/sdd1 /mnt/sdd1</strong></pre>
<p>ทดสอบการเขียนไฟล์ขนาด 2 GB ในแต่ละพาร์ทิชั่น</p>
<pre>[root@fc10-disk sdc1]# <strong>cd /mnt/sdc1/
</strong>[root@fc10-disk sdc1]# <strong>dd if=/dev/zero of=file-2g.bin bs=1000000 count=2000
</strong>2000+0 records in
2000+0 records out
2000000000 bytes (2.0 GB) copied, 38.4796 s, <span style="color: #0000ff;">52.0 MB/s</span></pre>
<pre>[root@fc10-disk sdd1]# <strong>cd /mnt/sdd1/
</strong>[root@fc10-disk sdd1]# <strong>dd if=/dev/zero of=file-2g.bin bs=1000000 count=2000
</strong>2000+0 records in
2000+0 records out
2000000000 bytes (2.0 GB) copied, 42.4467 s, <span style="color: #0000ff;">47.1 MB/s</span></pre>
<p>ได้ความเร็วประมาณ 50 MB/s</p>
<p>ยกเลิกการ mount ดิสก์แต่ละก้อน</p>
<pre>[root@fc10-disk sdd1]# <strong>cd</strong>
[root@fc10-disk ~]# <strong>umount /mnt/sdc1
</strong>[root@fc10-disk ~]# <strong>umount /mnt/sdd1</strong></pre>
<h4>คำสั่ง mdadm สร้างดิสก์แบบ linear</h4>
<p>คอนฟิกแรกจะใช้คำสั่ง mdadm เพื่อสร้างดิสก์เป็นแบบ &#8220;linear&#8221; ซึ่งเป็นการนำพื้นที่ดิสก์ทั้งสองก้อนมาต่อเรียงกัน เวลาเขียนข้อมูลจะเขียนบนดิสก์ตัวเดียวก่อน ถ้าก้อนแรกเต็มถึงจะเขียนดิสก์อีกก้อน</p>
<pre>[root@fc10-disk ~]# <strong>mdadm --create --verbose /dev/md0 <span style="color: #0000ff;">--level=linear </span>--raid-devices=2 /dev/sdc1 /dev/sdd1
</strong>mdadm: chunk size defaults to 64K
mdadm: array /dev/md0 started.</pre>
<p>ตรวจสอบสถานะของดิสก์</p>
<pre>[root@fc10-disk ~]#<strong> mdadm --detail /dev/md0
</strong><span style="color: #0000ff;">/dev/md0</span>:
        Version : 0.90
  Creation Time : Sun Jun  7 12:35:05 2009
<span style="color: #0000ff;">     Raid Level : linear
</span>     Array Size : 390716672 (372.62 GiB 400.09 GB)
   Raid Devices : 2
  Total Devices : 2
Preferred Minor : 0
    Persistence : Superblock is persistent</pre>
<pre>    Update Time : Sun Jun  7 12:35:05 2009
          State : clean
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0</pre>
<pre>       Rounding : 64K</pre>
<pre>           UUID : 450c959b:c5d34b87:792b422a:65152846
         Events : 0.1</pre>
<pre>    Number   Major   Minor   RaidDevice State
<span style="color: #0000ff;">       0       8       33        0      active sync   /dev/sdc1
       1       8       49        1      active sync   /dev/sdd1
</span></pre>
<p>สร้าง filesystem เป็นแบบ xfs และ mount เข้ากับพาธที่สร้าง</p>
<pre>[root@fc10-disk ~]# <strong>mkfs.xfs -f /dev/md0
</strong>[root@fc10-disk ~]# <strong>mkdir /mnt/md0
</strong>[root@fc10-disk ~]# <strong>mount /dev/md0 /mnt/md0/</strong></pre>
<pre>ดูขนาด filesystem ที่สร้างได้</pre>
<pre>[root@fc10-disk ~]# <strong>cd /mnt/md0/
</strong>[root@fc10-disk md0]# <strong>df -k .
</strong>Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/md0             <span style="color: #0000ff;">390585600</span>      4256 390581344   1% /mnt/md0</pre>
<p>ทดสอบการเขียนไฟล์ขนาด 2 GB บนคอนฟิก &#8220;linear&#8221;</p>
<pre>[root@fc10-disk md0]# <strong>dd if=/dev/zero of=file-2g.bin bs=1000000 count=2000
</strong>2000+0 records in
2000+0 records out
2000000000 bytes (2.0 GB) copied, 37.9349 s, <span style="color: #0000ff;">52.7 MB/s</span></pre>
<p>ความเร็วที่ได้จะใกล้เคียงกับการเขียนไฟล์ลงดิสก์ก้อนเดียว</p>
<p>ยกเลิกการ mount ดิสก์ และปิด (stop) การใช้ดิสก์แบบ linear</p>
<pre>[root@fc10-disk md0]# <strong>cd</strong>
[root@fc10-disk ~]# <strong>umount /mnt/md0
</strong>[root@fc10-disk ~]# <strong>mdadm --stop /dev/md0
</strong>mdadm: stopped /dev/md0
[root@fc10-disk ~]# <strong>cat /proc/mdstat
</strong>Personalities : [linear]
unused devices: &lt;none&gt;</pre>
<h4>คำสั่ง mdadm สร้างดิสก์แบบ  stripe (RAID-0)</h4>
<p>คอนฟิกที่สอง จะใช้คำสั่ง mdadm เพื่อคอนฟิกดิกส์สองกันเป็นแบบ stripe หรือ RAID-0 เวลาเขียนข้อมูลจะเขียนลงบนดิสก์ทั้งสองก้อนพร้อมกัน ทำให้ความเร็วเพิ่มขึ้น</p>
<p>หมายเหตุ การระบุออปชั่น &#8220;&#8211;level&#8221; เป็นแบบ &#8220;stripe&#8221; หรือ &#8220;raid-0&#8243;  ให้ผลเหมือนกัน</p>
<pre>[root@fc10-disk ~]# <strong>mdadm --create --verbose /dev/md0 <span style="color: #0000ff;">--level=stripe</span> --raid-devices=2 /dev/sdc1 /dev/sdd1
</strong>mdadm: chunk size defaults to 64K
mdadm: /dev/sdc1 appears to be part of a raid array:
    level=linear devices=2 ctime=Sun Jun  7 13:28:06 2009
mdadm: /dev/sdd1 appears to be part of a raid array:
    level=linear devices=2 ctime=Sun Jun  7 13:28:06 2009
Continue creating array? <strong>y</strong>
mdadm: array /dev/md0 started.</pre>
<p>ตรวจสอบสถานะของดิสก์</p>
<pre>[root@fc10-disk ~]# <strong>mdadm --detail /dev/md0</strong>
<span style="color: #0000ff;">/dev/md0</span>:
        Version : 0.90
  Creation Time : Sun Jun  7 13:40:02 2009
<span style="color: #0000ff;">     Raid Level : raid0
</span>     Array Size : 390716672 (372.62 GiB 400.09 GB)
   Raid Devices : 2
  Total Devices : 2
Preferred Minor : 0
    Persistence : Superblock is persistent</pre>
<pre>    Update Time : Sun Jun  7 13:40:02 2009
          State : clean
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0</pre>
<pre>     Chunk Size : 64K</pre>
<pre>           UUID : 1ee50769:2becc762:fb9a3596:c284b115
         Events : 0.1</pre>
<pre>    Number   Major   Minor   RaidDevice State
<span style="color: #0000ff;">       0       8       33        0      active sync   /dev/sdc1
       1       8       49        1      active sync   /dev/sdd1
</span></pre>
<p>สร้าง filesystem เป็นแบบ xfs และ mount เข้ากับพาธที่สร้างไว้</p>
<pre>[root@fc10-disk ~]# <strong>mkfs.xfs -f /dev/md0
</strong>[root@fc10-disk ~]# <strong>mount /dev/md0 /mnt/md0/</strong></pre>
<pre>ดูขนาด filesystem ที่สร้างได้</pre>
<pre>[root@fc10-disk ~]# <strong>cd /mnt/md0/
</strong>[root@fc10-disk md0]# <strong>df -k .
</strong>Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/md0             <span style="color: #0000ff;">390585344</span>      4640 390580704   1% /mnt/md0</pre>
<p>ทดสอบความเร็วการเขียนข้อมูลบนดิสก์ RAID-0</p>
<pre>[root@fc10-disk md0]# <strong>dd if=/dev/zero of=file-2g.bin bs=1000000 count=2000
</strong>2000+0 records in
2000+0 records out
2000000000 bytes (2.0 GB) copied, 20.7292 s, <span style="color: #0000ff;">96.5 MB/s</span></pre>
<p>ความเร็วที่ได้ใกล้เคียงกับผลรวมของความเร็วในการเขียนข้อมูลลงดิสก์แต่ละก้อน</p>
<p>ยกเลิกการ mount ดิสก์ และปิด (stop) การใช้ดิสก์แบบ &#8220;stripe&#8221;</p>
<pre>[root@fc10-disk md0]# <strong>cd
</strong>[root@fc10-disk ~]# <strong>umount /mnt/md0
</strong>[root@fc10-disk ~]# <strong>mdadm --stop /dev/md0
</strong>mdadm: stopped /dev/md0
[root@fc10-disk ~]# <strong>cat /proc/mdstat
</strong>Personalities : [linear] [raid0]
unused devices: &lt;none&gt;</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_2">เปรียบเทียบ RAID-0 จากคำสั่ง mdadm และ lvm ตอนที่ 2</a></li>
<li><a href="http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_3">เปรียบเทียบ RAID-0 จากคำสั่ง mdadm และ lvm ตอนที่ 3<br />
</a></li>
<li><a href="http://spalinux.com/2008/08/creating_software_raid_on_linux">การสร้าง Software RAID บนลินุกซ์</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/06/compare_raid-0_between_mdadm_and_lvm_part_1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>คอมไพล์ sysbench บน Fedora 10</title>
		<link>http://spalinux.com/2009/05/%e0%b8%84%e0%b8%ad%e0%b8%a1%e0%b9%84%e0%b8%9e%e0%b8%a5%e0%b9%8c-sysbench-%e0%b8%9a%e0%b8%99-fedora-10</link>
		<comments>http://spalinux.com/2009/05/%e0%b8%84%e0%b8%ad%e0%b8%a1%e0%b9%84%e0%b8%9e%e0%b8%a5%e0%b9%8c-sysbench-%e0%b8%9a%e0%b8%99-fedora-10#comments</comments>
		<pubDate>Sat, 16 May 2009 10:40:35 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Benchmark]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Filesystem]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[sysbench]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=656</guid>
		<description><![CDATA[SysBench เป็นโปรแกรมที่ใช้วัดประสิทธิภาพ (benchmark) ของเครื่องได้หลายอย่าง ทั้ง CPU, Memory, Disk และ Database ทั้งนี้ยังสามารถระบุออปชั่นสำหรับการทดสอบได้เช่น จำนวน thread ที่รัน ขนาดที่จะทดสอบ ระยะเวลาที่ใช้ในการรัน เราสามารถนำผลลัพธ์ที่ได้มาเปรียบเทียบเพื่อการตัดสินใจเลือกซื้อ ปรับแต่งเครื่อง หรือแก้ไขคอนฟิกให้ระบบทำงานได้ดีขึ้น เนื่องจากในแผ่นติดั้ง หรือ จาก Fedora 10 Everything ไม่มีโปรแกรม sysbench ในรูปแบบ rpm ทำให้การที่จะใช้โปรแกรมนี้ได้ ในบทความนี้ขอนำเสนอขั้นตอนและวิธีการคอมไพล์โปรแกรม sysbench และติดตั้งเอง หมายเหตุ เครื่องที่จะคอมไพล์ source file ได้นั้น จำเป็นต้องติดตั้ง package ประเภท development ด้วย ดาวน์โหลดไฟล์ เวอร์ชั่นล่าสุดตอนที่เขียนบทความนี้ (16 May 2009) คือ sysbench-0.4.12 สามารถดาวน์โหลดได้ที่ Download sysbench &#8211; SourceForge.net: [...]]]></description>
			<content:encoded><![CDATA[<p>SysBench เป็นโปรแกรมที่ใช้วัดประสิทธิภาพ (benchmark) ของเครื่องได้หลายอย่าง ทั้ง CPU, Memory, Disk และ Database ทั้งนี้ยังสามารถระบุออปชั่นสำหรับการทดสอบได้เช่น จำนวน thread ที่รัน ขนาดที่จะทดสอบ ระยะเวลาที่ใช้ในการรัน</p>
<p>เราสามารถนำผลลัพธ์ที่ได้มาเปรียบเทียบเพื่อการตัดสินใจเลือกซื้อ ปรับแต่งเครื่อง หรือแก้ไขคอนฟิกให้ระบบทำงานได้ดีขึ้น</p>
<p>เนื่องจากในแผ่นติดั้ง หรือ จาก Fedora 10 Everything ไม่มีโปรแกรม sysbench ในรูปแบบ rpm ทำให้การที่จะใช้โปรแกรมนี้ได้ ในบทความนี้ขอนำเสนอขั้นตอนและวิธีการคอมไพล์โปรแกรม sysbench และติดตั้งเอง</p>
<p><span id="more-656"></span></p>
<p>หมายเหตุ เครื่องที่จะคอมไพล์ source file ได้นั้น จำเป็นต้องติดตั้ง package ประเภท development ด้วย</p>
<h4>ดาวน์โหลดไฟล์</h4>
<p>เวอร์ชั่นล่าสุดตอนที่เขียนบทความนี้ (16 May 2009) คือ sysbench-0.4.12 สามารถดาวน์โหลดได้ที่ <a href="http://sourceforge.net/project/showfiles.php?group_id=102348&amp;package_id=109810" target="_blank">Download sysbench &#8211; SourceForge.net: System performance benchmark: Files</a></p>
<h4>แตกไฟล์ (extract) ใน /usr/local/src/</h4>
<p>โปรแกรมที่นำมาคอมไพล์และติดตั้งเอง แนะนำให้ไว้ใน /usr/local/ เพราะเวลาปรับปรุง หรือติดตั้งใหม่ จะได้สะดวกต่อการอ้างอิงและค้นหา ในที่นี้จะไว้ใน /usr/local/src/ เพื่อเก็บ source file และไฟล์ที่ใช้ระหว่างการคอมไพล์โปรแกรม</p>
<pre>[root@fc10-dev ~]# <strong>cp sysbench-0.4.12.tar.gz /usr/local/src/</strong>
[root@fc10-dev ~]# <strong>cd /usr/local/src/
</strong>[root@fc10-dev src]# <strong>ls -l
</strong>total 420
-rw-r--r-- 1 root root 421932 2009-05-16 17:02 sysbench-0.4.12.tar.gz</pre>
<p>ใช้คำสั่ง tar เพื่อแตกไฟล์</p>
<pre>[root@fc10-dev src]# <strong>tar zxvf sysbench-0.4.12.tar.gz
</strong>sysbench-0.4.12/
sysbench-0.4.12/configure
sysbench-0.4.12/TODO
sysbench-0.4.12/missing
sysbench-0.4.12/INSTALL
sysbench-0.4.12/autogen.sh
sysbench-0.4.12/Makefile.in
sysbench-0.4.12/README
sysbench-0.4.12/Makefile.am
sysbench-0.4.12/README-WIN.txt
...
...
...
sysbench-0.4.12/sysbench/sysbench.h
sysbench-0.4.12/sysbench/sb_options.h
sysbench-0.4.12/sysbench/sb_list.h
sysbench-0.4.12/sysbench/sb_logger.h
sysbench-0.4.12/sysbench/sb_logger.c
sysbench-0.4.12/sysbench/sb_options.c
sysbench-0.4.12/sysbench/sb_timer.c
sysbench-0.4.12/sysbench/sb_timer.h
sysbench-0.4.12/sysbench/CMakeLists.txt
sysbench-0.4.12/sysbench/sb_win.c</pre>
<p>ใช้คำสั่ง cd เข้าไปในไดเร็คทอรี ใช้คำสั่ง ls เพื่อดูไฟล์</p>
<pre>[root@fc10-dev src]# cd sysbench-0.4.12/
[root@fc10-dev sysbench-0.4.12]# ls
acinclude.m4  autogen.sh  config     configure.ac  doc      install-sh   Makefile.in  mkinstalldirs  README-WIN.txt  TODO
aclocal.m4    ChangeLog   configure  COPYING       INSTALL  Makefile.am  missing      README         sysbench</pre>
<h4>รัน ./configure</h4>
<p>รัน ./configure เพื่อตรวจสอบไฟล์ต่างๆ ที่จำเป็นในการคอนไพล์โปรแกรม และสร้าง Makefile สำหรับคอมไพล์โปรแกรม</p>
<pre>[root@fc10-dev sysbench-0.4.12]# <strong>./configure
</strong>checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to compile with MySQL support... (cached) yes
checking whether to compile with Oracle support... (cached) no
checking whether to compile with PostgreSQL support... (cached) no
checking for style of include used by make... GNU
checking for gcc... gcc
...
...
...
checking for cc_r... gcc
checking for sqrt in -lm... yes
checking for mysql_config... no
<span style="color: #ff0000;">configure: error: mysql_config executable not found
********************************************************************************
ERROR: cannot find MySQL libraries. If you want to compile with MySQL support,
       you must either specify file locations explicitly using
       --with-mysql-includes and --with-mysql-libs options, or make sure path to
       mysql_config is listed in your PATH environment variable. If you want to
       disable MySQL support, use --without-mysql option.
********************************************************************************</span></pre>
<pre>[root@fc10-dev sysbench-0.4.12]#</pre>
<p>ถ้าเจอข้อความฟ้องเตือน error แปลว่าขาดไฟล์ที่ต้องใช้  จำเป็นต้องติดตั้งไฟล์เพิ่มเติมก่อน แล้วรัน ./configure อีกครั้ง</p>
<p><span style="color: #808080;">แต่ถ้าในกรณีเราไม่ต้องการใช้โปรแกรม sysbench เพื่อทดสอบประสิทธิภาพของ mysql สามารถรัน ./configure ตามด้วยออปชั่น &#8211;without-mysql ก็รัน ./configure ผ่านได้</span></p>
<pre><span style="color: #808080;">[root@fc10-dev sysbench-0.4.12]# </span><span style="color: #808080;"><strong>./configure --without-mysql
</strong>checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to compile with MySQL support... (cached) no
checking whether to compile with Oracle support... (cached) no
checking whether to compile with PostgreSQL support... (cached) no
checking for style of include used by make... GNU
checking for gcc... gcc
...
...
...
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/xsl/Makefile
config.status: creating doc/xsl/catalog.xml
config.status: creating doc/Makefile
config.status: creating sysbench/Makefile
config.status: creating sysbench/drivers/Makefile
config.status: creating sysbench/drivers/mysql/Makefile
config.status: creating sysbench/drivers/oracle/Makefile
config.status: creating sysbench/drivers/pgsql/Makefile
config.status: creating sysbench/tests/Makefile
config.status: creating sysbench/tests/cpu/Makefile
config.status: creating sysbench/tests/fileio/Makefile
config.status: creating sysbench/tests/memory/Makefile
config.status: creating sysbench/tests/threads/Makefile
config.status: creating sysbench/tests/mutex/Makefile
config.status: creating sysbench/tests/oltp/Makefile
config.status: creating config/config.h
config.status: executing depfiles commands
config.status: executing libtool commands
[root@fc10-dev sysbench-0.4.12]#</span></pre>
<p>ข้อความ error ด้านบน &#8220;<span style="color: #ff0000;">configure: error: mysql_config executable not found</span>&#8221; หมายถึงเครื่องนี้ไม่มีไฟล์ mysql_config ซึ่งได้จากการติดตั้ง mysql</p>
<p>สามารถติดตั้ง mysql เพิ่มเติม จากแผ่น DVD ติดตั้ง ใส่แผ่น DVD ใช้คำสั่ง mount เพื่อติดตั้งไฟล์ package ของ mysql</p>
<pre>[root@fc10-dev sysbench-0.4.12]# <strong>mount /dev/scd0 /media/
</strong>mount: block device /dev/sr0 is write-protected, mounting read-only
[root@fc10-dev sysbench-0.4.12]# <strong>cd /media/Packages/</strong></pre>
<pre>[root@fc10-dev Packages]# <strong>rpm -i mysql-libs-5.0.67-2.fc10.x86_64.rpm
</strong>[root@fc10-dev Packages]# <strong>rpm -i perl-DBI-1.607-1.fc10.x86_64.rpm
</strong>[root@fc10-dev Packages]# <strong>rpm -i mysql-5.0.67-2.fc10.x86_64.rpm</strong></pre>
<pre>[root@fc10-dev Packages]# <strong>cd -
</strong>/usr/local/src/sysbench-0.4.12
[root@fc10-dev sysbench-0.4.12]#</pre>
<p>รัน ./configure อีกครั้ง</p>
<pre>[root@fc10-dev sysbench-0.4.12]# <strong>./configure
</strong>checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to compile with MySQL support... (cached) yes
checking whether to compile with Oracle support... (cached) no
checking whether to compile with PostgreSQL support... (cached) no
checking for style of include used by make... GNU
checking for gcc... gcc
...
...
...
configure: creating ./config.status
config.status: creating Makefile
config.status: creating doc/xsl/Makefile
config.status: creating doc/xsl/catalog.xml
config.status: creating doc/Makefile
config.status: creating sysbench/Makefile
config.status: creating sysbench/drivers/Makefile
config.status: creating sysbench/drivers/mysql/Makefile
config.status: creating sysbench/drivers/oracle/Makefile
config.status: creating sysbench/drivers/pgsql/Makefile
config.status: creating sysbench/tests/Makefile
config.status: creating sysbench/tests/cpu/Makefile
config.status: creating sysbench/tests/fileio/Makefile
config.status: creating sysbench/tests/memory/Makefile
config.status: creating sysbench/tests/threads/Makefile
config.status: creating sysbench/tests/mutex/Makefile
config.status: creating sysbench/tests/oltp/Makefile
config.status: creating config/config.h
config.status: executing depfiles commands
config.status: executing libtool commands
[root@fc10-dev sysbench-0.4.12]#</pre>
<p>ก่อนจะข้ามไปขั้นตอนต่อไปต้องดูผลลัพธ์ของ ./configure ด้วยว่ายังมี error ใดๆ อีกหรือไม่</p>
<h4>รัน make</h4>
<p>รัน make เพื่อเริ่มคอมไฟล์โปรแกรม</p>
<pre>[root@fc10-dev sysbench-0.4.12]# <strong>make
</strong>Making all in doc
make[1]: Entering directory `/usr/local/src/sysbench-0.4.12/doc'
Making all in xsl
make[2]: Entering directory `/usr/local/src/sysbench-0.4.12/doc/xsl'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/usr/local/src/sysbench-0.4.12/doc/xsl'
make[2]: Entering directory `/usr/local/src/sysbench-0.4.12/doc'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/usr/local/src/sysbench-0.4.12/doc'
make[1]: Leaving directory `/usr/local/src/sysbench-0.4.12/doc'
Making all in sysbench
make[1]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench'
Making all in drivers
make[2]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench/drivers'
Making all in mysql
make[3]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench/drivers/mysql'
gcc -DHAVE_CONFIG_H -I. -I../../../config  -I/usr/include/mysql  -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -D_REENTRANT -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -I../../../sysbench  -pthread -g -O2 -MT libsbmysql_a-drv_mysql.o -MD -MP -MF .deps/libsbmysql_a-drv_mysql.Tpo -c -o libsbmysql_a-drv_mysql.o `test -f 'drv_mysql.c' || echo './'`drv_mysql.c
<span style="color: #ff0000;">drv_mysql.c:35:19: error: mysql.h: No such file or directory
drv_mysql.c:36:26: error: mysqld_error.h: No such file or directory
</span>drv_mysql.c: In function ‘mysql_drv_describe’:
drv_mysql.c:284: error: ‘MYSQL_RES’ undeclared (first use in this function)
drv_mysql.c:284: error: (Each undeclared identifier is reported only once
drv_mysql.c:284: error: for each function it appears in.)
drv_mysql.c:284: error: ‘res’ undeclared (first use in this function)
drv_mysql.c:285: error: ‘MYSQL_ROW’ undeclared (first use in this function)
drv_mysql.c:285: error: expected ‘;’ before ‘row’
drv_mysql.c:286: error: ‘MYSQL_FIELD’ undeclared (first use in this function)
drv_mysql.c:286: error: ‘fields’ undeclared (first use in this function)
drv_mysql.c:328: error: ‘row’ undeclared (first use in this function)
drv_mysql.c: In function ‘mysql_drv_connect’:
drv_mysql.c:360: error: ‘MYSQL’ undeclared (first use in this function)
drv_mysql.c:360: error: ‘con’ undeclared (first use in this function)
drv_mysql.c:366: error: expected expression before ‘)’ token
drv_mysql.c:401: error: ‘MYSQL_VERSION_ID’ undeclared (first use in this function)
drv_mysql.c: In function ‘mysql_drv_disconnect’:
drv_mysql.c:441: error: ‘MYSQL’ undeclared (first use in this function)
drv_mysql.c:441: error: ‘con’ undeclared (first use in this function)
drv_mysql.c: In function ‘mysql_drv_bind_param’:
drv_mysql.c:520: error: ‘MYSQL’ undeclared (first use in this function)
drv_mysql.c:520: error: ‘con’ undeclared (first use in this function)
drv_mysql.c:520: error: expected expression before ‘)’ token
drv_mysql.c: In function ‘mysql_drv_query’:
drv_mysql.c:729: error: ‘MYSQL’ undeclared (first use in this function)
drv_mysql.c:729: error: ‘con’ undeclared (first use in this function)
drv_mysql.c:739: error: ‘ER_LOCK_DEADLOCK’ undeclared (first use in this function)
drv_mysql.c:739: error: ‘ER_LOCK_WAIT_TIMEOUT’ undeclared (first use in this function)
drv_mysql.c:739: error: ‘ER_CHECKREAD’ undeclared (first use in this function)
drv_mysql.c: In function ‘mysql_drv_store_results’:
drv_mysql.c:789: error: ‘MYSQL’ undeclared (first use in this function)
drv_mysql.c:789: error: ‘con’ undeclared (first use in this function)
drv_mysql.c:790: error: ‘MYSQL_RES’ undeclared (first use in this function)
drv_mysql.c:790: error: ‘res’ undeclared (first use in this function)
drv_mysql.c:791: error: ‘MYSQL_ROW’ undeclared (first use in this function)
drv_mysql.c:791: error: expected ‘;’ before ‘row’
drv_mysql.c:839: error: ‘ER_LOCK_DEADLOCK’ undeclared (first use in this function)
drv_mysql.c:839: error: ‘ER_LOCK_WAIT_TIMEOUT’ undeclared (first use in this function)
drv_mysql.c:855: error: ‘row’ undeclared (first use in this function)
drv_mysql.c: In function ‘mysql_drv_free_results’:
drv_mysql.c:879: error: ‘MYSQL_RES’ undeclared (first use in this function)
drv_mysql.c:879: error: expected expression before ‘)’ token
make[3]: *** [libsbmysql_a-drv_mysql.o] Error 1
make[3]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench/drivers/mysql'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench/drivers'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench'
make: *** [all-recursive] Error 1
[root@fc10-dev sysbench-0.4.12]#</pre>
<p>ถ้ามีข้อความ error ฟ้องเตือนขึ้นมา แสดงว่าคอมไพล์โปรแกรมไม่สำเร็จ ต้องทำการแก้ไข ส่วนมากคือขาดไฟล์ที่ต้องใช้ ในที่นี้</p>
<pre><span style="color: #ff0000;">drv_mysql.c:35:19: error: mysql.h: No such file or directory
drv_mysql.c:36:26: error: mysqld_error.h: No such file or directory</span></pre>
<p>แปลว่าขาดไฟล์ header ของ mysql ต้องติดตั้งเพิ่มเติม ไฟล์ header (mysql.h, mysqld_error.h) อยู่ใน package ชื่อ mysql-devel ซึ่งไม่มีอยู่ในแผ่นติดตั้ง DVD ต้องดาวน์โหลดเพิ่มเติมจาก  <a href="ftp://www.mirror.in.th./fedora/releases/10/Everything/x86_64/os/Packages/" target="_blank">FC10 Everything (x86_64)</a></p>
<pre>[root@fc10-dev sysbench-0.4.12]# <strong>cd ~
</strong>[root@fc10-dev ~]# <strong>rpm -i mysql-devel-5.0.67-2.fc10.x86_64.rpm</strong></pre>
<pre>[root@fc10-dev ~]# <strong>cd -</strong>
/usr/local/src/sysbench-0.4.12
[root@fc10-dev sysbench-0.4.12]#</pre>
<p>รันคำสั่ง make อีกครั้ง</p>
<pre>[root@fc10-dev sysbench-0.4.12]# <strong>make
</strong>Making all in doc
make[1]: Entering directory `/usr/local/src/sysbench-0.4.12/doc'
Making all in xsl
make[2]: Entering directory `/usr/local/src/sysbench-0.4.12/doc/xsl'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/usr/local/src/sysbench-0.4.12/doc/xsl'
make[2]: Entering directory `/usr/local/src/sysbench-0.4.12/doc'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/usr/local/src/sysbench-0.4.12/doc'
make[1]: Leaving directory `/usr/local/src/sysbench-0.4.12/doc'
Making all in sysbench
make[1]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench'
Making all in drivers
make[2]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench/drivers'
Making all in mysql
make[3]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench/drivers/mysql'
gcc -DHAVE_CONFIG_H -I. -I../../../config  -I/usr/include/mysql  -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -D_REENTRANT -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -I../../../sysbench  -pthread -g -O2 -MT libsbmysql_a-drv_mysql.o -MD -MP -MF .deps/libsbmysql_a-drv_mysql.Tpo -c -o libsbmysql_a-drv_mysql.o `test -f 'drv_mysql.c' || echo './'`drv_mysql.c
mv -f .deps/libsbmysql_a-drv_mysql.Tpo .deps/libsbmysql_a-drv_mysql.Po
rm -f libsbmysql.a
ar cru libsbmysql.a libsbmysql_a-drv_mysql.o
ranlib libsbmysql.a
make[3]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench/drivers/mysql'
make[3]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench/drivers'
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench/drivers'
make[2]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench/drivers'
Making all in tests
make[2]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench/tests'
Making all in cpu
make[3]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench/tests/cpu'
gcc -DHAVE_CONFIG_H -I. -I../../../config  -D_REENTRANT -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -I../../../sysbench  -pthread -g -O2 -MT libsbcpu_a-sb_cpu.o -MD -MP -MF .deps/libsbcpu_a-sb_cpu.Tpo -c -o libsbcpu_a-sb_cpu.o `test -f 'sb_cpu.c' || echo './'`sb_cpu.c
mv -f .deps/libsbcpu_a-sb_cpu.Tpo .deps/libsbcpu_a-sb_cpu.Po
rm -f libsbcpu.a
ar cru libsbcpu.a libsbcpu_a-sb_cpu.o
ranlib libsbcpu.a
make[3]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench/tests/cpu'
Making all in fileio
make[3]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench/tests/fileio'
gcc -DHAVE_CONFIG_H -I. -I../../../config  -D_REENTRANT -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -I../../../sysbench  -pthread -g -O2 -MT libsbfileio_a-sb_fileio.o -MD -MP -MF .deps/libsbfileio_a-sb_fileio.Tpo -c -o libsbfileio_a-sb_fileio.o `test -f 'sb_fileio.c' || echo './'`sb_fileio.c
mv -f .deps/libsbfileio_a-sb_fileio.Tpo .deps/libsbfileio_a-sb_fileio.Po
gcc -DHAVE_CONFIG_H -I. -I../../../config  -D_REENTRANT -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -I../../../sysbench  -pthread -g -O2 -MT libsbfileio_a-crc32.o -MD -MP -MF .deps/libsbfileio_a-crc32.Tpo -c -o libsbfileio_a-crc32.o `test -f 'crc32.c' || echo './'`crc32.c
mv -f .deps/libsbfileio_a-crc32.Tpo .deps/libsbfileio_a-crc32.Po
rm -f libsbfileio.a
ar cru libsbfileio.a libsbfileio_a-sb_fileio.o libsbfileio_a-crc32.o
ranlib libsbfileio.a
make[3]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench/tests/fileio'
Making all in memory
make[3]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench/tests/memory'
gcc -DHAVE_CONFIG_H -I. -I../../../config  -D_REENTRANT -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -I../../../sysbench  -pthread -g -O2 -MT libsbmemory_a-sb_memory.o -MD -MP -MF .deps/libsbmemory_a-sb_memory.Tpo -c -o libsbmemory_a-sb_memory.o `test -f 'sb_memory.c' || echo './'`sb_memory.c
mv -f .deps/libsbmemory_a-sb_memory.Tpo .deps/libsbmemory_a-sb_memory.Po
rm -f libsbmemory.a
ar cru libsbmemory.a libsbmemory_a-sb_memory.o
ranlib libsbmemory.a
make[3]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench/tests/memory'
Making all in threads
make[3]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench/tests/threads'
gcc -DHAVE_CONFIG_H -I. -I../../../config  -D_REENTRANT -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -I../../../sysbench  -pthread -g -O2 -MT libsbthreads_a-sb_threads.o -MD -MP -MF .deps/libsbthreads_a-sb_threads.Tpo -c -o libsbthreads_a-sb_threads.o `test -f 'sb_threads.c' || echo './'`sb_threads.c
mv -f .deps/libsbthreads_a-sb_threads.Tpo .deps/libsbthreads_a-sb_threads.Po
rm -f libsbthreads.a
ar cru libsbthreads.a libsbthreads_a-sb_threads.o
ranlib libsbthreads.a
make[3]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench/tests/threads'
Making all in mutex
make[3]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench/tests/mutex'
gcc -DHAVE_CONFIG_H -I. -I../../../config  -D_REENTRANT -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -I../../../sysbench  -pthread -g -O2 -MT libsbmutex_a-sb_mutex.o -MD -MP -MF .deps/libsbmutex_a-sb_mutex.Tpo -c -o libsbmutex_a-sb_mutex.o `test -f 'sb_mutex.c' || echo './'`sb_mutex.c
mv -f .deps/libsbmutex_a-sb_mutex.Tpo .deps/libsbmutex_a-sb_mutex.Po
rm -f libsbmutex.a
ar cru libsbmutex.a libsbmutex_a-sb_mutex.o
ranlib libsbmutex.a
make[3]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench/tests/mutex'
Making all in oltp
make[3]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench/tests/oltp'
gcc -DHAVE_CONFIG_H -I. -I../../../config  -I./.. -D_REENTRANT -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -I../../../sysbench -I/usr/include/mysql  -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC  -pthread -g -O2 -MT libsboltp_a-sb_oltp.o -MD -MP -MF .deps/libsboltp_a-sb_oltp.Tpo -c -o libsboltp_a-sb_oltp.o `test -f 'sb_oltp.c' || echo './'`sb_oltp.c
mv -f .deps/libsboltp_a-sb_oltp.Tpo .deps/libsboltp_a-sb_oltp.Po
rm -f libsboltp.a
ar cru libsboltp.a libsboltp_a-sb_oltp.o
ranlib libsboltp.a
make[3]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench/tests/oltp'
make[3]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench/tests'
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench/tests'
make[2]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench/tests'
Making all in .
make[2]: Entering directory `/usr/local/src/sysbench-0.4.12/sysbench'
gcc -DHAVE_CONFIG_H -I. -I../config  -D_REENTRANT -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -I../sysbench  -pthread -g -O2 -MT sysbench.o -MD -MP -MF .deps/sysbench.Tpo -c -o sysbench.o sysbench.c
mv -f .deps/sysbench.Tpo .deps/sysbench.Po
gcc -DHAVE_CONFIG_H -I. -I../config  -D_REENTRANT -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -I../sysbench  -pthread -g -O2 -MT sb_timer.o -MD -MP -MF .deps/sb_timer.Tpo -c -o sb_timer.o sb_timer.c
mv -f .deps/sb_timer.Tpo .deps/sb_timer.Po
gcc -DHAVE_CONFIG_H -I. -I../config  -D_REENTRANT -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -I../sysbench  -pthread -g -O2 -MT sb_options.o -MD -MP -MF .deps/sb_options.Tpo -c -o sb_options.o sb_options.c
mv -f .deps/sb_options.Tpo .deps/sb_options.Po
gcc -DHAVE_CONFIG_H -I. -I../config  -D_REENTRANT -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -I../sysbench  -pthread -g -O2 -MT sb_logger.o -MD -MP -MF .deps/sb_logger.Tpo -c -o sb_logger.o sb_logger.c
mv -f .deps/sb_logger.Tpo .deps/sb_logger.Po
gcc -DHAVE_CONFIG_H -I. -I../config  -D_REENTRANT -D_XOPEN_SOURCE=500 -D_GNU_SOURCE -I../sysbench  -pthread -g -O2 -MT db_driver.o -MD -MP -MF .deps/db_driver.Tpo -c -o db_driver.o db_driver.c
mv -f .deps/db_driver.Tpo .deps/db_driver.Po
/bin/sh ../libtool --tag=CC   --mode=link gcc -pthread -g -O2      -o sysbench sysbench.o sb_timer.o sb_options.o sb_logger.o db_driver.o tests/fileio/libsbfileio.a tests/threads/libsbthreads.a tests/memory/libsbmemory.a tests/cpu/libsbcpu.a tests/oltp/libsboltp.a tests/mutex/libsbmutex.a drivers/mysql/libsbmysql.a -rdynamic -L/usr/lib64/mysql -lmysqlclient_r -lz -lcrypt -lnsl -lm -L/usr/lib64 -lssl -lcrypto   -lrt -lm
<span style="color: #ff0000;">../libtool: line 838: X--tag=CC: command not found
../libtool: line 871: libtool: ignoring unknown tag : command not found
../libtool: line 838: X--mode=link: command not found
../libtool: line 1004: *** Warning: inferring the mode of operation is deprecated.: command not found
../libtool: line 1005: *** Future versions of Libtool will require --mode=MODE be specified.: command not found
../libtool: line 2231: X-g: command not found
../libtool: line 2231: X-O2: command not found
../libtool: line 2231: X-rdynamic: command not found
../libtool: line 1951: X-L/usr/lib64/mysql: No such file or directory
../libtool: line 1951: X-L/usr/lib64: No such file or directory
../libtool: line 2400: Xsysbench: command not found
../libtool: line 2405: X: command not found
../libtool: line 2412: Xsysbench: command not found
../libtool: line 2547: X-lmysqlclient_r: command not found
../libtool: line 2547: X-lz: command not found
../libtool: line 2547: X-lcrypt: command not found
../libtool: line 2547: X-lnsl: command not found
../libtool: line 2547: X-lm: command not found
../libtool: line 2547: X-lssl: command not found
../libtool: line 2547: X-lcrypto: command not found
../libtool: line 2547: X-lrt: command not found
../libtool: line 2547: X-lm: command not found
../libtool: line 2629: X-L/usr/local/src/sysbench-0.4.12/sysbench: No such file or directory
../libtool: line 2547: X-lmysqlclient_r: command not found
../libtool: line 2547: X-lz: command not found
../libtool: line 2547: X-lcrypt: command not found
../libtool: line 2547: X-lnsl: command not found
../libtool: line 2547: X-lssl: command not found
../libtool: line 2547: X-lcrypto: command not found
../libtool: line 2547: X-lrt: command not found
../libtool: line 2547: X-lm: command not found
../libtool: line 2629: X-L/usr/local/src/sysbench-0.4.12/sysbench: No such file or directory
../libtool: line 2547: X-lmysqlclient_r: command not found
../libtool: line 2547: X-lz: command not found
../libtool: line 2547: X-lcrypt: command not found
../libtool: line 2547: X-lnsl: command not found
../libtool: line 2547: X-lssl: command not found
../libtool: line 2547: X-lcrypto: command not found
../libtool: line 2547: X-lrt: command not found
../libtool: line 2547: X-lm: command not found
../libtool: line 5162: Xgcc -pthread "" "" -o @OUTPUT@ sysbench.o sb_timer.o sb_options.o sb_logger.o db_driver.o ""  tests/fileio/libsbfileio.a tests/threads/libsbthreads.a tests/memory/libsbmemory.a tests/cpu/libsbcpu.a tests/oltp/libsboltp.a tests/mutex/libsbmutex.a drivers/mysql/libsbmysql.a -L/usr/local/src/sysbench-0.4.12/sysbench -lmysqlclient_r -lz -lcrypt -lnsl -lssl -lcrypto -lrt -lm: No such file or directory
../libtool: line 5163: Xgcc -pthread "" "" -o @OUTPUT@ sysbench.o sb_timer.o sb_options.o sb_logger.o db_driver.o ""  tests/fileio/libsbfileio.a tests/threads/libsbthreads.a tests/memory/libsbmemory.a tests/cpu/libsbcpu.a tests/oltp/libsboltp.a tests/mutex/libsbmutex.a drivers/mysql/libsbmysql.a -L/usr/local/src/sysbench-0.4.12/sysbench -lmysqlclient_r -lz -lcrypt -lnsl -lssl -lcrypto -lrt -lm: No such file or directory
../libtool: line 5168: X: command not found
../libtool: line 5172: : command not found
</span>make[2]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench'
make[1]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench'
make[1]: Entering directory `/usr/local/src/sysbench-0.4.12'
make[1]: Nothing to be done for `all-am'.
make[1]: Leaving directory `/usr/local/src/sysbench-0.4.12'
[root@fc10-dev sysbench-0.4.12]#</pre>
<p>การรัน make ครั้งนี้ก็ยังมี error อีก</p>
<pre><span style="color: #ff0000;">../libtool: line 838: X--tag=CC: command not found
../libtool: line 871: libtool: ignoring unknown tag : command not found
../libtool: line 838: X--mode=link: command not found</span></pre>
<p>เท่าที่ทดสอบและตรวจสอบข้อมูลจากเว็บไซต์ของ <a href="http://sourceforge.net/forum/forum.php?thread_id=3137221&amp;forum_id=353124" target="_blank">sysbench</a> เอง มีการเปลี่ยนแปลงเวอร์ชั่นของ libtool ซึ่งเป็น library ที่ใช้ในการคอมไพล์โปรแกรม เวอร์ชั่นตั้งแต่ 0.4.11  ต้องรันคำสั่งด้านล่างนี้เพื่อแก้ไขปัญหา</p>
<pre>[root@fc10-dev sysbench-0.4.12]# <strong>libtoolize --force --copy
</strong>You should update your `aclocal.m4' by running aclocal.
Putting files in AC_CONFIG_AUX_DIR, `config'.</pre>
<pre>[root@fc10-dev sysbench-0.4.12]# <strong>./autogen.sh
</strong>[root@fc10-dev sysbench-0.4.12]#</pre>
<p>รันคำสั่ง make อีกครั้ง หลังจากรันคำสั่งแก้ไข</p>
<pre>[root@fc10-dev sysbench-0.4.12]# <strong>make</strong>
/bin/sh ./config.status --recheck
running CONFIG_SHELL=/bin/sh /bin/sh ./configure   --no-create --no-recursion
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to compile with MySQL support... (cached) yes
checking whether to compile with Oracle support... (cached) no
checking whether to compile with PostgreSQL support... (cached) no
checking for style of include used by make... GNU
checking for gcc... gcc
...
...
...
/bin/sh ../libtool --tag=CC   --mode=link gcc -pthread -g -O2      -o sysbench sysbench.o sb_timer.o sb_options.o sb_logger.o db_driver.o tests/fileio/libsbfileio.a tests/threads/libsbthreads.a tests/memory/libsbmemory.a tests/cpu/libsbcpu.a tests/oltp/libsboltp.a tests/mutex/libsbmutex.a drivers/mysql/libsbmysql.a -rdynamic -L/usr/lib64/mysql -lmysqlclient_r -lz -lcrypt -lnsl -lm -L/usr/lib64 -lssl -lcrypto   -lrt -lm
mkdir .libs
gcc -pthread -g -O2 -o sysbench sysbench.o sb_timer.o sb_options.o sb_logger.o db_driver.o -rdynamic  tests/fileio/libsbfileio.a tests/threads/libsbthreads.a tests/memory/libsbmemory.a tests/cpu/libsbcpu.a tests/oltp/libsboltp.a tests/mutex/libsbmutex.a drivers/mysql/libsbmysql.a -L/usr/lib64/mysql -lmysqlclient_r -lz -lcrypt -lnsl -L/usr/lib64 -lssl -lcrypto -lrt -lm
make[2]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench'
make[1]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench'
make[1]: Entering directory `/usr/local/src/sysbench-0.4.12'
make[1]: Nothing to be done for `all-am'.
make[1]: Leaving directory `/usr/local/src/sysbench-0.4.12'
[root@fc10-dev sysbench-0.4.12]#</pre>
<p>ตรวจสอบอีกครั้งว่าไม่มี error ขึ้นมาอีก จากการันคำสั่ง make แล้วค่อยไปขั้นตอนต่อไป</p>
<h4>รัน make install</h4>
<p>ถ้ารัน make แล้ว ไม่มีข้อความ error แสดงว่าโปรแกรมคอมไพล์สำเร็จ สามารถใช้คำสั่ง make install เพื่อติดตั้งไฟล์ได้ โดยดีฟอลต์ โปรแกรมที่คอมไฟล์เองจะติดตั้งไฟล์ไว้ใน /usr/local/</p>
<pre>[root@fc10-dev sysbench-0.4.12]# <strong>make install
</strong>Making install in doc
make[1]: Entering directory `/usr/local/src/sysbench-0.4.12/doc'
Making install in xsl
make[2]: Entering directory `/usr/local/src/sysbench-0.4.12/doc/xsl'
make[3]: Entering directory `/usr/local/src/sysbench-0.4.12/doc/xsl'
make[3]: Nothing to be done for `install-exec-am'.
make[3]: Nothing to be done for `install-data-am'.
make[3]: Leaving directory `/usr/local/src/sysbench-0.4.12/doc/xsl'
make[2]: Leaving directory `/usr/local/src/sysbench-0.4.12/doc/xsl'
...
...
...
make[3]: Nothing to be done for `install-data-am'.
make[3]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench'
make[2]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench'
make[1]: Leaving directory `/usr/local/src/sysbench-0.4.12/sysbench'
make[1]: Entering directory `/usr/local/src/sysbench-0.4.12'
make[2]: Entering directory `/usr/local/src/sysbench-0.4.12'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/usr/local/src/sysbench-0.4.12'
make[1]: Leaving directory `/usr/local/src/sysbench-0.4.12'
[root@fc10-dev sysbench-0.4.12]#</pre>
<p>ตรวจสอบโปรแกรม sysbench ที่ถูกติดตั้ง ไว้ใน /usr/local/bin/</p>
<pre>[root@fc10-dev sysbench-0.4.12]# <strong>ls -l /usr/local/bin/
</strong>total 308
-rwxr-xr-x 1 root root 307952 2009-05-16 17:20 sysbench
[root@fc10-dev sysbench-0.4.12]#</pre>
<h4>ทดลองรัน sysbench</h4>
<p>ทดลองรัน sysbench โดยไม่ได้ระบุออปชั่น ถ้าคอมไพล์และติดตั้งถูกต้อง หน้าจอจะขึ้นวิธีการใช้ (usage) ขึ้นมา</p>
<p><strong>หมายเหตุ </strong>โดยดีฟอลต์จากการติดตั้งลีนุกซ์ส่วนใหญ่แล้ว /usr/local/bin/ จะอยู่ใน PATH อยู่แล้ว ทำให้เราไม่ต้องระบุ PATH เต็มๆ เวลารันไฟล์ ที่อยู่ใน /usr/local/bin/</p>
<pre>[root@fc10-dev sysbench-0.4.12]# <strong>sysbench</strong>
Missing required command argument.
Usage:
  sysbench [general-options]... --test=&lt;test-name&gt; [test-options]... command</pre>
<pre>General options:
  --num-threads=N            number of threads to use [1]
  --max-requests=N           limit for total number of requests [10000]
  --max-time=N               limit for total execution time in seconds [0]
  --forced-shutdown=STRING   amount of time to wait after --max-time before forcing shutdown [off]
  --thread-stack-size=SIZE   size of stack per thread [32K]
  --init-rng=[on|off]        initialize random number generator [off]
  --test=STRING              test to run
  --debug=[on|off]           print more debugging info [off]
  --validate=[on|off]        perform validation checks where possible [off]
  --help=[on|off]            print help and exit
  --version=[on|off]         print version and exit</pre>
<pre>Compiled-in tests:
  fileio - File I/O test
  cpu - CPU performance test
  memory - Memory functions speed test
  threads - Threads subsystem performance test
  mutex - Mutex performance test
  oltp - OLTP test</pre>
<pre>Commands: prepare run cleanup help version</pre>
<pre>See 'sysbench --test=&lt;name&gt; help' for a list of options for each test.</pre>
<pre>[root@fc10-dev sysbench-0.4.12]#</pre>
<h4>ลบไฟล์ที่คอมไพล์ (optional)</h4>
<p>หลังจากคอมไพล์และติดตั้งลงโปรแกรมไว้ใน /usr/local/bin/ แล้ว เราสามารถลบไฟล์ที่คอมไพล์ออกไปได้ เพื่อประหยัดพื้นที่ดิสก์</p>
<pre>[root@fc10-dev sysbench-0.4.12]# cd ..
[root@fc10-dev src]# <strong>rm -rvf sysbench-0.4.12/ sysbench-0.4.12.tar.gz
</strong>removed `sysbench-0.4.12/configure'
removed `sysbench-0.4.12/Makefile.in'
removed `sysbench-0.4.12/TODO'
removed `sysbench-0.4.12/install-sh'
removed `sysbench-0.4.12/aclocal.m4'
removed `sysbench-0.4.12/Makefile'
removed `sysbench-0.4.12/README'
removed `sysbench-0.4.12/autogen.sh'
removed `sysbench-0.4.12/sysbench/sysbench.o'
removed directory: `sysbench-0.4.12/sysbench/.libs'
removed `sysbench-0.4.12/sysbench/db_driver.c'
removed `sysbench-0.4.12/sysbench/sb_win.h'
...
...
...
removed directory: `sysbench-0.4.12/config'
removed `sysbench-0.4.12/libtool'
removed `sysbench-0.4.12/config.log'
removed `sysbench-0.4.12/Makefile.am'
removed `sysbench-0.4.12/README-WIN.txt'
removed directory: `sysbench-0.4.12'
removed `sysbench-0.4.12.tar.gz'
[root@fc10-dev src]#  ls -l
total 0
[root@fc10-dev src]#</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://sysbench.sourceforge.net/" target="_blank">System performance benchmark</a></li>
<li><a href="http://sourceforge.net/project/showfiles.php?group_id=102348&amp;package_id=109810" target="_blank">Download sysbench &#8211; SourceForge.net: System performance benchmark: Files</a></li>
<li><a href="http://sourceforge.net/forum/forum.php?thread_id=3137221&amp;forum_id=353124" target="_blank">Problem with compile on Centos 4.6</a></li>
<li><a href="ftp://www.mirror.in.th./fedora/releases/10/Everything/x86_64/os/Packages/" target="_blank">FC10 Everything (x86_64)</a></li>
<li><a href="http://spalinux.com/2009/05/sysbench_cpu_benchmark">sysbench วัดความแรงของ CPU</a></li>
<li><a href="http://spalinux.com/2009/05/compile_sysbench_on_solaris_10_x86">คอมไพล์ sysbench บน Solaris 10 (x86)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/05/%e0%b8%84%e0%b8%ad%e0%b8%a1%e0%b9%84%e0%b8%9e%e0%b8%a5%e0%b9%8c-sysbench-%e0%b8%9a%e0%b8%99-fedora-10/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
