<?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; Networking</title>
	<atom:link href="http://spalinux.com/category/networking/feed" rel="self" type="application/rss+xml" />
	<link>http://spalinux.com</link>
	<description>Resources for Relaxing Linux System Administrators</description>
	<lastBuildDate>Sat, 21 Jan 2012 16:07:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>แกะกล่องทดสอบ AirLive WL-5460AP v2 Wireless Access Point</title>
		<link>http://spalinux.com/2011/12/basic-test-airlive-wl-5460ap-v2-wireless-access-point</link>
		<comments>http://spalinux.com/2011/12/basic-test-airlive-wl-5460ap-v2-wireless-access-point#comments</comments>
		<pubDate>Wed, 28 Dec 2011 18:41:57 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Wireless]]></category>
		<category><![CDATA[Access Point]]></category>
		<category><![CDATA[AirLive]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1584</guid>
		<description><![CDATA[วันก่อนเดินตลาดเพื่อหาซื้อ Access Point รุ่นประจำที่เคยใช้ แต่ของขาดตลาด ผู้ขายเลยแนะนำรุ่นนี้มาให้ ว่ากันว่าสามารถปรับสัญญาณ Wireless ได้แรงมาก เลยต้องมาทดสอบกันหน่อย ในที่นี้จะทดสอบคอนฟิกเบื้องต้น รายละเอียดรุ่น AirLive WL-5460AP v2 802.11g Multi-function Wireless Access Point LAN: 2 port LAN1, LAN2 ดีฟอลต์คอนฟิกจากโรงงาน AP default IP address : 192.168.100.252 Subnet Mask : 255.255.255.0 default passsword: airlive คำแนะนำ ให้ทดสอบทำความเข้าใจ ก่อนที่จะต่อเชื่อม Access Point เข้ากับ network ที่ใช้งานจริงอยู่ เริ่มคอนฟิก Access Point เซ็ต IP ของพอร์ต LAN เครื่อง [...]]]></description>
			<content:encoded><![CDATA[<p>วันก่อนเดินตลาดเพื่อหาซื้อ Access Point รุ่นประจำที่เคยใช้ แต่ของขาดตลาด ผู้ขายเลยแนะนำรุ่นนี้มาให้ ว่ากันว่าสามารถปรับสัญญาณ Wireless ได้แรงมาก</p>
<p>เลยต้องมาทดสอบกันหน่อย ในที่นี้จะทดสอบคอนฟิกเบื้องต้น</p>
<p><span id="more-1584"></span></p>
<p>รายละเอียดรุ่น</p>
<ul>
<li>AirLive WL-5460AP v2</li>
<li>802.11g Multi-function Wireless Access Point</li>
<li>LAN: 2 port LAN1, LAN2</li>
</ul>
<p>ดีฟอลต์คอนฟิกจากโรงงาน</p>
<ul>
<li>AP default IP address : 192.168.100.252</li>
<li>Subnet Mask : 255.255.255.0</li>
<li>default passsword: airlive</li>
</ul>
<p><span style="color: #ff0000;">คำแนะนำ ให้ทดสอบทำความเข้าใจ ก่อนที่จะต่อเชื่อม Access Point เข้ากับ network ที่ใช้งานจริงอยู่</span></p>
<h4>เริ่มคอนฟิก Access Point</h4>
<p>เซ็ต IP ของพอร์ต LAN เครื่อง PC หรือ Notebook ที่จะใช้คอนฟิกให้อยู่ใน Subnet 192.168.100.x (ห้ามตั้งชนกับ 192.168.100.252)</p>
<p>ต่อสายแลนเข้ากับพอร์ต LAN1 ของ AirLive</p>
<p>ใช้ Browser เปิดไปที่ http://192.168.100.252</p>
<p>หน้าเว็บขอบคุณที่เลือกใช้</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/12/a01.png"><img class="alignnone size-full wp-image-1585" title="a01" src="http://spalinux.com/wp-content/uploads/2011/12/a01.png" alt="" width="733" height="275" /></a></p>
<p>&nbsp;</p>
<p>คลิ้กที่แท็ป &#8220;Mode&#8221; เพิ่อเริ่มคอนฟิก Wireless</p>
<p>หน้าเว็บ &#8220;Wireless Mode&#8221;</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/12/a02.png"><img class="alignnone size-full wp-image-1586" title="a02" src="http://spalinux.com/wp-content/uploads/2011/12/a02.png" alt="" width="733" height="519" /></a></p>
<p>&nbsp;</p>
<ul>
<li> เลือกโหมด AP (Access Point) แล้วกดปุ่ม [Setup]</li>
</ul>
<p>&nbsp;</p>
<p>หน้าเว็บ &#8220;AP Mode Settings&#8221; เพื่อแก้ไขค่าคอนฟิก Wireless</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/12/a03.png"><img class="alignnone size-full wp-image-1587" title="a03" src="http://spalinux.com/wp-content/uploads/2011/12/a03.png" alt="" width="734" height="676" /></a></p>
<p>&nbsp;</p>
<ul>
<li>แนะนำให้เปลี่ยนชื่อ SSID</li>
<li>บรรทัด Secrity: กดปุ่ม [Setup] เพื่อตั้งค่ารหัส (Encryption key) =&gt; ไปที่หน้าเว็บ &#8220;Wireless Security Setup&#8221;</li>
<li>บรรทัด Advanced Settings: กดปุ่ม [Setup] เพื่อเข้าสู่การตั้งค่าขั้นสูง =&gt; ไปที่หน้าเว็บ &#8220;Wireless Advanced Settings&#8221;</li>
</ul>
<p>หน้าเว็บ &#8220;Wireless Security Setup&#8221;</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/12/a04.png"><img class="alignnone size-full wp-image-1588" title="a04" src="http://spalinux.com/wp-content/uploads/2011/12/a04.png" alt="" width="710" height="259" /></a></p>
<p>&nbsp;</p>
<ul>
<li>เลือก Encryption: ที่ต้องการใช้ เช่นเลือกเป็น WPA-PSK2 Mixed</li>
<li>เลือก Pre-Shared Key Format: Passphrase</li>
<li>ใส่ค่า Pre-Shared Key: ที่ต้องการ เป็นรหัสที่ Wireless Client ต้องใส่ก่อนที่จะเชื่อมต่อกับ Access Point ได้</li>
</ul>
<p>กดปุ่ม [Apply Changes]</p>
<p>&nbsp;</p>
<p><span style="color: #0000ff;">หมายเหตุ ข้อเสียอย่างหนึ่งของ Access Point ยี่ห้อนี้คือ เปลี่ยนคอนฟิกไปแล้ว จะมีผลหลังจาก &#8220;Reboot&#8221; เท่านั้น เพราะฉะนั้น แนะนำให้เปลี่ยนคอนฟิกทุกอย่างให้เรียบร้อย แล้วค่อย reboot ครั้งเดียว</span></p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/12/a05.png"><img class="alignnone size-full wp-image-1589" title="a05" src="http://spalinux.com/wp-content/uploads/2011/12/a05.png" alt="" width="356" height="122" /></a></p>
<p>&nbsp;</p>
<p>หน้าเว็บ &#8220;Wireless Advanced Settings&#8221;</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/12/a06.png"><img class="alignnone size-full wp-image-1590" title="a06" src="http://spalinux.com/wp-content/uploads/2011/12/a06.png" alt="" width="660" height="608" /></a></p>
<p>&nbsp;</p>
<ul>
<li>แนะนำให้ปิดการ &#8220;Broadcast SSID:&#8221; โดยเปลี่ยนเป็น &#8220;Disabled&#8221;</li>
</ul>
<p>กดปุ่ม [Apply Changes]</p>
<p>&nbsp;</p>
<h4>คอนฟิก DHCP Server บน Access Point</h4>
<p>สำหรับการทดสอบนี้ จะคอนฟิกให้ Access Point แจก IP address ด้วย</p>
<p><span style="color: #ff0000;">คำเตือน ปิดการใช้งาน DHCP บน AP นี้ ก่อนจะเชื่อมต่อเข้ากับ network ที่มี DHCP Server อยู่แล้ว ยกเว้น คุณจะตั้งใจให้ AP ตัวนี้เป็น DHCP Server</span></p>
<p>คลิ้กแท็ป &#8220;TCP/IP&#8221; หน้าเว็บจะแสดง LAN Interface Setup</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/12/a07.png"><img class="alignnone size-full wp-image-1591" title="a07" src="http://spalinux.com/wp-content/uploads/2011/12/a07.png" alt="" width="734" height="676" /></a></p>
<p>&nbsp;</p>
<ul>
<li>บรรทัด DHCP: เลือกเป็น Server</li>
<li>บรรทัด DHCP Client Range: ใส่ IP address ที่ต้องการแจก</li>
</ul>
<p>&nbsp;</p>
<p>เบื้องต้นทดลองเปลี่ยนคอนฟิกแค่นี้ก่อน กดแท็ป &#8220;Reboot&#8221; แล้วกดปุ่ม [Reboot] เพื่อรีบู๊ตอุปกรณ์</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/12/a08.png"><img class="alignnone size-full wp-image-1592" title="a08" src="http://spalinux.com/wp-content/uploads/2011/12/a08.png" alt="" width="734" height="307" /></a></p>
<p>&nbsp;</p>
<p>กดปุ่ม [OK] เพื่อยีนยันการ reboot</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/12/a10.png"><img class="alignnone size-full wp-image-1594" title="a10" src="http://spalinux.com/wp-content/uploads/2011/12/a10.png" alt="" width="356" height="148" /></a></p>
<p>&nbsp;</p>
<p>หน้าเว็บแสดงกำลัง Reboot เท่าที่จับเวลา ประมาณ 100 วินาที ถึงจะกลับมาใช้ได้ ใกล้เคียงกับแถบสีแดงที่ขึ้นบนหน้าเว็บเต็มพอดี เพราะฉะนั้นเปิดหน้า Rebooting ทิ้งไว้ได้เลย แต่ยกเว้นมีการเปลี่ยน IP ของ Access Point</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/12/a09.png"><img class="alignnone size-full wp-image-1593" title="a09" src="http://spalinux.com/wp-content/uploads/2011/12/a09.png" alt="" width="732" height="300" /></a></p>
<p>&nbsp;</p>
<p>ลองเซ็ต Wireless Client ตั้งค่า SSID, Encryption และ key ที่คอนฟิกไว้ แล้วลองเชื่อมต่อดู</p>
<p>&nbsp;</p>
<p>หากต้องการดู Client ที่เชื่อมต่อ ให้คลิ้กแท็ป &#8220;Status&#8221; แล้วคลิ้กลิ้งค์ย่อย &#8220;Active Clients&#8221; ที่อยู่ข้างล่างแท็ป</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/12/a11.png"><img class="alignnone size-full wp-image-1595" title="a11" src="http://spalinux.com/wp-content/uploads/2011/12/a11.png" alt="" width="733" height="388" /></a></p>
<p>&nbsp;</p>
<p>ข้อมูลอ้างอิง</p>
<ul>
<li><a href="http://www.airlive.com/" target="_blank">www.airlive.com</a></li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/12/basic-test-airlive-wl-5460ap-v2-wireless-access-point/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เก็บข้อมูลการใช้เว็บผ่าน Linux Router ด้วย Squid Transparent Proxy</title>
		<link>http://spalinux.com/2011/11/how-to-log-web-traffic-via-linux-router-using-squid-transparent-proxy</link>
		<comments>http://spalinux.com/2011/11/how-to-log-web-traffic-via-linux-router-using-squid-transparent-proxy#comments</comments>
		<pubDate>Fri, 25 Nov 2011 17:44:17 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[router]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[Transparent Proxy]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1519</guid>
		<description><![CDATA[ด้วยกฎหมาย พรบ. ที่เริ่มมีผลบังคับ ให้เก็บข้อมูลการใช้เว็บอินเตอร์เน็ต ว่าเป็นใครใช้ เข้าเว็บไหน เมื่อไร ถ้าเป็นเครื่องที่เราสามารถดูแลได้ วิธีหนึ่งที่ทำได้คือ คอนฟิก Proxy ใน ฺBrowser ของแต่ละเครื่องที่จะใช้อินเตอร์เน็ต ชี้ไปยัง Proxy Server ที่ทำหน้าที่เก็บข้อมูลการใช้งาน แต่ถ้าเราไม่สามารถควบคุมดูแลได้ หรือเครื่องที่ใช้งานมีการเปลี่ยนแปลงตลอดเวลา เช่นให้บริการอินเตอร์เน็ต สำหรับผู้มาติดต่องาน ถ้าเป็นแบบนี้ แนะนำให้คอนฟิก Transparent Proxy บน Linux Router เพื่อให้ทำหน้าที่เก็บข้อมูลการใช้เว็บโดยอัตโนมัติ ระบบทดสอบ Linux Router ติดตั้ง Squid มีพอร์ต LAN สองพอร์ต eth0, eth1 เครื่องผู้ใช้งานทั้งหมดต่อพอร์ต eth0 ของ Linux Router พอร์ต eth1 ของ Linux Router ต่อไปยังอินเตอร์เน็ต Redirect Web Traffic ให้เข้าไปใน Proxy [...]]]></description>
			<content:encoded><![CDATA[<p>ด้วยกฎหมาย พรบ. ที่เริ่มมีผลบังคับ ให้เก็บข้อมูลการใช้เว็บอินเตอร์เน็ต ว่าเป็นใครใช้ เข้าเว็บไหน เมื่อไร</p>
<p>ถ้าเป็นเครื่องที่เราสามารถดูแลได้ วิธีหนึ่งที่ทำได้คือ คอนฟิก Proxy ใน ฺBrowser ของแต่ละเครื่องที่จะใช้อินเตอร์เน็ต ชี้ไปยัง Proxy Server ที่ทำหน้าที่เก็บข้อมูลการใช้งาน</p>
<p>แต่ถ้าเราไม่สามารถควบคุมดูแลได้ หรือเครื่องที่ใช้งานมีการเปลี่ยนแปลงตลอดเวลา เช่นให้บริการอินเตอร์เน็ต สำหรับผู้มาติดต่องาน</p>
<p>ถ้าเป็นแบบนี้ แนะนำให้คอนฟิก Transparent Proxy บน Linux Router เพื่อให้ทำหน้าที่เก็บข้อมูลการใช้เว็บโดยอัตโนมัติ</p>
<p><span id="more-1519"></span></p>
<h4>ระบบทดสอบ</h4>
<ul>
<li>Linux Router ติดตั้ง Squid มีพอร์ต LAN สองพอร์ต eth0, eth1</li>
<li>เครื่องผู้ใช้งานทั้งหมดต่อพอร์ต eth0 ของ Linux Router</li>
<li>พอร์ต eth1 ของ Linux Router ต่อไปยังอินเตอร์เน็ต</li>
</ul>
<h4></h4>
<h4>Redirect Web Traffic ให้เข้าไปใน Proxy Server</h4>
<p>เริ่มแรกต้องบังคับให้การใช้เว็บอินเตอร์เน็ตทั้งหมดต้องผ่าน Linux Router เข้าพอร์ต eth0 แล้วออกอินเตอร์เน็ตทางพอร์ต eth1</p>
<p>ถ้าเราต้องการให้การใช้เว็บ (TCP Port 80) ทั้งหมด เข้าพอร์ต eth0 ต้องผ่านเข้าไปใน Proxy Server (TCP Port 3128) ก่อน เพื่อให้เก็บข้อมูลการใช้งาน สามารถใช้คำสั่ง iptables ตามตัวอย่าง</p>
<pre>
[root@router ~]# <b>iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128</b>
</pre>
<h4>คอนฟิก Squid ให้ทำหน้าที่เป็น Transparent Proxy</h4>
<p>อย่างที่สองคือต้องแก้ไขไฟล์คอนฟิก Squid ซึ่งอยู่ใน /etc/squid/squid.conf</p>
<p>การแก้ไขคอนฟิกขึ้นอยู่กับเวอร์ชั่นของ Squid ที่ติดตั้ง</p>
<p>คำแนะนำ : เพื่อคุณสมบัติและประสิทธิภาพที่ดีกว่า แนะนำให้ใช้เวอร์ชั่นใหม่ล่าสุดที่สามารถติดตั้งได้</p>
<p><span style="text-decoration: underline;"><strong>เวอร์ชั่นเก่ากว่า 2.6</strong></span></p>
<pre>
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
</pre>
<p><span style="text-decoration: underline;"><strong>เวอร์ชั่น 2.6 &#8211; 3.0</strong></span></p>
<pre>
http_port 3128 transparent
</pre>
<p><span style="text-decoration: underline;"><strong>ตั้งแต่เวอร์ชั่น 3.1</strong></span></p>
<pre>
http_port 3128 intercept
</pre>
<p>หรือ</p>
<pre>
http_port 3128 transparent
</pre>
<p>หลังการแก้ไขคอนฟิกไฟล์ของ squid ต้องรีสตาร์ตเซอร์วิส squid</p>
<pre>
[root@router ~]# <b>service squid restart</b>
</pre>
<p>สามารถดูข้อมูลการใช้งานเว็บได้ในไฟล์ /var/log/squid/access.log</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2008/05/configure_squid_proxy_server">คอนฟิก Squid Proxy Server</a></li>
<li><a href="http://www.squid-cache.org/" target="_blank">squid : Optimising Web Delivery</a></li>
<li><a href="http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch32_:_Controlling_Web_Access_with_Squid" target="_blank">Quick HOWTO : Ch32 : Controlling Web Access with Squid</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/11/how-to-log-web-traffic-via-linux-router-using-squid-transparent-proxy/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>คำสั่ง เพิ่ม ลบ แสดง route บน OS ต่างๆ</title>
		<link>http://spalinux.com/2011/06/howto_add_delete_show_route_on_different_os</link>
		<comments>http://spalinux.com/2011/06/howto_add_delete_show_route_on_different_os#comments</comments>
		<pubDate>Thu, 09 Jun 2011 10:26:54 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[netstat]]></category>
		<category><![CDATA[route]]></category>
		<category><![CDATA[routing table]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1362</guid>
		<description><![CDATA[ไม่มีไรมาก ในบทความนี้ ขอรวบรวม วิธีการ เพิ่ม ลบ และ แสดง routing table บน OS ต่างๆ เพื่อผู้สนใจ และอาจสับสนในบางครั้ง เมื่อต้องดูแลจัดการเครื่องหลายแบบ ตัวอย่างทั้งหมด แสดงการเพิ่ม และ ลบ route เพื่อไปยัง network &#8220;172.16.1.0/255.255.255.0&#8243; โดยผ่าน gateway &#8220;192.168.1.254&#8243; ส่วนการแสดง routing table นั้น จะแสดงผลลัพธ์เฉพาะส่วนที่เพิ่ม route เท่านั้น Linux [root@linux ~]# route add -net 172.16.1.0 netmask 255.255.255.0 gw 192.168.1.254 [root@linux ~]# netstat -rn Kernel IP routing table Destination     Gateway         Genmask         Flags   MSS [...]]]></description>
			<content:encoded><![CDATA[<p>ไม่มีไรมาก ในบทความนี้ ขอรวบรวม วิธีการ เพิ่ม ลบ และ แสดง routing table บน OS ต่างๆ เพื่อผู้สนใจ และอาจสับสนในบางครั้ง เมื่อต้องดูแลจัดการเครื่องหลายแบบ</p>
<p>ตัวอย่างทั้งหมด แสดงการเพิ่ม และ ลบ route เพื่อไปยัง network &#8220;172.16.1.0/255.255.255.0&#8243; โดยผ่าน gateway &#8220;192.168.1.254&#8243;</p>
<p>ส่วนการแสดง routing table นั้น จะแสดงผลลัพธ์เฉพาะส่วนที่เพิ่ม route เท่านั้น</p>
<h4><span id="more-1362"></span><br />
Linux</h4>
<pre>[root@linux ~]# <strong>route add -net 172.16.1.0 netmask 255.255.255.0 gw 192.168.1.254</strong></pre>
<pre>[root@linux ~]# <strong>netstat -rn
</strong>Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
172.16.1.0      192.168.1.254   255.255.255.0     UG      0 0          0 eth0</pre>
<pre>[root@linux ~]# <strong>route del -net 172.16.1.0 netmask 255.255.255.0 gw 192.168.1.254</strong></pre>
<pre> </pre>
<h4>MAC OS X</h4>
<pre>[root@osx ~]# <strong>route add -net 172.16.1.0 192.168.1.254 255.255.255.0
</strong>add net 172.16.1.0: gateway 192.168.1.254</pre>
<pre>[root@osx ~]# <strong>netstat -rn</strong>
Routing tables</pre>
<pre>Internet:
Destination        Gateway            Flags    Refs      Use  Netif Expire
172.16.1/24        192.168.1.254      UGSc        0        0    en0</pre>
<pre>[root@osx ~]# <strong>route delete -net 172.16.1.0 192.168.1.254 255.255.255.0</strong>
delete net 172.16.1.0: gateway 192.168.1.254</pre>
<p> </p>
<h4>Solaris </h4>
<pre>[root@solaris /]# <strong>route add -net 172.16.1.0 -netmask 255.255.255.0 192.168.1.254
</strong>add net 172.16.1.0: gateway 192.168.1.254 </pre>
<pre>[root@solaris /]# <strong>netstat -rnv</strong></pre>
<pre>IRE Table: IPv4
  Destination             Mask           Gateway          Device Mxfrg Rtt   Ref Flg  Out  In/Fwd
-------------------- --------------- -------------------- ------ ----- ----- --- --- ----- ------
172.16.1.0           255.255.255.0   192.168.1.254               1500*    0    1 UG      0      0</pre>
<pre>[root@solaris /]# <strong>route delete -net 172.16.1.0 -netmask 255.255.255.0 192.168.1.254
</strong>delete net 172.16.1.0: gateway 192.168.1.254</pre>
<p> </p>
<h4>Windows</h4>
<pre>C:\&gt; <strong>route add 172.16.1.0 mask 255.255.255.0 192.168.1.254</strong></pre>
<pre>C:\&gt; <strong>netstat -rn</strong></pre>
<pre>Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
       172.16.1.0      255.255.255.0     192.168.1.254  192.168.1.       1</pre>
<pre>C:\&gt; <strong>route delete 172.16.1.0 mask 255.255.255.0 192.168.1.254</strong></pre>
<pre><strong></strong> </pre>
<pre><strong></strong> </pre>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/06/howto_add_delete_show_route_on_different_os/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ดักจับ Traffic ใน Network ด้วย tcpdump</title>
		<link>http://spalinux.com/2011/06/using_tcpdump_to_capture_traffic_on_network</link>
		<comments>http://spalinux.com/2011/06/using_tcpdump_to_capture_traffic_on_network#comments</comments>
		<pubDate>Fri, 03 Jun 2011 14:44:19 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Console]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Sniffer]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[tcpdump]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1351</guid>
		<description><![CDATA[tcpdump เป็นโปรแกรมประเภทเดียวกับ Sniffer, Wireshark คือใช้ในการดักจับ (capture) Traffic หรือ Packet ที่ รับ/ส่ง เข้า/ออก ระหว่างพอร์ตแลน (LAN) ของเซิรฟ์เวอร์เครื่องที่รันคำสั่ง และอุปกรณ์เครือข่าย (Router, Switch, HUB) มีประโยชน์อย่างมาก เพื่อใช้ในการวิเคราะห์ ตรวจสอบ หรือแก้ปัญหาเกี่ยวกับ Network ได้ tcpdump ต้องรันด้วย root หรือเทียบเท่า และรันแบบ command line ติดตั้งมาเป็นดีฟอลต์บนลีนุกซ์เกือบทุกตระกูล เวอร์ชั่น จึงใช้งานได้สะดวก ไม่ต้องติดตั้งเพิ่มเติมเหมือนโปรแกรมอื่นๆ ในที่นี้ขอแนะนำวิธีการใช้งานเบื้องต้นของ tcpdump รันคำสั่ง tcpdump ล็อกอินเป็น root แล้วพิมพ์คำสั่ง tcpdump หมายเหตุ พอร์ตที่ใช้ในดักจับ packet ไม่จำเป็นต้องใส่ IP Address หรือเป็น IP ในกลุ่มเดียวกับ IP อื่นๆ [...]]]></description>
			<content:encoded><![CDATA[<p>tcpdump เป็นโปรแกรมประเภทเดียวกับ Sniffer, Wireshark คือใช้ในการดักจับ (capture) Traffic หรือ Packet ที่ รับ/ส่ง เข้า/ออก ระหว่างพอร์ตแลน (LAN) ของเซิรฟ์เวอร์เครื่องที่รันคำสั่ง และอุปกรณ์เครือข่าย (Router, Switch, HUB)</p>
<p>มีประโยชน์อย่างมาก เพื่อใช้ในการวิเคราะห์ ตรวจสอบ หรือแก้ปัญหาเกี่ยวกับ Network ได้</p>
<p>tcpdump ต้องรันด้วย root หรือเทียบเท่า และรันแบบ command line ติดตั้งมาเป็นดีฟอลต์บนลีนุกซ์เกือบทุกตระกูล เวอร์ชั่น จึงใช้งานได้สะดวก ไม่ต้องติดตั้งเพิ่มเติมเหมือนโปรแกรมอื่นๆ</p>
<p>ในที่นี้ขอแนะนำวิธีการใช้งานเบื้องต้นของ tcpdump</p>
<h4><span id="more-1351"></span><br />
รันคำสั่ง tcpdump</h4>
<p>ล็อกอินเป็น root แล้วพิมพ์คำสั่ง tcpdump</p>
<p><strong>หมายเหตุ</strong> พอร์ตที่ใช้ในดักจับ packet ไม่จำเป็นต้องใส่ IP Address หรือเป็น IP ในกลุ่มเดียวกับ IP อื่นๆ ใน Network ที่ต้องการดักจับ ขอให้สถานะ Up พอ</p>
<p>หากไม่ระบุออปชั่นใดๆ เลย tcpdump จะเลือกดักจับ packet ที่เข้าออก พอร์ตแลนแรก โดยทั่วไปคือ eth0</p>
<p>ตัวอย่างการรันคำสั่งแบบไม่ระบุออปชั่น</p>
<pre>[root@server ~]# <strong>tcpdump
</strong>tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
09:15:53.948422 IP 192.168.1.102.jwalkserver &gt; server.example.com.ssh: Flags [.], ack 1108, win 64623, length 0
09:15:53.955117 IP server.example.com.ssh &gt; 192.168.1.102.jwalkserver: Flags [P.], seq 1108:1384, ack 1, win 8576, length 276
09:15:53.963948 IP server.example.com.ssh &gt; 192.168.1.102.jwalkserver: Flags [P.], seq 1384:1548, ack 1, win 8576, length 164
09:15:53.964191 IP 192.168.1.102.jwalkserver &gt; server.example.com.ssh: Flags [.], ack 1548, win 64183, length 0
09:15:53.972707 IP server.example.com.ssh &gt; 192.168.1.102.jwalkserver: Flags [P.], seq 1548:1824, ack 1, win 8576, length 276
<span style="color: #ff0000;"><strong>^C</strong></span></pre>
<pre>102 packets captured
102 packets received by filter
0 packets dropped by kernel</pre>
<p>กด [Ctrl-C] เพื่อออกจากคำสั่ง tcpdump ด้านล่างจะมีรายงานสรุปว่า ดักจับได้กี่ packet</p>
<p>ผลลัพธ์ที่แสดงจากคำสั่ง tcpdump จะแตกต่างกันไปขึ้นกับ Network Protocol ที่รับ/ส่ง เช่นถ้าเป็น IP Protocol (TCP, UDP) รูปแบบจะเป็น</p>
<ul>
<li>เวลา</li>
<li>IP</li>
<li>[Source IP Address].[Source Port]</li>
<li>[Destination Address].[Destination Port]</li>
<li>IP, TCP, UDP Headers</li>
</ul>
<p> </p>
<h4>เลือกพอร์ตที่ดักจับ</h4>
<p>ระบุออปชั่น &#8220;-i&#8221; แล้วตามด้วยชื่อพอร์ต เช่น ต้องการจับ packet ที่เข้าออก eth1</p>
<pre>[root@server ~]# <strong>tcpdump -i eth1
</strong>tcpdump: WARNING: eth1: no IPv4 address assigned
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
<span style="color: #ff0000;"><strong>^C</strong></span></pre>
<p>ในที่นี้ พอร์ต eth1 ไม่มีการใส่ IP Address จึงขึ้นฟ้อง &#8220;WARNING: eth1: no IPv4 address assigned&#8221; แต่ก็ยังสามารถดักจับ Traffic ได้</p>
<h4>ไม่ต้องแปลง IP เป็นชื่อ hostname</h4>
<p>ผลลัพธ์ที่แสดงออกมา โปรแกรม tcpdump จะพยายามแปลง IP Address ทั้งต้นทาง ปลายทาง ของ packet ที่ดักจับได้ ให้เป็นชื่อ hostname โดยใช้ไฟล์ /etc/hosts หรือ บริการ DNS</p>
<p>ถ้าหาก traffic มีปริมาณมาก แนะนำให้ปิดคุณสมบัติการพยายามแปลง IP เป็น ชื่อ hostname ออกซะ ด้วยการระบุออปชั่น &#8220;-n&#8221; เพื่อลดโหลด DNS</p>
<pre>[root@server ~]# <strong>tcpdump -i eth0 -l -n
</strong>tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
09:31:10.322145 IP 192.168.1.1.ssh &gt; 192.168.1.102.jwalkserver: Flags [P.], seq 1901277915:1901278111, ack 2244887520, win 8576, length 196
09:31:10.322752 IP 192.168.1.102.jwalkserver &gt; 192.168.1.1.ssh: Flags [.], ack 196, win 65535, length 0
09:31:10.330843 IP 192.168.1.1.ssh &gt; 192.168.1.102.jwalkserver: Flags [P.], seq 196:472, ack 1, win 8576, length 276
09:31:10.332785 IP 192.168.1.1.ssh &gt; 192.168.1.102.jwalkserver: Flags [P.], seq 472:636, ack 1, win 8576, length 164
09:31:10.333209 IP 192.168.1.102.jwalkserver &gt; 192.168.1.1.ssh: Flags [.], ack 636, win 65095, length 0
<span style="color: #ff0000;">^C</span></pre>
<p> </p>
<h4>ไม่ต้องแปลง Port Number เป็นชื่อ Port Name</h4>
<p>หากต้องการแสดงชื่อพอร์ต (TCP, UDP ports) เป็นตัวเลข (ไฟล์ /etc/services)  ให้ระบุออปชั่น &#8220;-n&#8221; เพิ่มอีกหนึ่ง หรือระบุเป็น &#8220;-nn&#8221; เลย</p>
<pre>[root@server ~]# <strong>tcpdump -i eth0 -l -nn
</strong>tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
09:39:38.800430 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: Flags [.], ack 196, win 65535, length 0
09:39:38.802793 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: Flags [P.], seq 196:456, ack 1, win 8576, length 260
09:39:38.805709 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: Flags [P.], seq 456:604, ack 1, win 8576, length 148
09:39:38.805963 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: Flags [.], ack 604, win 65127, length 0
09:39:38.808655 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: Flags [P.], seq 604:848, ack 1, win 8576, length 244
<span style="color: #ff0000;"><strong>^C</strong></span></pre>
<h4>ผลลัพธ์แบบสั้นๆ </h4>
<p>หากไม่สนใจ ข้อมูลใน IP, TCP, UDP Headers ต้องการรู้แค่ว่า IP อะไรคุยกัน ใช้พอร์ตอะไร แค่นั้นพอ ให้ระบุออปชั่น &#8220;-q&#8221;</p>
<pre>[root@server ~]# <strong>tcpdump -i eth0 -l -nn -q
</strong>tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
09:40:48.472427 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 196
09:40:48.473006 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: tcp 0
09:40:48.479252 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 164
09:40:48.487003 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 100
09:40:48.487311 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: tcp 0
<span style="color: #ff0000;"><strong>^C</strong></span></pre>
<p> </p>
<h4>แสดงข้อมูล Layer 2 (MAC Address)</h4>
<p>ระบุออปชั่น &#8220;-e&#8221;  หากต้องการแสดงข้อมูล Layer 2 หรือแสดง Source, Destination MAC Address ด้วย</p>
<pre>[root@server ~]# <strong>tcpdump -i eth0 -l -nn -e -q
</strong>tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
09:44:05.644395 00:11:22:33:44:55 &gt; 00:55:66:77:88:99, IPv4, length 250: 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 196
09:44:05.644959 00:55:66:77:88:99 &gt; 00:11:22:33:44:55, IPv4, length 60: 192.168.1.102.1289 &gt; 192.168.1.1.22: tcp 0
09:44:05.652121 00:11:22:33:44:55 &gt; 00:55:66:77:88:99, IPv4, length 314: 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 260
09:44:05.660897 00:11:22:33:44:55 &gt; 00:55:66:77:88:99, IPv4, length 218: 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 164
09:44:05.661173 00:55:66:77:88:99 &gt; 00:11:22:33:44:55, IPv4, length 60: 192.168.1.102.1289 &gt; 192.168.1.1.22: tcp 0
<span style="color: #ff0000;"><strong>^C</strong></span></pre>
<h4> <br />
save ผลลัพธ์เก็บในไฟล์</h4>
<p>หากต้องการบันทึก (save) ผลลัพธ์ที่ดักจับได้ ให้เหมือนกับหน้าจอที่แสดงขึ้นมา ก็ใช้การ redirection</p>
<p>ตัวอย่าง การเก็บผลลัพธ์ลงไฟล์ ให้เหมือนกับที่แสดงขึ้นมา</p>
<pre>[root@server ~]# <strong>tcpdump -i eth0 -l -nn -q &gt; catpure-display.log
</strong>tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
<span style="color: #ff0000;"><strong>^C</strong></span>
7 packets captured
7 packets received by filter
0 packets dropped by kernel</pre>
<pre>หากต้องการหยุด ก็กดปุ่ม [Ctrl-C] เหมือนกัน</pre>
<p>ใช้คำสั่ง cat เพื่อดูเนื้อหาไฟล์ที่บันทึก</p>
<pre>[root@server ~]# <strong>cat capture-display.log
</strong>09:57:08.118314 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 196
09:57:08.118515 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: tcp 0
09:57:09.138258 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: tcp 36
09:57:09.355761 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: tcp 36
09:57:09.356025 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: tcp 0
<span style="color: #ff0000;"><strong>^C</strong></span></pre>
<p> แต่ถ้าต้องการบันทึกแบบเต็มรูปแบบ ให้ใช้ออปชั่น &#8220;-w&#8221; แล้วตามด้วยชื่อไฟล์ โดยทั่วไปนิยมบันทึกเป็นไฟล์นามสกุล &#8220;.cap&#8221;</p>
<pre>[root@server ~]# <strong>tcpdump -i eth0 -w capture-raw.cap
</strong>tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
<strong><span style="color: #ff0000;">^C</span></strong>
24 packets captured
24 packets received by filter
0 packets dropped by kernel</pre>
<p>ไฟล์ที่บันทึกด้วยออปชั่น &#8220;-w&#8221; สามารถนำมาเปิดย้อนหลังด้วยคำสั่ง tcpdump ตามด้วยออปชั่น &#8220;-r&#8221;  นอกจากนี้ ยังสามารถนำไปเปิดกับโปรแกรม Wireshark ได้อีกด้วย</p>
<pre>[root@server ~]# <strong>tcpdump -r capture-raw.cap -l -nn
</strong>reading from file capture-raw.cap, link-type EN10MB (Ethernet)
10:00:14.959339 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: Flags [P.], seq 105:157, ack 236, win 65431, length 52
10:00:14.972070 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: Flags [P.], seq 236:288, ack 157, win 8576, length 52
10:00:15.137079 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: Flags [.], ack 288, win 65379, length 0
10:00:15.221339 IP 192.168.1.102.1289 &gt; 192.168.1.1.22: Flags [P.], seq 157:209, ack 288, win 65379, length 52
10:00:15.227905 IP 192.168.1.1.22 &gt; 192.168.1.102.1289: Flags [P.], seq 288:340, ack 209, win 8576, length 52
<span style="color: #ff0000;"><strong>^C</strong></span></pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2008/09/verify_lan_network_interface_status_on_linux">ตรวจสอบสถานะของการ์ดเน็ตเวิร์กบนลีนุกซ์</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/06/using_tcpdump_to_capture_traffic_on_network/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ล็อกอินผิดมากเกิน แบนซะด้วย fail2ban</title>
		<link>http://spalinux.com/2011/05/ban_failed_login_attempts_using_fail2ban</link>
		<comments>http://spalinux.com/2011/05/ban_failed_login_attempts_using_fail2ban#comments</comments>
		<pubDate>Sat, 07 May 2011 09:01:08 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Firewall]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[fail2ban]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1316</guid>
		<description><![CDATA[หากเซิร์ฟเวอร์ของคุณตั้งอยู่บนอินเตอร์เน็ต เพื่อให้บริการเว็บไซต์หรืออื่นๆ และคุณจำเป็นต้องเปิด SSH เพื่อสามารถ login เข้าไปตรวจสอบสถานะของเครื่องได้ คุณต้องเคยเจอปัญหานี้แน่นอน คือมีการพยายามเจาะระบบด้วยการ ssh เข้ามา ด้วย user, password ต่างๆ ที่คาดว่าจะมีในเครื่อง ตัวอย่างไฟล์ /var/log/secure แสดงถึงการพยายาม ssh แต่ไม่สำเร็จ May  2 16:39:27 server sshd[8309]: Invalid user john from x.x.x.x May  2 16:39:27 server sshd[8310]: input_userauth_request: invalid user john May  2 16:39:27 server sshd[8309]: pam_unix(sshd:auth): check pass; user unknown May  2 16:39:27 server sshd[8309]: pam_unix(sshd:auth): [...]]]></description>
			<content:encoded><![CDATA[<p>หากเซิร์ฟเวอร์ของคุณตั้งอยู่บนอินเตอร์เน็ต เพื่อให้บริการเว็บไซต์หรืออื่นๆ และคุณจำเป็นต้องเปิด SSH เพื่อสามารถ login เข้าไปตรวจสอบสถานะของเครื่องได้</p>
<p>คุณต้องเคยเจอปัญหานี้แน่นอน คือมีการพยายามเจาะระบบด้วยการ ssh เข้ามา ด้วย user, password ต่างๆ ที่คาดว่าจะมีในเครื่อง</p>
<p><span id="more-1316"></span></p>
<p>ตัวอย่างไฟล์ /var/log/secure แสดงถึงการพยายาม ssh แต่ไม่สำเร็จ</p>
<pre>May  2 16:39:27 server sshd[8309]: Invalid user john from x.x.x.x
May  2 16:39:27 server sshd[8310]: input_userauth_request: invalid user john
May  2 16:39:27 server sshd[8309]: pam_unix(sshd:auth): check pass; user unknown
May  2 16:39:27 server sshd[8309]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=x.x.x.x
May  2 16:39:27 server sshd[8309]: pam_succeed_if(sshd:auth): error retrieving information about user john
May  2 16:39:29 server sshd[8309]: Failed password for invalid user john from x.x.x.x port 3291 ssh2
May  2 16:39:29 server sshd[8310]: Received disconnect from x.x.x.x: 11: Bye Bye</pre>
<pre> </pre>
<p>การป้องกัน หรือคำแนะนำอย่างแรก ที่พึงกระทำคือ ตั้ง user, password ให้ยากต่อการคาดเดา แต่เท่านั้นอาจไม่เพียงพอ</p>
<p>บทความนี้ขอเสนอวิธีการป้องกันด้วย fail2ban ซึ่งจะช่วยแบน ip ที่พยายาม login แต่ไม่สำเร็จได้</p>
<p>หลักการทำงานคร่าวๆ คือ โปรแกรม fail2ban จะคอยตรวจสอบไฟล์ที่ตั้งไว้ โดยค้นหาคำหรือประโยคที่เกิดขึ้นในไฟล์ เมื่อมีการ failed attempts เกิดขึ้นถึงจำนวนครั้งที่กำหนด fail2ban จะทำการบางอย่างที่ตั้งไว้ เช่น รันคำสั่ง iptables เพื่อ DROP packets ได้</p>
<h4>ติดตั้งไฟล์ rpm</h4>
<p>ในที่นี้ทดสอบบน Fedora 14 ต้องติดตั้งไฟล์ rpm เพิ่มเติมดังนี้</p>
<pre>[root@fc14-x64 ~]# <strong>rpm -ivh gamin-python-0.1.10-8.fc14.x86_64.rpm
</strong>[root@fc14-x64 ~]# <strong>rpm -ivh shorewall-4.4.11.1-1.fc14.noarch.rpm
</strong>[root@fc14-x64 ~]# <strong>rpm -ivh fail2ban-0.8.4-25.fc14.noarch.rpm</strong></pre>
<p>เพื่อความชัดเจนในการทดสอบ จะรันคำสั่ง service iptables stop เพื่อเคลียร์ rule ของ iptables ทั้งหมดออกก่อน</p>
<pre>[root@fc14-x64 ~]# <strong>service iptables stop
</strong>iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]</pre>
<p>ใช้คำสั่ง iptables เพื่อแสดง rule ที่ใช้งานอยู่</p>
<pre>[root@fc14-x64 ~]# <strong>iptables -L -v -n
</strong>Chain INPUT (policy ACCEPT 46 packets, 3176 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain OUTPUT (policy ACCEPT 40 packets, 5272 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<p>ใช้คำสั่ง service เพื่อสตาร์ต fail2ban</p>
<pre>[root@fc14-x64 ~]# <strong>service fail2ban start
</strong>Starting fail2ban:                                         [  OK  ]</pre>
<p>ใช้คำสั่ง ps เพื่อดูโปรเซสของ fail2ban</p>
<pre>[root@fc14-x64 ~]# <strong>ps -ef | grep fail2ban
</strong>root      1151     1  0 23:32 ?        00:00:00 /usr/bin/python /usr/bin/fail2ban-server -b -s /var/run/fail2ban/fail2ban.sock -x</pre>
<p>ดูในไฟล์ /var/log/messages แสดงการเริ่มต้นทำงานของ fail2ban</p>
<pre>[root@fc14-x64 ~]# <strong>tail /var/log/messages</strong></pre>
<pre>May  6 23:35:32 fc14-x64 fail2ban.server : INFO   Changed logging target to SYSLOG for Fail2ban v0.8.4
May  6 23:35:32 fc14-x64 fail2ban.jail   : INFO   Creating new jail 'ssh-iptables'
May  6 23:35:32 fc14-x64 fail2ban.jail   : INFO   Jail 'ssh-iptables' uses Gamin
May  6 23:35:32 fc14-x64 fail2ban.filter : INFO   Added logfile = /var/log/secure
May  6 23:35:32 fc14-x64 fail2ban.filter : INFO   Set maxRetry = 5
May  6 23:35:32 fc14-x64 fail2ban.filter : INFO   Set findtime = 600
May  6 23:35:32 fc14-x64 fail2ban.actions: INFO   Set banTime = 600
May  6 23:35:32 fc14-x64 fail2ban.jail   : INFO   Jail 'ssh-iptables' started</pre>
<p>ดีฟอลต์คอนฟิกไฟล์ rpm ที่ได้มาจาก Fedora 14 จะตรวจสอบเฉพาะการพยายาม SSH โดยดูในไฟล์ /var/log/secure</p>
<p>fail2ban จะสร้าง rule และ chain ใหม่ขึ้นมา ใน iptables</p>
<pre>[root@fc14-x64 ~]# <strong>iptables -L -v -n
</strong>Chain INPUT (policy ACCEPT 92 packets, 7885 bytes)
 pkts bytes target     prot opt in     out     source               destination
<span style="color: #0000ff;"><strong>   53  4052 fail2ban-SSH  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:22</strong></span></pre>
<pre>Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain OUTPUT (policy ACCEPT 84 packets, 8087 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain <strong><span style="color: #0000ff;">fail2ban-SSH</span> </strong>(1 references)
 pkts bytes target     prot opt in     out     source               destination
<span style="color: #0000ff;"><strong>   53  4052 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0</strong></span></pre>
<p> </p>
<h4>ไฟล์คอนฟิกของ fail2ban</h4>
<p>ไฟล์คอนฟิกของ fail2ban อยู่ใน /etc/fail2ban/</p>
<p>ไฟล์ /etc/fail2ban/jail.conf จะเป็นการกำหนดการทำงานของ fail2ban</p>
<p>คอนฟิกบางส่วนจากไฟล์ jail.conf</p>
<pre>[root@fc14-x64 ~]# <strong>cat /etc/fail2ban/jail.conf</strong>
...
[DEFAULT]
...
# "bantime" is the number of seconds that a host is banned.
<span style="color: #0000ff;">bantime  = 600</span></pre>
<pre># A host is banned if it has generated "maxretry" during the last "findtime"
# seconds.
<span style="color: #0000ff;">findtime  = 600
</span>...
[ssh-iptables]</pre>
<pre>enabled  = true
filter   = sshd
action   = iptables[name=SSH, port=ssh, protocol=tcp]
           sendmail-whois[name=SSH, dest=root, sender=fail2ban@mail.com]
logpath  = /var/log/secure
maxretry = 5</pre>
<p>คำอธิบายคร่าวๆ จากไฟล์ jail.conf คือ ให้ตรวจสอบ (filter) การ ssh โดยดูในไฟล์ (logpath) /var/log/secure ว่า ถ้ามีการ failed login เกิน (maxretry) ครั้ง ภายในเวลา (findtime) 600 วินาที ให้ทำการ (action) รัน iptables ด้วยออปชั่นในวงเล็บ</p>
<p>สามารถดูรายละเอียด filter ในไฟล์ /etc/fail2ban/filter.d/sshd.conf</p>
<pre>[root@fc14-x64 ~]# <strong>cat /etc/fail2ban/filter.d/sshd.conf
</strong>...
[Definition]</pre>
<pre>_daemon = sshd
...
failregex = ^%(__prefix_line)s(?:error: PAM: )?Authentication failure for .* from &lt;HOST&gt;\s*$
            ^%(__prefix_line)s(?:error: PAM: )?User not known to the underlying authentication module for .* from &lt;HOST&gt;\s*$
            ^%(__prefix_line)sFailed (?:password|publickey) for .* from &lt;HOST&gt;(?: port \d*)?(?: ssh\d*)?$
            ^%(__prefix_line)sROOT LOGIN REFUSED.* FROM &lt;HOST&gt;\s*$
            ^%(__prefix_line)s[iI](?:llegal|nvalid) user .* from &lt;HOST&gt;\s*$
            ^%(__prefix_line)sUser \S+ from &lt;HOST&gt; not allowed because not listed in AllowUsers$
            ^%(__prefix_line)sauthentication failure; logname=\S* uid=\S* euid=\S* tty=\S* ruser=\S* rhost=&lt;HOST&gt;(?:\s+user=.*)?\s*$
            ^%(__prefix_line)srefused connect from \S+ \(&lt;HOST&gt;\)\s*$
            ^%(__prefix_line)sAddress &lt;HOST&gt; .* POSSIBLE BREAK-IN ATTEMPT!*\s*$
            ^%(__prefix_line)sUser \S+ from &lt;HOST&gt; not allowed because none of user's groups are listed in AllowGroups$</pre>
<p>คำอธิบายจากไฟล์คอนฟิก filter คือ ให้ตรวจสอบหาคำหรือประโยคที่ระบุไว้ใน failregex (regular expression)</p>
<p>ส่วน action ที่ทำ หลังจาก maxretry ดูได้ในไฟล์  /etc/fail2ban/action.d/iptables.conf</p>
<pre>[root@fc14-x64 ~]# <strong>cat /etc/fail2ban/action.d/iptables.conf
</strong>...
actionban = iptables -I fail2ban-&lt;name&gt; 1 -s &lt;ip&gt; -j DROP
...
actionunban = iptables -D fail2ban-&lt;name&gt; -s &lt;ip&gt; -j DROP</pre>
<p>คำอธิบาย คือการรันคำสั่ง iptables เพื่อสร้าง rule เพื่อจะ ban &lt;ip&gt; ที่พยายามเข้ามา</p>
<p>และเมื่อเกินเวลา (bantime) 600 วินาที แล้ว ก็รันคำสั่ง iptables เพื่อลบ rule ที่สร้างขึ้น อนุญาตให้ &lt;ip&gt; สามารถเข้ามาได้อีกครั้ง</p>
<h4>ทดสอบการ login fail</h4>
<p><span style="color: #ff0000;"><strong>คำเตือน </strong>การทดลองใช้ fail2ban ให้ลองบนเครื่องที่สามารถ console ได้  เพราะการคอนฟิกหรือลอง login fail จะทำให้คุณไม่สามารถ ssh เข้าเครื่องนั้นได้ ช่วงเวลาหนึ่ง</span></p>
<p>สมมุติให้ลอง ssh login fail ด้วย root จาก 192.168.1.12</p>
<p>ดูไฟล์ /var/log/secure ที่เกิดขึ้นบน server</p>
<pre>[root@fc14-x64 ~]#<strong> tail -f /var/log/secure
</strong>May  6 23:43:47 fc14-x64 unix_chkpwd[1340]: password check failed for user (root)
May  6 23:43:47 fc14-x64 sshd[1338]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.12  user=root
May  6 23:43:49 fc14-x64 sshd[1338]: Failed password for root from 192.168.1.12 port 34811 ssh2</pre>
<pre>May  6 23:43:56 fc14-x64 unix_chkpwd[1342]: password check failed for user (root)
May  6 23:43:58 fc14-x64 sshd[1338]: Failed password for root from 192.168.1.12 port 34811 ssh2</pre>
<pre>May  6 23:44:00 fc14-x64 unix_chkpwd[1343]: password check failed for user (root)
May  6 23:44:01 fc14-x64 sshd[1338]: Failed password for root from 192.168.1.12 port 34811 ssh2
May  6 23:44:01 fc14-x64 sshd[1339]: Connection closed by 192.168.1.12
May  6 23:44:01 fc14-x64 sshd[1338]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.12  user=root</pre>
<pre>May  6 23:44:16 fc14-x64 unix_chkpwd[1348]: password check failed for user (root)
May  6 23:44:16 fc14-x64 sshd[1346]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.12  user=root
May  6 23:44:19 fc14-x64 sshd[1346]: Failed password for root from 192.168.1.12 port 34812 ssh2</pre>
<pre>May  6 23:44:22 fc14-x64 unix_chkpwd[1349]: password check failed for user (root)
May  6 23:44:25 fc14-x64 sshd[1346]: Failed password for root from 192.168.1.12 port 34812 ssh2
May  6 23:44:25 fc14-x64 sshd[1347]: Connection closed by 192.168.1.12
May  6 23:44:25 fc14-x64 sshd[1346]: PAM 1 more authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.1.12  user=root</pre>
<p>เมื่อ login fail เกินค่า maxretry ที่ตั้งไว้ ในที่นี้คือ 5 ครั้ง สังเกตในไฟล์ /var/log/messages  โปรแกรม fail2ban จะทำการ action ขึ้นมา เพื่อ ban 192.168.1.12</p>
<pre>[root@fc14-x64 ~]# <strong>tail /var/log/messages
</strong>May  6 23:44:27 fc14-x64 &lt;28&gt;<span style="color: #0000ff;">fail2ban.actions: WARNING [ssh-iptables] Ban 192.168.1.12</span></pre>
<p>ใช้คำสั่ง iptables เพื่อตรวจสอบ rule ที่เพิ่มขึ้น</p>
<pre>[root@fc14-x64 ~]# <strong>iptables -L -v -n
</strong>Chain INPUT (policy ACCEPT 61 packets, 10699 bytes)
 pkts bytes target     prot opt in     out     source               destination
  453 37587 fail2ban-SSH  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           <span style="color: #0000ff;"><strong>tcp dpt:22</strong></span></pre>
<pre>Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain OUTPUT (policy ACCEPT 60 packets, 7044 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain fail2ban-SSH (1 references)
 pkts bytes target     prot opt in     out     source               destination
<span style="color: #0000ff;"><strong>    2   120 DROP       all  --  *      *       192.168.1.12            0.0.0.0/0
</strong></span>  451 37467 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0</pre>
<p>สังเกตว่า rule ที่สร้างขึ้น จะ DROP เฉพาะการ ssh (tcp 22) เท่านั้น แปลว่า ip ที่ถูก ban ไป จะไม่สามารถ ssh เข้าเครื่อง server ได้อีก แต่ยังสามารถเปิด web (tcp 80) หรืออื่นๆ ได้ตามปกติ</p>
<p>คอนฟิกในไฟล์ jail.conf เมื่อมีการ ban เกิดขึ้น จะมีการส่ง mail หา root ด้วย</p>
<p>ตัวอย่าง mail ที่ส่งให้ root</p>
<pre>From fail2ban@mail.com  Fri May  6 23:44:28 2011
Return-Path: &lt;fail2ban@mail.com&gt;
Date: Fri, 6 May 2011 23:44:27 +0700
Subject: [Fail2Ban] SSH: banned 192.168.1.12
From: Fail2Ban &lt;fail2ban@mail.com&gt;
To: <a href="mailto:root@fc14-x64.example.com">root@fc14-x64.example.com</a>
Status: R</pre>
<pre>Hi,</pre>
<pre>The IP 192.168.1.12 has just been banned by Fail2Ban after 5 attempts against SSH.
...</pre>
<p>เมื่อเวลาผ่านไป เกินเวลา bantime ในที่นี้ 600 วินาที  โปรแกรม fail2ban ก็จะปลดการ ban ออก ดูได้จากไฟล์ /var/log/messsages</p>
<pre>[root@fc14-x64 ~]# <strong>tail /var/log/messages
</strong>May  6 23:44:27 fc14-x64 &lt;28&gt;fail2ban.actions: WARNING [ssh-iptables] Ban 192.168.1.12
May  6 23:54:28 fc14-x64 &lt;28&gt;<span style="color: #0000ff;">fail2ban.actions: WARNING [ssh-iptables] Unban 192.168.1.12</span></pre>
<p>ใช้คำสั่ง iptables เพื่อตรวจสอบ rule ที่ใช้งานอยู่ หลังจาก unban</p>
<pre>[root@fc14-x64 log]# <strong>iptables -L -v -n
</strong>Chain INPUT (policy ACCEPT 561 packets, 50572 bytes)
 pkts bytes target     prot opt in     out     source               destination
 1753  141K fail2ban-SSH  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:22</pre>
<pre>Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain OUTPUT (policy ACCEPT 501 packets, 50410 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<pre>Chain fail2ban-SSH (1 references)
 pkts bytes target     prot opt in     out     source               destination
 1751  141K RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0</pre>
<p> </p>
<p>ลองนำไปใช้ดูครับ เพิ่มความปลอดภัยให้เครื่องได้อีกระดับ</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://www.fail2ban.org/" target="_blank">Fail2ban</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/05/ban_failed_login_attempts_using_fail2ban/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>สร้าง Storage Server ง่ายๆ ด้วย FreeNAS</title>
		<link>http://spalinux.com/2011/02/create_storage_server_using_freenas</link>
		<comments>http://spalinux.com/2011/02/create_storage_server_using_freenas#comments</comments>
		<pubDate>Sat, 19 Feb 2011 09:30:48 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Backup]]></category>
		<category><![CDATA[Disk]]></category>
		<category><![CDATA[File Sharing]]></category>
		<category><![CDATA[Filesystem]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[RAID]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[FreeNAS]]></category>
		<category><![CDATA[NAS]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1284</guid>
		<description><![CDATA[เดี๋ยวนี้เดินตามร้านคอมพิวเตอร์เริ่มมีอุปกรณ์ประเภท NAS (Network Attached Storage Server) ขายเป็น box สำเร็จรูป เพื่อผู้ใช้นำไปสำรองข้อมูล แชร์ไฟล์ได้หลายเครื่อง แถมบางยี่ห้อสามารถรันโปรแกรม BitTorrent เพื่อโหลดไฟล์ได้ แทนที่จะซื้อ box ใหม่ ลองหาเครื่องเก่าๆ ที่ยังพอใช้งานได้อยู่ หากขนาดพื้นที่ดิสก์เก่าไม่พอ ก็ซื้อเฉพาะฮาร์ดดิสก์เท่านั้น แล้วติดตั้งโปรแกรม FreeNAS ภายในไม่ถึง10 นาที  (ไม่รวมเวลาดาวน์โหลดไฟล์ iso ขนาด 130 กว่า MB นะ) คุณก็จะได้ Storage Server ไว้ใช้ อย่างง่ายดาย คุณสมบัติ (features) เพียบ&#8230; คำเตือน FreeNAS จะล้าง (Format) ข้อมูลทั้งหมดในดิสก์ของเครื่อง การทดลองรันแบบ LiveCD ค่าคอนฟิกที่สร้างทั้งหมดจะหายไป เมื่อมีการรีบู๊ตหรือปิดเครื่อง FreeNAS เป็นโปรแกรม Open Source พัฒนาขึ้นมาบน FreeBSD [...]]]></description>
			<content:encoded><![CDATA[<p>เดี๋ยวนี้เดินตามร้านคอมพิวเตอร์เริ่มมีอุปกรณ์ประเภท NAS (Network Attached Storage Server) ขายเป็น box สำเร็จรูป เพื่อผู้ใช้นำไปสำรองข้อมูล แชร์ไฟล์ได้หลายเครื่อง แถมบางยี่ห้อสามารถรันโปรแกรม BitTorrent เพื่อโหลดไฟล์ได้</p>
<p>แทนที่จะซื้อ box ใหม่ ลองหาเครื่องเก่าๆ ที่ยังพอใช้งานได้อยู่ หากขนาดพื้นที่ดิสก์เก่าไม่พอ ก็ซื้อเฉพาะฮาร์ดดิสก์เท่านั้น แล้วติดตั้งโปรแกรม FreeNAS ภายในไม่ถึง10 นาที  (ไม่รวมเวลาดาวน์โหลดไฟล์ iso ขนาด 130 กว่า MB นะ) คุณก็จะได้ Storage Server ไว้ใช้ อย่างง่ายดาย คุณสมบัติ (features) เพียบ&#8230;</p>
<p><span style="color: #ff0000;"><strong>คำเตือน</strong></span></p>
<ul>
<li><span style="color: #ff0000;"><strong>FreeNAS จะล้าง (Format) ข้อมูลทั้งหมดในดิสก์ของเครื่อง</strong></span></li>
<li><span style="color: #ff0000;"><strong>การทดลองรันแบบ LiveCD ค่าคอนฟิกที่สร้างทั้งหมดจะหายไป เมื่อมีการรีบู๊ตหรือปิดเครื่อง</strong></span></li>
</ul>
<p><span id="more-1284"></span></p>
<p>FreeNAS เป็นโปรแกรม Open Source พัฒนาขึ้นมาบน FreeBSD รองรับการใช้งานได้หลากหลายเช่น CIFS (Samba), FTP, NFS, TFTP, AFP, RSYNC, Unison, iSCSI (initiator and target) and UPnP. สามารถคอนฟิกดิสก์เป็นแบบ RAID (0, 1, 5), ZFS, disk encryption ได้</p>
<p>การใช้งานผ่าน Web Interface สามารถลองใช้แบบ LiveCD หรือติดตั้งลงบนดิสก์</p>
<p>ในเริ่มต้น แนะนำในลองใช้แบบ LiveCD เพื่อดูคุณสมบัติต่างๆ ของโปรแกรม</p>
<p>เลือกดาวน์โหลดไฟล์เวอร์ชั่นล่าสุดของ Stable Releases (ล่าสุดที่เขียนคือ 0.7.2) หากเครื่องสามารถลงแบบ 64-bit ได้ แนะนำให้เลือก FreeNAS-amd64-LiveCD-0.7.2.5543.iso ถ้าไม่ได้ ก็ใช้เวอร์ชั่น 32-bit คือ FreeNAS-i386-LiveCD-0.7.2.5543.iso</p>
<p>ไฟล์ที่ดาวน์โหลดจะเป็นแบบ iso คือต้องนำมา burn ลง cd ก่อนแล้วนำไปใช้บู๊ตเครื่อง</p>
<p>ในบทความนี้จะทดลองใน VMware Server</p>
<p>หน้าจอบู๊ตเครื่อง</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/02/01-Boot_FreeNAS1.png"><img class="alignnone size-full wp-image-1302" title="01-Boot_FreeNAS" src="http://spalinux.com/wp-content/uploads/2011/02/01-Boot_FreeNAS1.png" alt="" width="720" height="400" /></a></p>
<p>หน้าจอ Console แสดงข้อมูลคอนฟิกเบื้องต้น พร้อมใช้งาน</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/02/02-FreeNAS_Console1.png"><img class="alignnone size-full wp-image-1301" title="02-FreeNAS_Console" src="http://spalinux.com/wp-content/uploads/2011/02/02-FreeNAS_Console1.png" alt="" width="720" height="400" /></a></p>
<p>เมื่อบู๊ตเครื่องมาถึงขั้นตอนนี้ คุณก็มี Storage Server พร้อมใช้แล้ว หากต้องการแก้ไขคอนฟิก ก็ใส่ตัวเลขเมนู เพื่อเข้าไปแก้ไขได้ เช่นต้องการแก้ไข IP address สามารถทำได้โดยเข้าเมนู 2) Set LAN IP address</p>
<p><strong>คำแนะนำ หากต้องการนำไปใช้งานจริง ต้องเลือกเมนู 9) Install/Upgrade to hard drive/flash device, etc. เพื่อเลือกติดตั้ง FreeNAS ลงบนดิสก์เลย</strong></p>
<p>ดีฟอลต์ IP address คือ 192.168.1.250</p>
<p>เปิด browser เพื่อเริ่มใช้งาน FreeNAS</p>
<p>หน้าเว็บล็อกอินของ FreeNAS  ใส่ค่า Username, Password เริ่มต้นคือ admin, freenas</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/02/03-FreeNAS_Login.png"><img class="alignnone size-full wp-image-1300" title="03-FreeNAS_Login" src="http://spalinux.com/wp-content/uploads/2011/02/03-FreeNAS_Login.png" alt="" width="836" height="724" /></a></p>
<p>หน้าเว็บแสดงข้อมูล System Information</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/02/04-System_Information.png"><img class="alignnone size-full wp-image-1299" title="04-System_Information" src="http://spalinux.com/wp-content/uploads/2011/02/04-System_Information.png" alt="" width="835" height="730" /></a></p>
<p>หน้าเว็บการจัดการดิสก์ (Disks Management)</p>
<p>ไปที่เมนู Disks -&gt; Management เพื่อแสดงข้อมูลดิสก์ที่โปรแกรม FreeNAS รู้จัก</p>
<p>เริ่มต้นจะไม่มีดิสก์ใดแสดงเลย ต้องกดเครื่องหมาย + ด้านขวามือเพื่อเพิ่มดิสก์ที่มีอยู่ในเครื่อง ให้ FreeNAS รู้จัก</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/02/05-Disks_Management.png"><img class="alignnone size-full wp-image-1298" title="05-Disks_Management" src="http://spalinux.com/wp-content/uploads/2011/02/05-Disks_Management.png" alt="" width="835" height="730" /></a></p>
<h4>Add Disk</h4>
<p>หน้าเว็บการเพิ่มดิสก์</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/02/06-Disks_Add.png"><img class="alignnone size-full wp-image-1297" title="06-Disks_Add" src="http://spalinux.com/wp-content/uploads/2011/02/06-Disks_Add.png" alt="" width="835" height="730" /></a></p>
<p>หลังจากเพิ่มดิสก์ ต้องกดปุ่ม [Apply changes] เพื่อให้คอนฟิกที่เพิ่มเข้าไปมีผล</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/02/07-Disks_added.png"><img class="alignnone size-full wp-image-1296" title="07-Disks_added" src="http://spalinux.com/wp-content/uploads/2011/02/07-Disks_added.png" alt="" width="835" height="730" /></a></p>
<h4> </h4>
<h4>Format Disk</h4>
<p>ไปที่เมนู Disks -&gt; Format เพื่อ Format Disk</p>
<p>Disk: เลือกดิสก์ที่จะ format<br />
File system: เลือก &#8220;UFS (GPT and Soft Updates&#8221;<br />
Volume Label: ใส่ชื่อ Volume</p>
<p>กดปุ่ม [Format disk]</p>
<p>หน้าเว็บแสดงการ Format Disk</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/02/08-Disks_Format.png"><img class="alignnone size-full wp-image-1295" title="08-Disks_Format" src="http://spalinux.com/wp-content/uploads/2011/02/08-Disks_Format.png" alt="" width="835" height="730" /></a></p>
<p>หลังจาก Format เครื่องแล้ว ต้อง mount ดิสก์ขึ้นมาใช้งานด้วย</p>
<h4> </h4>
<h4>Mount Disk</h4>
<p>ไปที่เมนู Disks -&gt; Mount Point กดเคื่องหมาย + เพื่อเริ่มการ mount ดิสก์</p>
<p>เลือก Disk และใส่ค่า Mount point name แล้วกด Add</p>
<p>หน้าเว็บ Disks Mount Point &#8211; Add</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/02/09-Disks_Mount_Point_Add.png"><img class="alignnone size-full wp-image-1294" title="09-Disks_Mount_Point_Add" src="http://spalinux.com/wp-content/uploads/2011/02/09-Disks_Mount_Point_Add.png" alt="" width="835" height="730" /></a></p>
<p>กดปุ่ม [Apply changes] เพื่อให้คอนฟิกที่เพิ่มมีผล หน้าเว็บแสดงการ mount point</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/02/10-Disks_Mount_Point_Management.png"><img class="alignnone size-full wp-image-1293" title="10-Disks_Mount_Point_Management" src="http://spalinux.com/wp-content/uploads/2011/02/10-Disks_Mount_Point_Management.png" alt="" width="835" height="730" /></a></p>
<h4> </h4>
<h4>CIFS/SMB Settings</h4>
<p>หากต้องการแชร์ไฟล์แบบ Samba เพื่อให้เครื่อง Windows อื่นๆ มองเห็น ก็สามารถทำได้ง่ายๆ โดยไปที่เมนู Services -&gt; CIFS/SMB</p>
<p>ในหน้า Settings คลิ้กเลือก [x] Enable แล้วใส่ค่าคอนฟิกต่างๆ เสร็จเรียบร้อยด้านล่างกดปุ่ม [Save and Restart]</p>
<p>หน้าเว็บแสดงการเปิด Services CIFS/SMB</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/02/11-Services_CIFS_SMB_Settings.png"><img class="alignnone size-full wp-image-1292" title="11-Services_CIFS_SMB_Settings" src="http://spalinux.com/wp-content/uploads/2011/02/11-Services_CIFS_SMB_Settings.png" alt="" width="835" height="730" /></a><br />
ในหน้าเว็บเดียวกันนี้ คลิ้กแท็ป [Shares] เพื่อคอนฟิกชื่อและดิสก์ที่ใช้แชร์ไฟล์</p>
<p>กดเครื่องหมาย + เพื่อเพิ่มการ Share</p>
<p>ใส่ Name, Comment เลือก Path จาก Mount Point แล้วกดปุ่ม [Add]</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/02/12-Services_CIFS_SMB_Shares_Add.png"><img class="alignnone size-full wp-image-1291" title="12-Services_CIFS_SMB_Shares_Add" src="http://spalinux.com/wp-content/uploads/2011/02/12-Services_CIFS_SMB_Shares_Add.png" alt="" width="835" height="730" /></a></p>
<p>หลังจากแก้ไข กดปุ่ม [Apply changes] เพื่อให้คอนฟิกใหม่มีผล</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/02/13-Services_CIFS_SMB_Shares.png"><img class="alignnone size-full wp-image-1290" title="13-Services_CIFS_SMB_Shares" src="http://spalinux.com/wp-content/uploads/2011/02/13-Services_CIFS_SMB_Shares.png" alt="" width="835" height="730" /></a></p>
<p>ทดลองเรียก Share Drive จากเครื่อง Windows</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/02/14-Windows_Network_Drive.png"><img class="alignnone size-full wp-image-1289" title="14-Windows_Network_Drive" src="http://spalinux.com/wp-content/uploads/2011/02/14-Windows_Network_Drive.png" alt="" width="482" height="345" /></a></p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://freenas.org/" target="_blank">FreeNAS</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/02/create_storage_server_using_freenas/feed</wfw:commentRss>
		<slash:comments>0</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>2</slash:comments>
		</item>
		<item>
		<title>คอนฟิก iSCSI initiator บน Linux</title>
		<link>http://spalinux.com/2009/11/configure_iscsi_initiator_on_linux</link>
		<comments>http://spalinux.com/2009/11/configure_iscsi_initiator_on_linux#comments</comments>
		<pubDate>Sat, 14 Nov 2009 10:19:25 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Disk]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[iSCSI]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=962</guid>
		<description><![CDATA[iSCSI (Internet Small Computer System Interface) เป็นวิธีการเชื่อมต่อ storage โดยผ่าน Internet Protocol (IP) ทำให้สามารถเชื่อมต่อ เครื่องกับ storage ผ่านทาง network ต่างๆ ระยะทางไกลได้ (เป็นข้อดีที่เหนือกว่าการใช้ Fiber Channel ที่ถูกจำกัดระยะทางด้วยสาย Fiber) iSCSI ทำงานในรูปแบบ Server-Client โดย ฝั่ง Client หรือเรียกว่า Initiator ทำหน้าที่ส่ง SCSI command ไปยัง storage ของ Server ปลายทาง ที่เรียกว่า Target บทความนี้กล่าวถึงวิธีการติดตั้งโปรแกรมและคอนฟิก iSCSI ฝั่ง Client เพื่อให้สามารถเรียกใช้ดิสก์ (target) จาก server ได้ โดยฝั่ง server อาจเป็น Storage [...]]]></description>
			<content:encoded><![CDATA[<p>iSCSI (Internet Small Computer System Interface) เป็นวิธีการเชื่อมต่อ storage โดยผ่าน Internet Protocol (IP) ทำให้สามารถเชื่อมต่อ เครื่องกับ storage ผ่านทาง network ต่างๆ ระยะทางไกลได้ (เป็นข้อดีที่เหนือกว่าการใช้ Fiber Channel ที่ถูกจำกัดระยะทางด้วยสาย Fiber)</p>
<p>iSCSI ทำงานในรูปแบบ Server-Client โดย ฝั่ง Client หรือเรียกว่า Initiator ทำหน้าที่ส่ง SCSI command ไปยัง storage ของ Server ปลายทาง ที่เรียกว่า Target</p>
<p>บทความนี้กล่าวถึงวิธีการติดตั้งโปรแกรมและคอนฟิก iSCSI ฝั่ง Client เพื่อให้สามารถเรียกใช้ดิสก์ (target) จาก server ได้ โดยฝั่ง server อาจเป็น Storage Array หรือ Server ที่ถูกคอนฟิกเพื่อทำหน้าที่เป็น target ได้</p>
<p><span id="more-962"></span></p>
<p>ตัวอย่างในบทความนี้ ถือว่าฝั่ง server คอนฟิกสร้าง volume ชื่อ &#8220;vol-01&#8243; และอนุญาตให้เครื่องที่เราจะคอนฟิกสามารถใช้งานได้ (access)</p>
<h4>ติดตั้งไฟล์ rpm</h4>
<p>ตัวอย่างการติดตั้งไฟล์ rpm สำหรับ Fedora 11</p>
<pre>[root@fc11-64a ~]# <strong>rpm -i iscsi-initiator-utils-6.2.0.870-8.fc11.x86_64.rpm</strong></pre>
<h4>ค้นหา target</h4>
<p>เริ่มต้น ต้องค้นหาชื่อ target ปลายทางจาก IP ที่ระบุ โดยใช้คำสั่ง iscsiadm โหมด discovery</p>
<pre>[root@fc11-64a ~]# <strong>iscsiadm -m discovery -t sendtargets -p 192.168.1.1:3260
</strong>Starting iscsid:                                           [  OK  ]
192.168.1.1:3260,1 iqn.2000-10.com.example:0-999999-b8f877804-bfd0000000c13f3e-vss-control
192.168.1.1:3260,1 iqn.2000-10.com.example:0-999999-141376505-58c000000654afe7-vol-01</pre>
<p>หากเป็นการเรียกใช้คำสั่ง iscsiadm ครั้งแรก เซอร์วิส iscsid จะถูกรันขึ้นมาโดยอัตโนมัติ</p>
<p>ตัวอย่างข้อความที่เกิดขึ้นในไฟล์ /var/log/messages ซึ่งไฟล์นี้จะมีประโยชน์มากในการตรวจสอบ และแก้ไขปัญหาที่อาจเกิดขึ้น</p>
<pre>[root@fc11-64a ~]# <strong>tail -f /var/log/messages
</strong>...
Nov 14 16:24:31 fc11-64a kernel: Loading iSCSI transport class v2.0-870.
Nov 14 16:24:31 fc11-64a kernel: iscsi: registered transport (tcp)
Nov 14 16:24:31 fc11-64a kernel: iscsi: registered transport (iser)
Nov 14 16:24:31 fc11-64a iscsid: iSCSI logger with pid=6014 started!
Nov 14 16:24:32 fc11-64a iscsid: transport class version 2.0-870. iscsid version 2.0-870
Nov 14 16:24:32 fc11-64a iscsid: iSCSI daemon with pid=6016 started!</pre>
<h4>login เข้า target ที่ต้องการ</h4>
<p>เมื่อเราทราบชื่อ target ที่ต้องการใช้แล้ว สามารถใช้คำสั่ง iscsiadm โหมด node ระบุออปชั่น &#8216;-l&#8217; เพื่อ login เข้าสู่ target ได้</p>
<pre>[root@fc11-64a ~]# <strong>iscsiadm -m node -p 192.168.1.1 -T iqn.2000-10.com.example:0-999999-141376505-58c000000654afe7-vol-01 -l
</strong>Logging in to [iface: default, target: iqn.2000-10.com.example:0-999999-141376505-58c000000654afe7-vol-01, portal: 192.168.1.1,3260]
Login to [iface: default, target: iqn.2000-10.com.example:0-999999-141376505-58c000000654afe7-vol-01, portal: 192.168.1.1,3260]: successful</pre>
<p>ตัวอย่างข้อความที่เกิดขึ้นในไฟล์ /var/log/messages</p>
<pre>[root@fc11-64a ~]# <strong>tail -f /var/log/messages
</strong>...
Nov 14 16:28:20 fc11-64a kernel: scsi6 : iSCSI Initiator over TCP/IP
Nov 14 16:28:30 fc11-64a kernel: scsi 6:0:0:0: Direct-Access     EXAMPLE  100E-00         x.x  PQ: 0 ANSI: 5
Nov 14 16:28:30 fc11-64a kernel: sd 6:0:0:0: [sdb] 209725440 512-byte hardware sectors: (107 GB/100 GiB)
Nov 14 16:28:30 fc11-64a kernel: sd 6:0:0:0: [sdb] Write Protect is off
Nov 14 16:28:30 fc11-64a kernel: sd 6:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
Nov 14 16:28:30 fc11-64a kernel: sd 6:0:0:0: [sdb] 209725440 512-byte hardware sectors: (107 GB/100 GiB)
Nov 14 16:28:30 fc11-64a kernel: sd 6:0:0:0: [sdb] Write Protect is off
Nov 14 16:28:30 fc11-64a kernel: sd 6:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
Nov 14 16:28:30 fc11-64a kernel: sdb: unknown partition table
Nov 14 16:28:30 fc11-64a kernel: sd 6:0:0:0: [sdb] Attached SCSI disk
Nov 14 16:28:30 fc11-64a kernel: sd 6:0:0:0: Attached scsi generic sg2 type 0
Nov 14 16:28:30 fc11-64a iscsid: connection1:0 is operational now</pre>
<p>จากไฟล์ /var/log/messages เมื่อ login เข้า target สำเร็จ volume จะถูก map เป็นดิสก์ (sdb) ให้เราสามารถเรียกใช้ได้</p>
<p>ใช้คำสั่ง fdisk ตรวจสอบ</p>
<pre>[root@fc11-64a ~]# <strong>fdisk -l /dev/sdb</strong></pre>
<pre>Disk /dev/sdb: 107.3 GB, 107379425280 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000</pre>
<pre>Disk /dev/sdb doesn't contain a valid partition table</pre>
<p>เราสามารถสร้าง partition แล้วสร้าง filesystem ตามที่ต้องการได้เหมือนดิสก์ทั่วๆ ไป</p>
<p>ใช้คำสั่ง fdisk เพื่อสร้าง partition</p>
<pre>[root@fc11-64a ~]# <strong>fdisk /dev/sdb
</strong>Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x52c1bb70.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.</pre>
<pre>The number of cylinders for this disk is set to 13054.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)</pre>
<pre>Command (m for help): <strong>n</strong>
Command action
   e   extended
   p   primary partition (1-4)
<strong>p
</strong>Partition number (1-4): <strong>1
</strong>First cylinder (1-13054, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054):
Using default value 13054</pre>
<pre>Command (m for help): <strong>p</strong></pre>
<pre>Disk /dev/sdb: 107.3 GB, 107379425280 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x52c1bb70</pre>
<pre>   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1       13054   104856223+  83  Linux</pre>
<pre>Command (m for help): <strong>w
</strong>The partition table has been altered!</pre>
<pre>Calling ioctl() to re-read partition table.
Syncing disks.</pre>
<p>ใช้คำสั่ง mkfs.xfs เพื่อสร้าง filesystem แบบ xfs บน partition ที่ถูกสร้างขึ้น</p>
<pre>[root@fc11-64a ~]# <strong>mkfs.xfs /dev/sdb1
</strong>meta-data=/dev/sdb1              isize=256    agcount=4, agsize=6553514 blks
         =                       sectsz=512   attr=2
data     =                       bsize=4096   blocks=26214055, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal log           bsize=4096   blocks=12799, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=0
realtime =none                   extsz=4096   blocks=0, rtextents=0</pre>
<p>ใช้คำสั่ง mount เพื่อ mount filesystem</p>
<pre>[root@fc11-64a ~]# <strong>mount /dev/sdb1 /mnt/vol-01/
</strong>[root@fc11-64a ~]# <strong>cd /mnt/vol-01/
</strong>[root@fc11-64a vol-01]# <strong>df -h .
</strong>Filesystem            Size  Used Avail Use% Mounted on
/dev/sdb1             100G  4.2M  100G   1% /mnt/vol-01</pre>
<h4>เลิกใช้งาน disk</h4>
<p>เมื่อจะเลิกใช้งาน ต้อง umount ก่อน</p>
<pre>[root@fc11-64a ~]# <strong>umount /mnt/vol-01
</strong>[root@fc11-64a ~]#</pre>
<p>ใช้คำสั่ง iscsiadm โหมด node ระบุออปชั่น &#8216;-u&#8217; เพื่อจะ logout ออกจาก target</p>
<pre>[root@fc11-64a ~]# <strong>iscsiadm -m node -p 192.168.1.1 -T iqn.2000-10.com.example:0-999999-141376505-58c000000654afe7-vol-01 -u
</strong>Logging out of session [sid: 1, target: iqn.2000-10.com.example:0-999999-141376505-58c000000654afe7-vol-01, portal: 192.168.1.1,3260]
Logout of [sid: 1, target: iqn.2000-10.com.example:0-999999-141376505-58c000000654afe7-vol-01, portal: 192.168.1.1,3260]: successful</pre>
<p>หลังจาก logout แล้ว ตรวจสอบด้วยคำสั่ง fdisk จะไม่เห็นดิสก์ที่ map ไว้</p>
<pre>[root@fc11-64a ~]# <strong>fdisk -l /dev/sdb
</strong>[root@fc11-64a ~]#</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2009/11/configure_iscsi_target_on_linux">คอนฟิก iSCSI target บน Linux</a></li>
<li><a href="http://en.wikipedia.org/wiki/ISCSI" target="_blank">iSCSI &#8211; Wikipedia</a></li>
<li>man iscsiadm (8)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/11/configure_iscsi_initiator_on_linux/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

