<?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; Programming</title>
	<atom:link href="http://spalinux.com/category/programming/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>เขียนโปรแกรมโหลดเว็บเพจด้วย PHP cURL</title>
		<link>http://spalinux.com/2011/12/program-php-curl-to-load-web-page</link>
		<comments>http://spalinux.com/2011/12/program-php-curl-to-load-web-page#comments</comments>
		<pubDate>Thu, 22 Dec 2011 16:11:06 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[load web page]]></category>
		<category><![CDATA[php curl]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1574</guid>
		<description><![CDATA[จากที่ได้นำเสนอ วิธีการใช้ cURL เพื่อโหลดเว็บเพจ ซึ่งเป็นการรันคำสั่งแบบ command line มาแล้ว คราวนี้จะเป็นการเขียนโปรแกรม PHP โดยเรียกใช้ฟังก์ชั่นในโมดูล curl เพื่อโหลดเว็บเพจ ตรวจสอบโมดูล php curl ก่อนที่เราจะเรียกใช้ฟังก์ชั่นจากโมดูล curl เพื่อเขียนโปรแกรมใน PHP ได้นั้น จำเป็นต้องมีโมดูล curl ติดตั้งอยู่แล้ว ซึ่งสามารถตรวจสอบได้ด้วยการรันคำสั่ง php ตามด้วยออปชั่น &#8216;-m&#8217; ดูผลลัพธ์ที่ได้ ตัวอย่างการรันคำสั่ง php ด้วยออปชั่น &#8216;-m&#8217; เพื่อดูว่ามีโมดูล curl หรือไม่ [user1@dev ~]$ php -m &#124; grep curl curl ถ้าไม่มี ต้องติดตั้งเพิ่มเติม ซึ่งอาจจะด้วยการใช้ rpm หรือ yum ก็ได้ เริ่มใช้ฟังก์ชั่น curl เริ่มต้นด้วยตัวอย่างการเขียนโปรแกรมโดยใช้ฟังก์ชั่น curl [...]]]></description>
			<content:encoded><![CDATA[<p>จากที่ได้นำเสนอ <a href="http://spalinux.com/2011/12/using-curl-to-load-web-page">วิธีการใช้ cURL เพื่อโหลดเว็บเพจ</a> ซึ่งเป็นการรันคำสั่งแบบ command line มาแล้ว</p>
<p>คราวนี้จะเป็นการเขียนโปรแกรม PHP โดยเรียกใช้ฟังก์ชั่นในโมดูล curl เพื่อโหลดเว็บเพจ</p>
<p><span id="more-1574"></span></p>
<h4>ตรวจสอบโมดูล php curl</h4>
<p>ก่อนที่เราจะเรียกใช้ฟังก์ชั่นจากโมดูล curl เพื่อเขียนโปรแกรมใน PHP ได้นั้น จำเป็นต้องมีโมดูล curl ติดตั้งอยู่แล้ว ซึ่งสามารถตรวจสอบได้ด้วยการรันคำสั่ง php ตามด้วยออปชั่น &#8216;-m&#8217; ดูผลลัพธ์ที่ได้</p>
<p>ตัวอย่างการรันคำสั่ง php ด้วยออปชั่น &#8216;-m&#8217; เพื่อดูว่ามีโมดูล curl หรือไม่</p>
<pre>[user1@dev ~]$ <strong>php -m | grep curl</strong>
curl</pre>
<p>ถ้าไม่มี ต้องติดตั้งเพิ่มเติม ซึ่งอาจจะด้วยการใช้ rpm หรือ yum ก็ได้</p>
<h4>เริ่มใช้ฟังก์ชั่น curl</h4>
<p>เริ่มต้นด้วยตัวอย่างการเขียนโปรแกรมโดยใช้ฟังก์ชั่น curl แบบง่ายสุด เพื่อโหลดเว็บเพจ มีสามขั้นตอนคือ</p>
<ul>
<li>curl_init ระบุเว็บไซต์ที่ต้องการโหลด</li>
<li>curl_exec โหลดหน้าเว็บและแสดงผลลัพธ์</li>
<li>curl_close สิ้นสุดการใช้ curl</li>
</ul>
<p>เช่นต้องการโหลดเว็บ www.php.net</p>
<pre>[user1@dev ~]$ <strong>cat curl.php</strong>
&lt;?php

// Create a curl handle
$ch = <span style="color: #0000ff;">curl_init</span>('http://www.php.net');

// Execute
$ret = <span style="color: #0000ff;">curl_exec</span>($ch);

// Close handle
<span style="color: #0000ff;">curl_close</span>($ch);

?&gt;</pre>
<p>ทดลองรันโปรแกรมที่เขียน</p>
<pre>[user1@dev ~]$ <strong>php curl.php</strong>
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
&lt;head&gt;
 &lt;title&gt;PHP: Hypertext Preprocessor&lt;/title&gt;
 &lt;style type="text/css" media="all"&gt;
  @import url("http://static.php.net/www.php.net/styles/site.css");
  @import url("http://static.php.net/www.php.net/styles/phpnet.css");

 &lt;/style&gt;
...</pre>
<p>สังเกตว่าผลลัพธ์การโหลด หรือไฟล์เว็บเพจจะแสดงผลออกหน้าจอเลย เมื่อใช้ฟังก์ชั่น curl_exec() ไม่ได้เก็บไว้ในตัวแปร $ret</p>
<p>หากต้องการเก็บผลลัพธ์ที่ได้ไว้ในตัวแปรก่อน เพื่อนำไปประมวลผล ต้องใช้ฟังก์ชั่น curl_setopt เพื่อตั้งค่า CURLOPT_RETURNTRANSFER ให้เป็น true</p>
<pre>&lt;?php

// Create a curl handle
$ch = curl_init('http://www.php.net');

<span style="color: #0000ff;">// Set curl options</span>
<span style="color: #0000ff;">curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);</span>

// Execute
$ret = curl_exec($ch);

// Return
<span style="color: #0000ff;">print 'return = ' . $ret . "\n";</span>

// Close handle
curl_close($ch);

?&gt;</pre>
<p>ลองรันโปรแกรมหลังจากแก้ไขแล้ว</p>
<pre>[user1@dev ~]$ php curl.php
<span style="color: #0000ff;">return =</span> &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
&lt;head&gt;
 &lt;title&gt;PHP: Hypertext Preprocessor&lt;/title&gt;
 &lt;style type="text/css" media="all"&gt;
  @import url("http://static.php.net/www.php.net/styles/site.css");
  @import url("http://static.php.net/www.php.net/styles/phpnet.css");

 &lt;/style&gt;
...</pre>
<p>&nbsp;</p>
<h4>ดูรายละเอียดการโหลดเว็บเพจ</h4>
<p>หากต้องการดูข้อมูลรายละเอียดของการโหลดเว็บเพจ สามารถใช้ฟังก์ชั่น curl_getinfo() ได้</p>
<pre>&lt;?php

// Create a curl handle
$ch = curl_init('http://www.php.net');

// Set curl options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute
$ret = curl_exec($ch);

<span style="color: #0000ff;">// Get information about the last transfer</span>
<span style="color: #0000ff;">$get_info = curl_getinfo($ch);</span>

<span style="color: #0000ff;">print_r($get_info);</span>

// Close handle
curl_close($ch);

?&gt;</pre>
<p>ผลการรันโปรแกรม จะแสดงค่าเกี่ยวกับการโหลดเว็บเพจทั้งหมด</p>
<pre>[user1@dev ~]$ <strong>php curl.php</strong>
Array
(
    [url] =&gt; http://www.php.net
    [content_type] =&gt; text/html;charset=utf-8
    [http_code] =&gt; 200
    [header_size] =&gt; 382
    [request_size] =&gt; 50
    [filetime] =&gt; -1
    [ssl_verify_result] =&gt; 0
    [redirect_count] =&gt; 0
    [total_time] =&gt; 1.523659
    [namelookup_time] =&gt; 0.006906
    [connect_time] =&gt; 0.249598
    [pretransfer_time] =&gt; 0.249602
    [size_upload] =&gt; 0
    [size_download] =&gt; 45325
    [speed_download] =&gt; 29747
    [speed_upload] =&gt; 0
    [download_content_length] =&gt; -1
    [upload_content_length] =&gt; 0
    [starttransfer_time] =&gt; 0.551071
    [redirect_time] =&gt; 0
    [certinfo] =&gt; Array
        (
        )

)</pre>
<p>&nbsp;</p>
<p>แต่ถ้าต้องการแสดงเฉพาะบางค่า เช่นขนาดไฟล์เว็บเพจที่โหลด ต้องระบุ CURLINFO_SIZE_DOWNLOAD ไว้ในฟังก์ชั่น curl_getinfo() ด้วย</p>
<pre>&lt;?php

// Create a curl handle
$ch = curl_init('http://www.php.net');

// Set curl options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute
$ret = curl_exec($ch);

// Get information about the last transfer
$get_info_size_download = curl_getinfo($ch, <span style="color: #0000ff;">CURLINFO_SIZE_DOWNLOAD</span>);

<span style="color: #0000ff;">print 'SIZE_DOWNLOAD = ' . $get_info_size_download . "\n";</span>

// Close handle
curl_close($ch);

?&gt;</pre>
<p>ผลการรันโปรแกรม</p>
<pre>[user1@dev ~]$ <strong>php curl.php</strong>
SIZE_DOWNLOAD = 45325</pre>
<p>&nbsp;</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://www.php.net/manual/en/intro.curl.php" target="_blank">PHP: cURL Functions &#8211; Manual</a></li>
<li><a href="http://spalinux.com/2011/12/using-curl-to-load-web-page">วิธีการใช้ cURL เพื่อโหลดเว็บเพจ</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/12/program-php-curl-to-load-web-page/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>วิธีการใช้ cURL เพื่อโหลดเว็บเพจ</title>
		<link>http://spalinux.com/2011/12/using-curl-to-load-web-page</link>
		<comments>http://spalinux.com/2011/12/using-curl-to-load-web-page#comments</comments>
		<pubDate>Fri, 16 Dec 2011 16:19:34 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Utility]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[libcurl]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1565</guid>
		<description><![CDATA[จากที่เคยแนะนำ วิธีการใช้คำสั่ง wget รันเป็นคำสั่งบน comand line เพื่อโหลดเว็บเพจได้ มาครั้งนี้ ขอแนะนำอีกคำสั่งคือ cURL โปรแกรมทำหน้าที่คล้ายกันแต่มีคุณสมบัติมากกว่า แถม curl ยังมี library (libcurl) ที่ภาษาต่างๆ เช่น PHP นำไปพัฒนาสร้างเป็นฟังก์ชั่นให้เรียกใช้ในการเขียนโปรแกรมได้ เริ่มต้นการใช้ด้วยการรันคำสั่ง curl ตามด้วย URL ของเว็บไซต์ เช่นต้องการโหลดเว็บหน้าแรกของ www.apple.com [user1@dev ~]$ curl http://www.apple.com &#60;!DOCTYPE html&#62; &#60;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"&#62; &#60;head&#62; &#60;meta http-equiv="content-type" content="text/html; charset=utf-8" /&#62; &#60;meta name="Author" content="Apple Inc." /&#62; &#60;meta name="viewport" content="width=1024" /&#62; &#60;meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7, [...]]]></description>
			<content:encoded><![CDATA[<p>จากที่เคยแนะนำ<a href="http://spalinux.com/2010/01/using_wget"> วิธีการใช้คำสั่ง wget</a> รันเป็นคำสั่งบน comand line เพื่อโหลดเว็บเพจได้ มาครั้งนี้ ขอแนะนำอีกคำสั่งคือ cURL โปรแกรมทำหน้าที่คล้ายกันแต่มีคุณสมบัติมากกว่า แถม curl ยังมี library (libcurl) ที่ภาษาต่างๆ เช่น PHP นำไปพัฒนาสร้างเป็นฟังก์ชั่นให้เรียกใช้ในการเขียนโปรแกรมได้</p>
<p><span id="more-1565"></span><br />
เริ่มต้นการใช้ด้วยการรันคำสั่ง curl ตามด้วย URL ของเว็บไซต์ เช่นต้องการโหลดเว็บหน้าแรกของ www.apple.com</p>
<pre>[user1@dev ~]$ <strong>curl http://www.apple.com</strong>
 &lt;!DOCTYPE html&gt;
 &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"&gt;
 &lt;head&gt;
 &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
 &lt;meta name="Author" content="Apple Inc." /&gt;
 &lt;meta name="viewport" content="width=1024" /&gt;
 &lt;meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7, IE=9" /&gt;
 &lt;link id="globalheader-stylesheet" rel="stylesheet" href="http://images.apple.com/global/nav/styles/navigation.css" type="text/css" /&gt;
 &lt;title&gt;Apple&lt;/title&gt;
 ...</pre>
<p>ดีฟอลต์ผลลัพธ์ที่ได้จะแสดงผลออกทางหน้าจอ (stdout)</p>
<h4>ออปชั่น -o (output)</h4>
<p>ระบุออปชั่น &#8220;-o&#8217; ถ้าต้องการบันทึกผลลัพธ์เป็นไฟล์</p>
<pre>[user1@dev dev]$ <strong>curl -o apple-index.html http://www.apple.com</strong>
 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
 Dload  Upload   Total   Spent    Left  Speed
 100  9346  100  9346    0     0  31031      0 --:--:-- --:--:-- --:--:-- 59151</pre>
<p>ไฟล์ผลลัพธ์ที่ได้</p>
<pre>[user1@dev dev]$ <strong>ls -l</strong>
 total 12
 -rw-r--r--. 1 user1 users 9346 Dec 16 22:56 apple-index.html

[user1@dev dev]$ <strong>head apple-index.html</strong>
 &lt;!DOCTYPE html&gt;
 &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"&gt;
 &lt;head&gt;
 &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
 &lt;meta name="Author" content="Apple Inc." /&gt;
 &lt;meta name="viewport" content="width=1024" /&gt;
 &lt;meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7, IE=9" /&gt;
 &lt;link id="globalheader-stylesheet" rel="stylesheet" href="http://images.apple.com/global/nav/styles/navigation.css" type="text/css" /&gt;
&lt;title&gt;Apple&lt;/title&gt;</pre>
<h4>ออปชั่น -v (verbose)</h4>
<p>หากต้องการดูรายละเอียด ขั้นตอนการโหลดเว็บเพจ สามารถทำได้โดยการระบุออปชั่น &#8220;-v&#8221;</p>
<pre>[user1@dev dev]$ <strong>curl -v http://www.apple.com</strong>
 * About to connect() to www.apple.com port 80 (#0)
 *   Trying 118.214.125.15... connected
 * Connected to www.apple.com (118.214.125.15) port 80 (#0)
 &gt; GET / HTTP/1.1
 &gt; User-Agent: curl/7.21.7 (x86_64-redhat-linux-gnu) libcurl/7.21.7 NSS/3.12.10.0 zlib/1.2.5 libidn/1.22 libssh2/1.2.7
 &gt; Host: www.apple.com
 &gt; Accept: */*
 &gt;
 &lt; HTTP/1.1 200 OK
 &lt; Content-Type: text/html; charset=UTF-8
 &lt; Server: Apache/2.2.3 (Oracle)
 &lt; Cache-Control: max-age=531
 &lt; Expires: Fri, 16 Dec 2011 16:06:55 GMT
 &lt; Date: Fri, 16 Dec 2011 15:58:04 GMT
 &lt; Content-Length: 9346
 &lt; Connection: keep-alive
 &lt;
 &lt;!DOCTYPE html&gt;
 &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"&gt;
 &lt;head&gt;
 &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
 &lt;meta name="Author" content="Apple Inc." /&gt;
 &lt;meta name="viewport" content="width=1024" /&gt;
 &lt;meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7, IE=9" /&gt;
 &lt;link id="globalheader-stylesheet" rel="stylesheet" href="http://images.apple.com/global/nav/styles/navigation.css" type="text/css" /&gt;
&lt;title&gt;Apple&lt;/title&gt;
 ...</pre>
<h4>ออปชั่น -h (help)</h4>
<p>ระบุออปชั่น &#8220;-h&#8221; เพื่อดูออปชั่นอื่นๆ พร้อมคำอธิบายคร่าวๆ</p>
<pre>[user1@dev ~]$ <strong>curl  --help</strong>
Usage: curl [options...] &lt;url&gt;
Options: (H) means HTTP/HTTPS only, (F) means FTP only
     --anyauth       Pick "any" authentication method (H)
 -a, --append        Append to target file when uploading (F/SFTP)
     --basic         Use HTTP Basic Authentication (H)
     --cacert FILE   CA certificate to verify peer against (SSL)
     --capath DIR    CA directory to verify peer against (SSL)
 -E, --cert CERT[:PASSWD] Client certificate file and password (SSL)
     --cert-type TYPE Certificate file type (DER/PEM/ENG) (SSL)
...</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://curl.haxx.se/" target="_blank">cURL groks URLs</a></li>
<li><a href="http://spalinux.com/2010/01/using_wget">วิธีการใช้คำสั่ง wget</a></li>
<li><a href="http://spalinux.com/2011/12/program-php-curl-to-load-web-page">เขียนโปรแกรมโหลดเว็บเพจด้วย PHP cURL</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/12/using-curl-to-load-web-page/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ตัดบางส่วนจากข้อความภาษาไทยด้วย PHP Multibyte String</title>
		<link>http://spalinux.com/2011/11/get-part-from-thai-sentence-using-php-multibyte-string</link>
		<comments>http://spalinux.com/2011/11/get-part-from-thai-sentence-using-php-multibyte-string#comments</comments>
		<pubDate>Tue, 22 Nov 2011 14:02:09 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Thai]]></category>
		<category><![CDATA[mbstring]]></category>
		<category><![CDATA[mutibyte string]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[substr]]></category>
		<category><![CDATA[thai]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1503</guid>
		<description><![CDATA[โปรแกรมประเภทเว็บบอร์ดหรือเว็บ Social ที่ต้องการตัดบางส่วนจากข้อความหรือบทความที่ยาว เพื่อเป็นตัวอย่าง แสดงในหน้าแรก หรือการ Share หัวข้อบทความเป็นตัวอย่าง จากเว็บไซต์อื่นๆ หากเป็นภาษาอังกฤษ สามารถทำได้อย่างง่าย แต่ปัญหาคือเวลาตัดคำภาษาไทย มักจะไม่ได้ตามที่ต้องการ และอาจมีอักษรประหลาดแสดงขึ้นมาด้วย ในบทความนี้จะแสดงการใช้ฟังก์ชั่น PHP Multibyte String เพื่อตัดบางส่วนของข้อความได้ตามต้องการได้ หมายเหตุ เครื่องที่ใช้ทดสอบ ตั้งค่าภาษาในรูปแบบ UTF-8 $ echo $LANG en_US.UTF-8 ถ้าเป็นภาษาอังกฤษ สามารถเขียนโปรแกรม PHP โดยใช้ฟังก์ชั่น substr เช่นต้องการข้อความโดยตัดตั้งแต่อักษรตัวแรก (0) ยาวไปจำนวน 7 ตัว &#60;?php $en_msg = 'This is an example'; print substr($en_msg, 0, 7) . "\n"; ?&#62; รันโปรแกรม ก็จะได้ข้อความตามที่ต้องการ $ php [...]]]></description>
			<content:encoded><![CDATA[<p>โปรแกรมประเภทเว็บบอร์ดหรือเว็บ Social ที่ต้องการตัดบางส่วนจากข้อความหรือบทความที่ยาว เพื่อเป็นตัวอย่าง แสดงในหน้าแรก หรือการ Share หัวข้อบทความเป็นตัวอย่าง จากเว็บไซต์อื่นๆ</p>
<p>หากเป็นภาษาอังกฤษ สามารถทำได้อย่างง่าย แต่ปัญหาคือเวลาตัดคำภาษาไทย มักจะไม่ได้ตามที่ต้องการ และอาจมีอักษรประหลาดแสดงขึ้นมาด้วย</p>
<p>ในบทความนี้จะแสดงการใช้ฟังก์ชั่น PHP Multibyte String เพื่อตัดบางส่วนของข้อความได้ตามต้องการได้</p>
<p><span id="more-1503"></span>หมายเหตุ เครื่องที่ใช้ทดสอบ ตั้งค่าภาษาในรูปแบบ UTF-8</p>
<pre>$ <strong>echo $LANG</strong>
en_US.UTF-8</pre>
<p>ถ้าเป็นภาษาอังกฤษ สามารถเขียนโปรแกรม PHP โดยใช้ฟังก์ชั่น substr เช่นต้องการข้อความโดยตัดตั้งแต่อักษรตัวแรก (0) ยาวไปจำนวน 7 ตัว</p>
<pre><!--?php <br ?-->&lt;?php
$en_msg = 'This is an example';
print <span style="color: #0000ff;">substr($en_msg, 0, 7)</span> . "\n";
?&gt;</pre>
<p>รันโปรแกรม ก็จะได้ข้อความตามที่ต้องการ</p>
<pre>$ <strong>php test-substr.php</strong>
This is</pre>
<p>แต่ถ้าเป็นข้อความภาษาไทย ข้อความที่ตัดได้จะไม่ใช่ เช่น ต้องการตั้งแต่อักษรตัวแรก (0) ยาวไปจำนวน 15 ตัวอักษร&lt;</p>
<pre><!--?php <br ?-->&lt;?php
$th_msg = 'ตัวอย่างข้อความภาษาไทยที่ใช้ทดสอบ';
print substr($th_msg, 0, 15) . "\n";
?&gt;</pre>
<p>ทดลองรันจะได้ตามตัวอย่าง</p>
<pre>$ <strong>php test-substr.php</strong>
ตัวอย</pre>
<p>เนื่องมาจากฟังก์ชั่น substr ไม่สามารถจัดการตัวอักษร UTF-8 ได้อย่างถูกต้อง จำเป็นต้องเปลี่ยนไปใช้ฟังก์ชั่น Multibyte String substr (mb_substr)</p>
<p>รูปแบบการใช้ฟังก์ชั่น mb_substr จะเหมือนกับ substr เพียงแต่ต้องระบุรูปแบบของภาษาด้วย&lt;</p>
<pre><!--?php <br ?-->&lt;?php
$th_msg = 'ตัวอย่างข้อความภาษาไทยที่ใช้ทดสอบ';
print <span style="color: #0000ff;">mb_substr($th_msg, 0, 15, 'UTF-8')</span>;
?&gt;</pre>
<p>ทดลองรันโปรแกรม</p>
<pre>$ <strong>php test-substr.php</strong>
<span style="color: #ff0000;">PHP Fatal error:  Call to undefined function mb_substr() in /home/user1/mbstring/test-substr.php on line 3</span>
หากขึ้น error แบบนี้ แสดงว่าไม่ได้ติดตั้งโมดูล Multibyte String ใน PHP</pre>
<p>ต้องคอมไพล์ PHP ใหม่ หรือติดตั้งไฟล์ rpm ชื่อ php-mbstring เพิ่มเติม</p>
<p>สามารถรัน php ตามด้วยออปชั่น &#8216;-m&#8217; เพื่อดูว่ามีโมดูล mbstring แล้วหรือไม่</p>
<p>หากติดตั้งเพิ่มเติมเรียบร้อยแล้ว</p>
<pre>$ <strong>php -m | grep mbstring</strong>
mbstring</pre>
<p>ทดลองรันอีกครั้ง ก็จะขึ้นจำนวนตัวอักษรถูกต้อง</p>
<pre>$ <strong>php test-substr.php</strong>
ตัวอย่างข้อความ</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://www.php.net/manual/en/function.substr.php" target="_blank">PHP: substr &#8211; Manual</a></li>
<li><a href="http://www.php.net/manual/en/function.mb-substr.php" target="_blank">PHP: mb_substr &#8211; Manual</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/11/get-part-from-thai-sentence-using-php-multibyte-string/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เขียนโปรแกรมด้วย PHP DOM เพื่อดึงข้อมูลจากไฟล์ HTML</title>
		<link>http://spalinux.com/2011/11/programming-using-php-dom-to-parse-html-file</link>
		<comments>http://spalinux.com/2011/11/programming-using-php-dom-to-parse-html-file#comments</comments>
		<pubDate>Sat, 12 Nov 2011 17:02:54 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1493</guid>
		<description><![CDATA[ได้รับข้อมูลในรูปแบบไฟล์ HTML เพื่อให้ดึงค่าจากบางฟิลด์ (field) ออกมา ใช้ในการทำรายงาน ในตอนแรกลองเขียนโปรแกรม PHP ขึ้นมาเอง โดยใช้ Regular Expression ทำไปซักพัก เริ่มยากขึ้น เหตุเพราะรูปแบบอันหลากหลายของไฟล์ HTML ไม่ว่าจะเป็นตัวอักษรพิมพ์ใหญ่เล็ก การเรียงลำดับ tag การเว้นวรรค พบวิธีการดึงข้อมูลโดยใช้ PHP DOM ง่ายขึ้นเยอะ เลยนำมาแชร์เล่าสู่กันฟัง ตัวอย่างไฟล์ test.html เพื่อจะดึงข้อมูล $ cat test.html &#60;html&#62; &#60;head&#62; &#60;title&#62;My Page&#60;/title&#62; &#60;/head&#62; &#60;body&#62; &#60;table&#62;  &#60;tr&#62;   &#60;td id="head_id"&#62;Id&#60;/td&#62;   &#60;td id="head_name"&#62;Name&#60;/td&#62;  &#60;/tr&#62;  &#60;tr&#62;   &#60;td id="data_id1"&#62;&#60;a href="view.php?id=1"&#62;1&#60;/a&#62;&#60;/td&#62;   &#60;td id="data_name1"&#62;Alice&#60;/td&#62;  &#60;/tr&#62;  &#60;tr&#62;   [...]]]></description>
			<content:encoded><![CDATA[<p>ได้รับข้อมูลในรูปแบบไฟล์ HTML เพื่อให้ดึงค่าจากบางฟิลด์ (field) ออกมา ใช้ในการทำรายงาน</p>
<p>ในตอนแรกลองเขียนโปรแกรม PHP ขึ้นมาเอง โดยใช้ Regular Expression ทำไปซักพัก เริ่มยากขึ้น เหตุเพราะรูปแบบอันหลากหลายของไฟล์ HTML ไม่ว่าจะเป็นตัวอักษรพิมพ์ใหญ่เล็ก การเรียงลำดับ tag การเว้นวรรค</p>
<p>พบวิธีการดึงข้อมูลโดยใช้ PHP DOM ง่ายขึ้นเยอะ เลยนำมาแชร์เล่าสู่กันฟัง</p>
<p><span id="more-1493"></span></p>
<p>ตัวอย่างไฟล์ test.html เพื่อจะดึงข้อมูล</p>
<pre>$ <strong>cat test.html</strong>

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My Page&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;table&gt;
 &lt;tr&gt;
  &lt;td id="head_id"&gt;Id&lt;/td&gt;
  &lt;td id="head_name"&gt;Name&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td id="data_id1"&gt;&lt;a href="view.php?id=1"&gt;1&lt;/a&gt;&lt;/td&gt;
  &lt;td id="data_name1"&gt;Alice&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td id="data_id2"&gt;&lt;a href="view.php?id=2"&gt;2&lt;/a&gt;&lt;/td&gt;
  &lt;td id="data_name2"&gt;Bob&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td id="data_id3"&gt;&lt;a href="view.php?id=3"&gt;3&lt;/a&gt;&lt;/td&gt;
  &lt;td id="data_name3"&gt;Carl&lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h4>เริ่มต้นโหลดไฟล์ html ด้วย php dom</h4>
<p>เขียนไฟล์ php เริ่มต้นโหลดไฟล์ html</p>
<pre>&lt;?php
$html = new <span style="color: #0000ff;">DOMDocument</span>();
$html-&gt;<span style="color: #0000ff;">loadHTMLFile</span>('test.html');
var_dump($html);
?&gt;</pre>
<p>คำอธิบาย</p>
<ul>
<li>สร้าง object จาก class ชื่อ DOMDocument ตั้งไว้เป็นตัวแปรชื่อ $html</li>
<li>เรียก method ชื่อ loadHTMLFile เพื่อโหลดไฟล์ HTML ที่ต้องการดึงข้อมูล (parse)</li>
</ul>
<p>ทดลองรันโปรแกรม</p>
<pre>$ <strong>php parse-dom.php</strong>
<span style="color: #ff0000;">PHP Fatal error:  Class 'DOMDocument' not found in /var/www/html/php/dom/parse-dom.php on line 3</span>
$</pre>
<p>รันแล้ว error แบบนี้ เพราะว่าไม่มี php module ที่ชื่อ dom</p>
<p>ต้องติดตั้ง extension ชื่อ libxml เพิ่มเติม ทำได้สองแบบ</p>
<p>หากคอมไพล์ php เอง ต้อง คอมไพล์ใหม่ด้วยการระบุออปชั่น &#8211;enable-libxml เพิ่มเติมตอนรัน configure</p>
<p>แต่ถ้าติดตั้ง php จาก rpm บน Fedora, RedHat หรือ CentOS ต้องติดตั้งไฟล์ php-xml เพิ่มเติม</p>
<p>ตัวอย่างติดตั้ง rpm เพิ่มเติม บน CentOS 5.5 (updates)</p>
<pre>[root@web updates]# <strong>rpm -ivh php53-xml-5.3.3-1.el5.x86_64.rpm</strong>
Preparing...                ########################################### [100%]
   1:php53-xml              ########################################### [100%]</pre>
<p>รัน php ด้วยออปชั่น -m เพื่อดู  module ที่เพิ่มขึ้นมา</p>
<pre>$ <strong>php -m</strong>
...
<span style="color: #0000ff;">dom</span>
wddx
xmlreader
xmlwriter
xsl</pre>
<p>ทดลองรันโปรแกรมอีกครั้ง</p>
<pre>$ <strong>php parse-dom.php</strong>
object(DOMDocument)#1 (0) {
}</pre>
<h4>ดึงข้อมูลตาม html tag ที่ต้องการ</h4>
<p>ทำได้โดยง่ายด้วย method ชื่อ getElementsByTagName() ระบุชื่อ tag ที่ต้องการค้นหา</p>
<p>ตัวอย่าง ต้องการดึงข้อมูลที่อยู่ใน tag &#8220;td&#8221; หรือระหว่าง &lt;td&gt;&lt;/td&gt;</p>
<pre>&lt;?php
$html = new DOMDocument();
$html-&gt;loadHTMLFile('test.html');
$tds = $html-&gt;<span style="color: #0000ff;">getElementsByTagName</span>('td');
foreach ($tds as $td) {
    print $td-&gt;<span style="color: #0000ff;">nodeValue</span> . "\n";
}
?&gt;</pre>
<p>ทดลองรันโปรแกรม จะเห็นผลลัพธ์ที่ได้</p>
<pre>$ <strong>php parse-dom.php</strong>
Id
Name
1
Alice
2
Bob
3
Carl</pre>
<h4>ดึงข้อมูลตาม id ในไฟล์ html ที่ต้องการ</h4>
<p>ทำได้โดยใช้ method ชื่อ <span style="color: #0000ff;">getElementById</span>() ระบุ id ที่ต้องการค้นหา</p>
<p>ตัวอย่าง ต้องการดึงข้อมูลที่อยู่ใน tag ที่ระบุด้วย id &#8220;data_name2&#8243;</p>
<pre>&lt;?php
$html = new DOMDocument();
$html-&gt;loadHTMLFile('test.html');
$id2 = $html-&gt;<span style="color: #0000ff;">getElementById</span>('data_name2');
print $id2-&gt;<span style="color: #0000ff;">nodeValue</span> . "\n";
?&gt;</pre>
<p>ทดลองรันโปรแกรม จะเห็นผลลัพธ์ที่ได้</p>
<pre>$ <strong>php parse-dom.php</strong>
Bob</pre>
<p>ลองนำไปต่อยอด พัฒนากันต่อครับ</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://www.php.net/manual/en/book.dom.php" target="_blank">PHP: DOM &#8211; Manual</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/11/programming-using-php-dom-to-parse-html-file/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ปรับหน้าเว็บเพจให้พอดีหน้าจอ iPhone</title>
		<link>http://spalinux.com/2011/11/how-to-make-web-page-fit-on-iphone-screen</link>
		<comments>http://spalinux.com/2011/11/how-to-make-web-page-fit-on-iphone-screen#comments</comments>
		<pubDate>Mon, 07 Nov 2011 17:47:56 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Safari]]></category>
		<category><![CDATA[viewport]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1475</guid>
		<description><![CDATA[อยู่ในช่วงปรับเว็บเพจที่พัฒนาใช้งานบน PC ให้สามารถรันบน browser ใน มือถือได้ด้วย เลยต้องปรับแต่งหน้าจอเพื่อให้ผู้ใช้งานได้สะดวก ในที่นี้ขอแชร์วิธีการเพิ่มขนาดเว็บเพจ เพื่อให้พอดีกับหน้าจอ Safari บน iPhone ด้วยการใช้ &#8220;viewport&#8221; ตัวอย่างไฟล์ HTML แบบง่ายๆ สำหรับหน้าจอการ Login &#60;html&#62; &#60;head&#62; &#60;title&#62;Login&#60;/title&#62; &#60;/head&#62; &#60;body&#62; &#60;div style="padding: 5px; background-color: #cccccc"&#62; &#60;form&#62; Username:&#60;br&#62; &#60;input type="text" name="username"&#62; &#60;br&#62; Password:&#60;br&#62; &#60;input type="text" name="password"&#62;&#60;br&#62; &#60;br&#62; &#60;input type="submit" value="login"&#62; &#60;/form&#62; &#60;/div&#62; &#60;/body&#62; &#60;/html&#62; เมื่อเปิดด้วย Safari บน iPhone จะเป็นแบบนี้ จะเห็นว่า ขนาดของฟอร์มมีขนาดเล็กเกินไป ผู้ใช้จำต้องขยายขนาด [...]]]></description>
			<content:encoded><![CDATA[<p>อยู่ในช่วงปรับเว็บเพจที่พัฒนาใช้งานบน PC ให้สามารถรันบน browser ใน มือถือได้ด้วย เลยต้องปรับแต่งหน้าจอเพื่อให้ผู้ใช้งานได้สะดวก</p>
<p>ในที่นี้ขอแชร์วิธีการเพิ่มขนาดเว็บเพจ เพื่อให้พอดีกับหน้าจอ Safari บน iPhone ด้วยการใช้ &#8220;viewport&#8221;</p>
<p><span id="more-1475"></span></p>
<p>ตัวอย่างไฟล์ HTML แบบง่ายๆ สำหรับหน้าจอการ Login</p>
<pre>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Login&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div style="padding: 5px; background-color: #cccccc"&gt;
&lt;form&gt;
Username:&lt;br&gt;
&lt;input type="text" name="username"&gt;
&lt;br&gt;
Password:&lt;br&gt;
&lt;input type="text" name="password"&gt;&lt;br&gt;
&lt;br&gt;
&lt;input type="submit" value="login"&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>เมื่อเปิดด้วย Safari บน iPhone จะเป็นแบบนี้</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/11/Picture-001.png"><img class="alignnone size-full wp-image-1477" title="Picture 001" src="http://spalinux.com/wp-content/uploads/2011/11/Picture-001.png" alt="" width="447" height="211" /></a></p>
<p>จะเห็นว่า ขนาดของฟอร์มมีขนาดเล็กเกินไป ผู้ใช้จำต้องขยายขนาด เพื่อจะกดใช้งาน ทำให้ไม่สะดวก</p>
<p>ได้ไอเดียมาจากหน้า login ของโปรแกรม wordpress โดยต้องเพิ่ม tag meta &#8220;viewport&#8221; ในไฟล์ HTML เพื่อให้ขนาดของเว็บเพจมีขนาดใหญ่ขึ้น</p>
<pre>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Login&lt;/title&gt;
<span style="color: #0000ff;">&lt;meta name="viewport" content="width=320; initial-scale=0.9; maximum-scale=1.0; user-scalable=0;" /&gt;</span>
&lt;/head&gt;
&lt;body&gt;
&lt;div style="padding: 5px; background-color: #cccccc"&gt;
&lt;form&gt;
Username:&lt;br&gt;
&lt;input type="text" name="username"&gt;
&lt;br&gt;
Password:&lt;br&gt;
&lt;input type="text" name="password"&gt;&lt;br&gt;
&lt;br&gt;
&lt;input type="submit" value="login"&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>เมื่อเปิดด้วย Safari บน iPhone ขนาดก็จะเพิ่มขึ้นมา</p>
<p><a href="http://spalinux.com/wp-content/uploads/2011/11/Picture-002.png"><img class="alignnone size-full wp-image-1478" title="Picture 002" src="http://spalinux.com/wp-content/uploads/2011/11/Picture-002.png" alt="" width="448" height="285" /></a><br />
สามารถปรับเปลี่ยนตามที่ต้องการได้ ทดลองดูให้เหมาะกับเว็บเพจของคุณ</p>
<pre>&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Login&lt;/title&gt;
<span style="color: #0000ff;">&lt;meta name="viewport" content="width=100%; initial-scale=1.4; maximum-scale=1.4; user-scalable=0;" /&gt; </span>&lt;/head&gt;
&lt;body&gt;
&lt;div style="padding: 5px; background-color: #cccccc"&gt;
&lt;form&gt;
Username:&lt;br&gt;
&lt;input type="text" name="username"&gt;
&lt;br&gt;
Password:&lt;br&gt;
&lt;input type="text" name="password"&gt;&lt;br&gt;
&lt;br&gt;
&lt;input type="submit" value="login"&gt;
&lt;/form&gt;
&lt;/div&gt;</pre>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
<p><a href="http://spalinux.com/wp-content/uploads/2011/11/Picture-003.png"><img class="alignnone size-full wp-image-1479" title="Picture 003" src="http://spalinux.com/wp-content/uploads/2011/11/Picture-003.png" alt="" width="448" height="398" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/11/how-to-make-web-page-fit-on-iphone-screen/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>เลือกออปชัน grep ให้เหมาะ ลดเวลาค้นหาได้มาก</title>
		<link>http://spalinux.com/2011/06/choose-grep-option-to-minimize-run-time</link>
		<comments>http://spalinux.com/2011/06/choose-grep-option-to-minimize-run-time#comments</comments>
		<pubDate>Fri, 24 Jun 2011 16:23:37 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Benchmark]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[egrep]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[regexp]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1387</guid>
		<description><![CDATA[ช่วงนี้รับงาน เพื่อเขียนโปรแกรมดึงข้อมูลจาก text file ทำเป็นรายงานสรุป โดยข้อมูลที่ได้มา มีจำนวนบรรทัดมากมายมหาศาล รวมๆ แล้วเป็น หมื่นล้านบรรทัด ต้องหากระบวนการที่มีประสิทธิภาพมากที่สุดในการเขียนโปรแกรม และเมื่อได้วิธีการที่ผู้เขียนคิดว่าดีที่สุดแล้ว เลยนำมาเปรียบเทียบแชร์เล่าสู่กันฟัง ข้อมูลที่อยู่ในไฟล์ แยกเป็นบรรทัด เหมือนกับ CSV ไฟล์ งานแรกที่ต้องทำคือ เขียนโปรแกรมเพื่อดึงข้อมูลเฉพาะบรรทัดที่มีคำที่ต้องการเท่านั้น หมายเหตุ เพื่อไม่ให้เวลาเพี้ยนไปเนื่องจากการทำ cached file บน Linux  ทุกครั้งก่อนรันคำสั่ง จะรัน cat เพื่อพยายามให้ไฟล์อยู่ใน cached เหมือนกันทุกครั้ง เนื่องจากข้อมูลมีปริมาณมาก การแสดงผลออกหน้าจอจะทำให้เวลาที่ได้เพี้ยนไป ดังนั้น ในการรันทุกคำสั่ง output ที่ได้ จะถูกส่งไปยัง /dev/null ใช้คำสั่ง time เพื่อจับเวลาในการรันคำสั่ง ตัวอย่างการรันคำสั่ง cat ทุกครั้ง เพื่อพยายามโหลดไฟล์ข้อมูลเข้า cached [user1@devel tmp]$ time cat test-data.txt &#62; /dev/null [...]]]></description>
			<content:encoded><![CDATA[<p>ช่วงนี้รับงาน เพื่อเขียนโปรแกรมดึงข้อมูลจาก text file ทำเป็นรายงานสรุป โดยข้อมูลที่ได้มา มีจำนวนบรรทัดมากมายมหาศาล รวมๆ แล้วเป็น หมื่นล้านบรรทัด</p>
<p>ต้องหากระบวนการที่มีประสิทธิภาพมากที่สุดในการเขียนโปรแกรม และเมื่อได้วิธีการที่ผู้เขียนคิดว่าดีที่สุดแล้ว เลยนำมาเปรียบเทียบแชร์เล่าสู่กันฟัง</p>
<p>ข้อมูลที่อยู่ในไฟล์ แยกเป็นบรรทัด เหมือนกับ CSV ไฟล์ งานแรกที่ต้องทำคือ เขียนโปรแกรมเพื่อดึงข้อมูลเฉพาะบรรทัดที่มีคำที่ต้องการเท่านั้น</p>
<p><span id="more-1387"></span></p>
<p>หมายเหตุ</p>
<ul>
<li>เพื่อไม่ให้เวลาเพี้ยนไปเนื่องจากการทำ cached file บน Linux  ทุกครั้งก่อนรันคำสั่ง จะรัน cat เพื่อพยายามให้ไฟล์อยู่ใน cached เหมือนกันทุกครั้ง</li>
<li>เนื่องจากข้อมูลมีปริมาณมาก การแสดงผลออกหน้าจอจะทำให้เวลาที่ได้เพี้ยนไป ดังนั้น ในการรันทุกคำสั่ง output ที่ได้ จะถูกส่งไปยัง /dev/null</li>
<li>ใช้คำสั่ง time เพื่อจับเวลาในการรันคำสั่ง</li>
</ul>
<p>ตัวอย่างการรันคำสั่ง cat ทุกครั้ง เพื่อพยายามโหลดไฟล์ข้อมูลเข้า cached</p>
<pre>[user1@devel tmp]$ <strong>time cat test-data.txt &gt; /dev/null</strong></pre>
<pre>real    0m0.519s
user    0m0.247s
sys     0m0.272s</pre>
<p>ใช้คำสั่ง wc -l เพื่อนับจำนวนบรรทัดของไฟล์ ไฟล์ข้อมูลที่ใช้ทดสอบ มีจำนวนบรรทัด 5,825,368 บรรทัด</p>
<pre>[user1@devel tmp]$ <strong>wc -l cat test-data.txt
</strong>5813492</pre>
<p>ต้องการดึงข้อมูลจากบรรทัดที่มีคำว่า &#8220;jan&#8221; หรือมีคำว่า &#8220;feb&#8221;</p>
<h4>grep -E หรือ egrep (extended-regexp)</h4>
<p>เราสามารถใช้คำสั่ง grep ตามด้วยออปชั่น -E หรือคำสั่ง egrep เพื่อเลือกเฉพาะบรรทัดที่มีคำที่ต้องการแบบมีเงื่อนไข extended regular expression</p>
<pre>[user1@devel tmp]$ <strong>time grep -E "(jan|feb)" test-data.txt  &gt; /dev/null</strong></pre>
<pre><span style="color: #ff0000;">real    0m22.070s</span>
user    0m19.298s
sys     0m3.038s</pre>
<p>หรือใช้คำสั่ง egrep ก็ให้ผลเหมือนกัน</p>
<pre>[user1@devel tmp]$ <strong>time egrep "(jan|feb)" test-data.txt &gt; /dev/null</strong></pre>
<pre><span style="color: #ff0000;">real    0m21.530s</span>
user    0m19.133s
sys     0m2.831s</pre>
<p>ใช้เวลาไปประมาณ 20 กว่าวินาที ก็ได้ผลลัพธ์ที่ต้องการ</p>
<p>แต่เมื่อคิดคำนวนคร่าวๆ   5 ล้านกว่าบรรทัด ใช้เวลา 20 วินาที แล้ว 10,000 ล้านบรรทัดล่ะ นี่ยังไม่รวมกระบวนการอื่นๆ ที่ต้องทำต่อไปอีกนะ &#8211;&#8221;</p>
<h4>grep แยกทีละคำ</h4>
<p>เมื่อคิดเรื่องเวลาแล้ว เลยหาวิธีใหม่ คือทดลอง grep แยกทีละคำ</p>
<p>หาเฉพาะที่มีคำว่า &#8220;jan&#8221; เวลาที่ใช้แค่ 1 วินาทีกว่าๆ</p>
<pre>[user1@devel tmp]$ <strong>time grep "jan" test-data.txt &gt; /dev/null</strong></pre>
<pre><span style="color: #ff0000;">real    0m1.472s</span>
user    0m1.522s
sys     0m0.375s</pre>
<p>หาเฉพาะที่มีคำว่า &#8220;feb&#8221; เวลาที่ใช้ไม่ถึงวินาที</p>
<pre>[user1@devel tmp]$ <strong>time grep "feb" test-data.txt &gt; /dev/null</strong></pre>
<pre><span style="color: #ff0000;">real    0m0.464s</span>
user    0m0.381s
sys     0m0.108s</pre>
<p>รวมๆ แล้ว เร็วกว่ามาก grep แยกทีละคำก็น่าจะดี แต่คงยุ่งยากในการเขียนโปรแกรมพอสมควร ยิ่งถ้ามีคำที่ต้องการค้นหาเพิ่มมาอีก</p>
<h4>*** grep -P (perl-regexp) ***</h4>
<p>อ่าน man page ของ grep พบอีกออปชั่น  -P เป็นการค้นหาคำแบบใช้เงื่อนไขของ Perl regular expression</p>
<pre>[user1@devel tmp]$ <strong>time grep -P "(jan|feb)" test-data.txt &gt; /dev/null</strong></pre>
<pre><span style="color: #0000ff;">real    0m2.063s
</span>user    0m2.143s
sys     0m0.358s</pre>
<p>ลดลงเวลาลงเกือบ 10 เท่า เมื่อเปรียบเทียบกับ grep -E แถมไม่ต้องยุ่งยากกับการเขียนโปรแกรมมากนัก</p>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/06/choose-grep-option-to-minimize-run-time/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>การใช้งานเบื้องต้น Sun Grid Engine</title>
		<link>http://spalinux.com/2011/01/how_to_use_sun_grid_engine</link>
		<comments>http://spalinux.com/2011/01/how_to_use_sun_grid_engine#comments</comments>
		<pubDate>Sat, 29 Jan 2011 09:22:25 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Cluster]]></category>
		<category><![CDATA[Grid]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Oracle Grid Engine]]></category>
		<category><![CDATA[Submit Job]]></category>
		<category><![CDATA[Sun Grid Engine]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1245</guid>
		<description><![CDATA[หลังจากติดตั้ง Sun Grid ทั้งเครื่อง qmaster และ execd host เรียบร้อยแล้ว บทความนี้จะแนะนำวิธีการใช้งานเบื้องต้นของ Sun Grid Engine เพื่อดูสถานะของเครื่อง งานที่รัน และวิธีการส่งงานอย่างง่ายๆ ตั้งค่าตัวแปร setting.sh ต้องรัน source ไฟล์ /gridware/sge/MyCell/common/settings.sh เพื่อตั้งค่าตัวแปรของ sge ก่อนที่จะรันคำสั่ง วิธีการรัน ใช้คำสั่ง source หรือ . เว้นวรรคแล้วตามด้วยชื่อไฟล์ /gridware/sge/MyCell/common/settings.sh [root@cent55-sge ~]# . /gridware/sge/MyCell/common/settings.sh ลองรันคำสั่ง set เพื่อดูค่าตัวแปรที่ถูกตั้งค่า เกี่ยวกับ sge [root@cent55-sge ~]# set &#124; grep -i sge MANPATH=/gridware/sge/man:/usr/share/man/en:/usr/share/man:/usr/local/share/man PATH=/gridware/sge/bin/lx24-amd64:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin SGE_CELL=MyCell SGE_CLUSTER_NAME=MyCluster SGE_ROOT=/gridware/sge คำสั่ง qconf [...]]]></description>
			<content:encoded><![CDATA[<p>หลังจากติดตั้ง Sun Grid ทั้งเครื่อง qmaster และ execd host เรียบร้อยแล้ว บทความนี้จะแนะนำวิธีการใช้งานเบื้องต้นของ Sun Grid Engine เพื่อดูสถานะของเครื่อง งานที่รัน และวิธีการส่งงานอย่างง่ายๆ</p>
<p><span id="more-1245"></span></p>
<h4>ตั้งค่าตัวแปร setting.sh</h4>
<p>ต้องรัน source ไฟล์ /gridware/sge/MyCell/common/settings.sh เพื่อตั้งค่าตัวแปรของ sge ก่อนที่จะรันคำสั่ง</p>
<p>วิธีการรัน ใช้คำสั่ง source หรือ . เว้นวรรคแล้วตามด้วยชื่อไฟล์ /gridware/sge/MyCell/common/settings.sh</p>
<pre>[root@cent55-sge ~]# <strong>. /gridware/sge/MyCell/common/settings.sh</strong></pre>
<p>ลองรันคำสั่ง set เพื่อดูค่าตัวแปรที่ถูกตั้งค่า เกี่ยวกับ sge</p>
<pre>[root@cent55-sge ~]# <strong>set | grep -i sge
</strong>MANPATH=<span style="color: #0000ff;">/gridware/sge/man</span>:/usr/share/man/en:/usr/share/man:/usr/local/share/man
PATH=<span style="color: #0000ff;">/gridware/sge/bin/lx24-amd64</span>:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
<span style="color: #0000ff;">SGE_CELL=MyCell</span>
<span style="color: #0000ff;">SGE_CLUSTER_NAME=MyCluster</span>
<span style="color: #0000ff;">SGE_ROOT=/gridware/sge</span></pre>
<h4>คำสั่ง qconf ดูคอนฟิก</h4>
<p>ใช้คำสั่ง qconf ตามด้วยออปชั่น เพื่อดูค่าคอนฟิกต่างๆ ของ sge</p>
<p>รันคำสั่ง qconf -ss เพื่อดูชื่อเครื่องที่มีสิทธิส่งงานหรือใช้คำสั่ง qsub ได้ (show a list of all submit hosts)</p>
<pre>[root@cent55-sge ~]# <strong>qconf -ss
</strong>cent55-node1.spalinux.com
cent55-node2.spalinux.com
cent55-sge.spalinux.com</pre>
<p>รันคำสั่ง qconf -sel เพื่อดูชื่อเครื่องที่ทำหน้าที่รันงาน (show a list of all exec servers)</p>
<pre>[root@cent55-sge ~]# <strong>qconf -sel
</strong>cent55-node1.spalinux.com
cent55-node2.spalinux.com</pre>
<h4>คำสั่ง qstat ดูสถานะ</h4>
<p>ใช้คำสั่ง qstat ตามด้วยออปชั่น เพื่อดูสถานะของงาน (job) และ queue ในการรันงาน</p>
<p>รันคำสั่ง qstat -f เพื่อดูสถานะของเครื่อง execd host และงานที่รัน</p>
<pre>[root@cent55-sge ~]# <strong>qstat -f
</strong>queuename                      qtype resv/used/tot. load_avg arch          states
---------------------------------------------------------------------------------
all.q@cent55-node1.spalinux.co BIP   0/0/1          0.00     lx24-amd64
---------------------------------------------------------------------------------
all.q@cent55-node2.spalinux.co BIP   0/0/1          0.34     lx24-amd64</pre>
<h4>ทดสอบการส่ง job</h4>
<p>เริ่มต้นจะทดลองส่ง job แบบง่ายๆ รันไฟล์ simple.sh ที่มาจากการติดตั้งโปรแกรม Sun Grid Engine</p>
<p>ไฟล์ simple เป็น shell script ที่รันคำสั่ง date รอ (sleep) 20 วินาที แล้วรันคำสั่ง date อีกครั้ง</p>
<pre>[root@cent55-sge ~]# <strong>cat /gridware/sge/examples/jobs/simple.sh
</strong>#!/bin/sh
#
#
# (c) 2009 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.</pre>
<pre># This is a simple example of a SGE batch script</pre>
<pre># request Bourne shell as shell for job
#$ -S /bin/sh</pre>
<pre>#
# print date and time
date
# Sleep for 20 seconds
sleep 20
# print date and time again
date</pre>
<p>ใช้คำสั่ง qsub ตามด้วยชื่อไฟล์ที่ต้องการรัน</p>
<pre>[root@cent55-sge ~]# <strong>qsub /gridware/sge/examples/jobs/simple.sh
</strong>Your job <span style="color: #0000ff;">206</span> ("simple.sh") has been submitted</pre>
<p>ใช้คำสั่ง qstat -f เพื่อดูสถานะของ job</p>
<pre>[root@cent55-sge ~]# <strong>qstat -f
</strong>queuename                      qtype resv/used/tot. load_avg arch          states
---------------------------------------------------------------------------------
all.q@cent55-node1.spalinux.co BIP   0/0/1          0.00     lx24-amd64
---------------------------------------------------------------------------------
all.q@cent55-node2.spalinux.co BIP   0/0/1          0.09     lx24-amd64</pre>
<pre>############################################################################
 - PENDING JOBS - PENDING JOBS - PENDING JOBS - PENDING JOBS - PENDING JOBS
############################################################################
<span style="color: #0000ff;">    206 0.00000 simple.sh  root         qw    01/29/2011 15:43:06     1</span></pre>
<p>ทดลองพิมพ์คำสั่ง qstat -f ไปเรื่อยๆ ช่วงแรก job 206 จะอยู่ในสถานะ PENDING JOBS คือรอการรัน</p>
<p>ผ่านไปไม่นาน สถานะของ job 206 จะเริ่มรันบนเครื่อง execd host ในตัวอย่างนี้รันบนเครื่อง node1</p>
<pre>[root@cent55-sge ~]# <strong>qstat -f
</strong>queuename                      qtype resv/used/tot. load_avg arch          states
---------------------------------------------------------------------------------
all.q@cent55-node1.spalinux.co BIP   0/1/1          0.00     lx24-amd64
<span style="color: #0000ff;">    206 0.55500 simple.sh  root         r     01/29/2011 15:43:15     1
</span>---------------------------------------------------------------------------------
all.q@cent55-node2.spalinux.co BIP   0/0/1          0.09     lx24-amd64</pre>
<p>หากล็อกอินเครื่อง node1 แล้วใช้คำสั่ง ps  จะเห็นโปรเซสของ job 206</p>
<pre style="text-align: justify;">[root@cent55-node1 ~]# <strong>ps -ef
</strong>...
sgeadmin  2192  2129  0 15:43 ?        00:00:00 sge_shepherd-206 -bg
root      2193  2192  0 15:43 ?        00:00:00 <span style="color: #0000ff;">-sh /gridware/sge/MyCell/spool/cent55-node1/job_scripts/206
</span>root      2218  2193  0 15:43 ?        00:00:00 sleep 20
root      2221  1754  0 15:43 pts/0    00:00:00 ps -ef</pre>
<p>ดูไฟล์โปรเซสที่รันบนเครื่อง node1 ซึ่งก็คือไฟล์ simple.sh นั่นเอง</p>
<pre>[root@cent55-node1 ~]# cat /gridware/sge/MyCell/spool/cent55-node1/job_scripts/206
#!/bin/sh
#
#
# (c) 2009 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.</pre>
<pre># This is a simple example of a SGE batch script</pre>
<pre># request Bourne shell as shell for job
#$ -S /bin/sh</pre>
<pre>#
# print date and time
date
# Sleep for 20 seconds
sleep 20
# print date and time again
date</pre>
<p>หลังจากรันงานเสร็จสิ้น สถานะ job 206 ก็จะหายไปจากคำสั่ง qstat</p>
<pre>[root@cent55-sge ~]# <strong>qstat -f
</strong>queuename                      qtype resv/used/tot. load_avg arch          states
---------------------------------------------------------------------------------
all.q@cent55-node1.spalinux.co BIP   0/0/1          0.00     lx24-amd64
---------------------------------------------------------------------------------
all.q@cent55-node2.spalinux.co BIP   0/0/1          0.09     lx24-amd64</pre>
<p>ผลลัพธ์ที่ได้จากการรันไฟล์ simple.sh จะถูกเก็บไว้บนเครื่อง execd host ที่ทำหน้าที่รัน เช่นในที่นี้คือบน node1</p>
<p>ไฟล์ simple.sh.o206 เก็บผลลัพธ์ standard output จากการรัน job 206</p>
<pre>[root@cent55-node1 ~]# <strong>cat simple.sh.o206
</strong>Sat Jan 29 15:43:14 ICT 2011
Sat Jan 29 15:43:34 ICT 2011</pre>
<p>ไฟล์ simple.sh.e206 เก็บผลลัพธ์ standard error จากการรัน job</p>
<pre>[root@cent55-node1 ~]# <strong>cat simple.sh.e206</strong></pre>
<p>ในที่นี้ไม่มี error จากการรัน ไฟล์จึงว่างเปล่า</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2011/01/install_sun_grid_engine_on_centos_5-5">ติดตั้ง Sun Grid Engine บน CentOS 5.5</a></li>
<li><a href="http://spalinux.com/2011/01/configure_sun_grid_engine_qmaster_host">คอนฟิก Sun Grid Engine qmaster host</a></li>
<li><a href="http://spalinux.com/2011/01/configure_sun_grid_engine_execd_host">คอนฟิก Sun Grid Engine execution (execd) host</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/01/how_to_use_sun_grid_engine/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>คอนฟิก Sun Grid Engine execution (execd) host</title>
		<link>http://spalinux.com/2011/01/configure_sun_grid_engine_execd_host</link>
		<comments>http://spalinux.com/2011/01/configure_sun_grid_engine_execd_host#comments</comments>
		<pubDate>Sat, 29 Jan 2011 07:45:11 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Cluster]]></category>
		<category><![CDATA[Grid]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Oracle Grid Engine]]></category>
		<category><![CDATA[Sun Grid Engine]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1237</guid>
		<description><![CDATA[เช่นเดียวกับเครื่องที่ทำหน้าที่เป็น qmaster  การเริ่มคอนฟิกเครื่อง execd host ก็ต้อง ติดตั้ง Sun Grid Engine บน CentOS 5.5 ก่อนแล้วค่อยคอนฟิกให้ทำหน้าที่เป็น execd host หมายเหตุ ตัวอย่างในบทความนี้คอนฟิกบน node1 เครื่องเดียว ส่วนเครื่องอื่นๆ ที่จะทำหน้าที่เป็น execd host ด้วย ก็คอนฟิกแบบเดียวกัน หลังจากติดตั้ง Sun Grid Engine แล้ว cd ไปยังไดเรคทอรีที่ติดตั้ง sge [root@cent55-node1 sge6_2u5]# cd /gridware/sge/ [root@cent55-node1 sge]# ls -l total 136 drwxr-xr-x  2 root root  4096 Jan  8 22:25 3rd_party drwxr-xr-x  3 root root  [...]]]></description>
			<content:encoded><![CDATA[<p>เช่นเดียวกับเครื่องที่ทำหน้าที่เป็น qmaster  การเริ่มคอนฟิกเครื่อง execd host ก็ต้อง <a href="http://spalinux.com/2011/01/install_sun_grid_engine_on_centos_5-5">ติดตั้ง Sun Grid Engine บน CentOS 5.5</a> ก่อนแล้วค่อยคอนฟิกให้ทำหน้าที่เป็น execd host</p>
<p>หมายเหตุ ตัวอย่างในบทความนี้คอนฟิกบน node1 เครื่องเดียว ส่วนเครื่องอื่นๆ ที่จะทำหน้าที่เป็น execd host ด้วย ก็คอนฟิกแบบเดียวกัน</p>
<p><span id="more-1237"></span></p>
<p>หลังจากติดตั้ง Sun Grid Engine แล้ว cd ไปยังไดเรคทอรีที่ติดตั้ง sge</p>
<pre>[root@cent55-node1 sge6_2u5]# <strong>cd /gridware/sge/</strong></pre>
<pre>[root@cent55-node1 sge]# <strong>ls -l
</strong>total 136
drwxr-xr-x  2 root root  4096 Jan  8 22:25 3rd_party
drwxr-xr-x  3 root root  4096 Jan  8 22:25 bin
drwxr-xr-x  3 root root  4096 Jan  8 22:25 catman
drwxr-xr-x  2 root root  4096 Jan  8 22:25 ckpt
drwxr-xr-x  5 root root  4096 Jan  8 22:25 doc
drwxr-xr-x  2 root root  4096 Jan  8 22:25 dtrace
drwxr-xr-x  5 root root  4096 Jan  8 22:25 examples
drwxr-xr-x  2 root root  4096 Jan  8 22:25 hadoop
drwxr-xr-x  2 root root  4096 Jan  8 22:25 include
-rwxr-xr-x  1 root root   125 Dec 11  2009 install_execd
-rwxr-xr-x  1 root root   125 Dec 11  2009 install_qmaster
-rwxr-xr-x  1 root root 59960 Dec 11  2009 inst_sge
drwxr-xr-x  3 root root  4096 Jan  8 22:25 lib
drwxr-xr-x  6 root root  4096 Jan  8 22:25 man
drwxr-xr-x  4 root root  4096 Jan  8 22:25 mpi
drwxr-xr-x  3 root root  4096 Jan  8 22:25 pvm
drwxr-xr-x  3 root root  4096 Jan  8 22:25 qmon
-rwxr-xr-x  1 root root  1289 Dec 11  2009 start_gui_installer
drwxr-xr-x 10 root root  4096 Jan  8 22:25 util
drwxr-xr-x  3 root root  4096 Jan  8 22:25 utilbin</pre>
<p>ต้อง copy ไดเรคทอรี ของ cell ที่คอนฟิกไว้บนเครื่อง qmaster host</p>
<p>ล็อกอินเข้าเครื่อง sge แล้วรันคำสั่ง tar ใน /gridware/sge/ เพื่อรวมไฟล์ทั้งหมดที่อยู่ในไดเรคทอรีของ cell ในที่นี้เราตั้งชื่อเป็น MyCell</p>
<pre>[root@cent55-sge ~]# <strong>cd /gridware/sge/</strong></pre>
<pre>[root@cent55-sge sge]# <strong>tar jcvpf MyCell.tar.bz2 MyCell/
</strong>MyCell/
MyCell/spool/
MyCell/spool/qmaster/
MyCell/spool/qmaster/heartbeat
MyCell/spool/qmaster/arseqnum
MyCell/spool/qmaster/qmaster.pid
MyCell/spool/qmaster/messages
MyCell/spool/qmaster/job_scripts/
MyCell/spool/qmaster/jobseqnum
MyCell/spool/qmaster/lock
MyCell/spool/spooldb/
MyCell/spool/spooldb/__db.005
MyCell/spool/spooldb/__db.001
MyCell/spool/spooldb/sge_job
MyCell/spool/spooldb/__db.003
MyCell/spool/spooldb/log.0000000001
MyCell/spool/spooldb/__db.004
MyCell/spool/spooldb/__db.002
MyCell/spool/spooldb/sge
MyCell/spool/spooldb/__db.006
MyCell/common/
MyCell/common/settings.csh
MyCell/common/sgeexecd
MyCell/common/act_qmaster
MyCell/common/bootstrap
MyCell/common/sgemaster
MyCell/common/sge_aliases
MyCell/common/sge_request
MyCell/common/cluster_name
MyCell/common/qtask
MyCell/common/settings.sh</pre>
<p>copy ไฟล์ ไปยังเครื่อง node1 โดยอาจใช้คำสั่ง scp หรืออื่นๆ ก็ได้</p>
<pre>[root@cent55-sge sge]# <strong>scp MyCell.tar.bz2 cent55-node1:</strong></pre>
<p>กลับมายังเครื่อง node1 รันคำสั่ง tar เพื่อแตกไฟล์ ไว้ใน /gridware/sge/</p>
<pre>[root@cent55-node1 sge]# <strong>tar jxvf /root/MyCell.tar.bz2
</strong>MyCell/
MyCell/spool/
MyCell/spool/qmaster/
MyCell/spool/qmaster/heartbeat
MyCell/spool/qmaster/arseqnum
MyCell/spool/qmaster/qmaster.pid
MyCell/spool/qmaster/messages
MyCell/spool/qmaster/job_scripts/
MyCell/spool/qmaster/jobseqnum
MyCell/spool/qmaster/lock
MyCell/spool/spooldb/
MyCell/spool/spooldb/__db.005
MyCell/spool/spooldb/__db.001
MyCell/spool/spooldb/sge_job
MyCell/spool/spooldb/__db.003
MyCell/spool/spooldb/log.0000000001
MyCell/spool/spooldb/__db.004
MyCell/spool/spooldb/__db.002
MyCell/spool/spooldb/sge
MyCell/spool/spooldb/__db.006
MyCell/common/
MyCell/common/settings.csh
MyCell/common/sgeexecd
MyCell/common/act_qmaster
MyCell/common/bootstrap
MyCell/common/sgemaster
MyCell/common/sge_aliases
MyCell/common/sge_request
MyCell/common/cluster_name
MyCell/common/qtask
MyCell/common/settings.sh</pre>
<p>รันคำสั่ง ./install_execd หรือ ./inst_sge -x เพื่อติดตั้ง sge บนเครื่องนี้ให้ทำหน้าที่เป็น qmaster host</p>
<p>หน้าจอแสดงเริ่มต้นการติดตั้งเป็น sge execution host</p>
<pre>[root@cent55-node1 sge]# <strong>./inst_sge -x</strong></pre>
<pre>Welcome to the Grid Engine execution host installation
------------------------------------------------------</pre>
<pre>If you haven't installed the Grid Engine qmaster host yet, you must execute
this step (with &gt;install_qmaster&lt;) prior the execution host installation.</pre>
<pre>For a sucessfull installation you need a running Grid Engine qmaster. It is
also neccesary that this host is an administrative host.</pre>
<pre>You can verify your current list of administrative hosts with
the command:</pre>
<pre>   # qconf -sh</pre>
<pre>You can add an administrative host with the command:</pre>
<pre>   # qconf -ah &lt;hostname&gt;</pre>
<pre>The execution host installation will take approximately 5 minutes.</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>ตรวจสอบไดเรคทอรีหลัก</p>
<pre>Checking $SGE_ROOT directory
----------------------------</pre>
<pre>The Grid Engine root directory is:</pre>
<pre>   $SGE_ROOT = /gridware/sge</pre>
<pre>If this directory is not correct (e.g. it may contain an automounter
prefix) enter the correct path to this directory or hit &lt;RETURN&gt;
to use default [/gridware/sge] &gt;&gt;</pre>
<pre>Your $SGE_ROOT directory: /gridware/sge</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>ระบุชื่อ cell ที่คอนฟิกไว้บน qmaster ในที่นี้คือ MyCell</p>
<pre>Grid Engine cells
-----------------</pre>
<pre>Please enter cell name which you used for the qmaster
installation or press &lt;RETURN&gt; to use [default] &gt;&gt; MyCell</pre>
<pre>Using cell: &gt;<span style="color: #0000ff;">MyCell</span>&lt;</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>พอร์ตสำหรับรัน sge_execd</p>
<pre>Grid Engine TCP/IP communication service
----------------------------------------</pre>
<pre>The port for sge_execd is currently set as service.</pre>
<pre>   sge_execd service set to port 10501</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>หาก node นี้อยู่ใน administrative host บน sge qmaster แล้ว</p>
<pre>Checking hostname resolving
---------------------------</pre>
<pre>This hostname is known at qmaster as an administrative host.</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>คอนฟิกไดเรคทอรี spool</p>
<pre>Execd spool directory configuration
-----------------------------------</pre>
<pre>You defined a global spool directory when you installed the master host.
You can use that directory for spooling jobs from this execution host
or you can define a different spool directory for this execution host.</pre>
<pre>ATTENTION: For most operating systems, the spool directory does not have to
be located on a local disk. The spool directory can be located on a
network-accessible drive. However, using a local spool directory provides
better performance.</pre>
<pre>FOR WINDOWS USERS: On Windows systems, the spool directory MUST be located
on a local disk. If you install an execution daemon on a Windows system
without a local spool directory, the execution host is unusable.</pre>
<pre>The spool directory is currently set to:
&lt;&lt;<span style="color: #0000ff;">/gridware/sge/MyCell/spool/cent55-node1</span>&gt;&gt;</pre>
<pre>Do you want to configure a different spool directory
for this host (y/n) [n] &gt;&gt;</pre>
<pre>Creating local configuration
----------------------------
sgeadmin@cent55-node1.spalinux.com added "cent55-node1.spalinux.com" to configuration list
Local configuration for host &gt;cent55-node1.spalinux.com&lt; created.</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt; </pre>
<p>สร้างไฟล์สำหรับรัน sge execd ตอนบู๊ตเครื่อง</p>
<pre>execd startup script
--------------------</pre>
<pre>We can install the startup script that will
start execd at machine boot (y/n) [y] &gt;&gt;</pre>
<pre>cp /gridware/sge/MyCell/common/sgeexecd /etc/init.d/sgeexecd.MyCluster
/usr/lib/lsb/install_initd /etc/init.d/sgeexecd.MyCluster</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<pre>Grid Engine execution daemon startup
------------------------------------</pre>
<pre>Starting execution daemon. Please wait ...
   starting sge_execd</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>เพิ่ม queue</p>
<pre> Adding a queue for this host
----------------------------</pre>
<pre>We can now add a queue instance for this host:</pre>
<pre>   - it is added to the &gt;allhosts&lt; hostgroup
   - the queue provides 1 slot(s) for jobs in all queues
     referencing the &gt;allhosts&lt; hostgroup</pre>
<pre>You do not need to add this host now, but before running jobs on this host
it must be added to at least one queue.</pre>
<pre>Do you want to add a default queue instance for this host (y/n) [y] &gt;&gt;</pre>
<pre>root@cent55-node1.spalinux.com modified "@allhosts" in host group list
root@cent55-node1.spalinux.com modified "all.q" in cluster queue list</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>หน้าจอแสดงวิธีการใช้ sge</p>
<pre>Using Grid Engine
-----------------</pre>
<pre>You should now enter the command:</pre>
<pre>   source /gridware/sge/MyCell/common/settings.csh</pre>
<pre>if you are a csh/tcsh user or</pre>
<pre>   # . /gridware/sge/MyCell/common/settings.sh</pre>
<pre>if you are a sh/ksh user.</pre>
<pre>This will set or expand the following environment variables:</pre>
<pre>   - $SGE_ROOT         (always necessary)
   - $SGE_CELL         (if you are using a cell other than &gt;default&lt;)
   - $SGE_CLUSTER_NAME (always necessary)
   - $SGE_QMASTER_PORT (if you haven't added the service &gt;sge_qmaster&lt;)
   - $SGE_EXECD_PORT   (if you haven't added the service &gt;sge_execd&lt;)
   - $PATH/$path       (to find the Grid Engine binaries)
   - $MANPATH          (to access the manual pages)</pre>
<pre>Hit &lt;RETURN&gt; to see where Grid Engine logs messages &gt;&gt;</pre>
<pre>Grid Engine messages
--------------------</pre>
<pre>Grid Engine messages can be found at:</pre>
<pre>   /tmp/qmaster_messages (during qmaster startup)
   /tmp/execd_messages   (during execution daemon startup)</pre>
<pre>After startup the daemons log their messages in their spool directories.</pre>
<pre>   Qmaster:     /gridware/sge/MyCell/spool/qmaster/messages
   Exec daemon: &lt;execd_spool_dir&gt;/&lt;hostname&gt;/messages</pre>
<pre>Grid Engine startup scripts
---------------------------</pre>
<pre>Grid Engine startup scripts can be found at:</pre>
<pre>   /gridware/sge/MyCell/common/sgemaster (qmaster)
   /gridware/sge/MyCell/common/sgeexecd (execd)</pre>
<pre>Do you want to see previous screen about using Grid Engine again (y/n) [n] &gt;&gt;</pre>
<pre>Your execution daemon installation is now completed.</pre>
<p>ใช้คำสั่ง ps ตรวจสอบโปรเซส sge_execd</p>
<pre>[root@cent55-node1 sge]# <strong>ps -ef | grep sge
</strong>sgeadmin  2346     1  0 22:37 ?        00:00:00 /gridware/sge/bin/lx24-amd64/sge_execd
root      2414  1668  0 22:39 pts/0    00:00:00 grep sge</pre>
<h4> <br />
การเปิด/ปิด เซอร์วิส sge_execd</h4>
<p>การปิดเซอร์วิส sgeexecd</p>
<pre>[root@cent55-node1 sge]# <strong>/etc/init.d/sgeexecd.MyCluster stop
</strong>   Shutting down Grid Engine execution daemon</pre>
<p>การเปิดหรือรันเซอร์วิส sgeexecd</p>
<pre>[root@cent55-node1 sge]# <strong>/etc/init.d/sgeexecd.MyCluster start
</strong>   starting sge_execd</pre>
<h4> <br />
ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2011/01/install_sun_grid_engine_on_centos_5-5">ติดตั้ง Sun Grid Engine บน CentOS 5.5</a></li>
<li><a href="http://spalinux.com/2011/01/configure_sun_grid_engine_qmaster_host">คอนฟิก Sun Grid Engine qmaster host</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/01/configure_sun_grid_engine_execd_host/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>คอนฟิก Sun Grid Engine qmaster host</title>
		<link>http://spalinux.com/2011/01/configure_sun_grid_engine_qmaster_host</link>
		<comments>http://spalinux.com/2011/01/configure_sun_grid_engine_qmaster_host#comments</comments>
		<pubDate>Sat, 15 Jan 2011 16:48:59 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Cluster]]></category>
		<category><![CDATA[Grid]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Oracle Grid Engine]]></category>
		<category><![CDATA[Sun Grid Engine]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1231</guid>
		<description><![CDATA[หลังจาก ติดตั้ง Sun Grid Engine บน CentOS 5.5 แล้ว บทความนี้จะกล่าวถึงวิธีการคอนฟิก sge ให้ทำหน้าที่เป็น qmaster host สำหรับจัดการเรื่อง job เริ่มต้น ใช้คำสั่ง cd ไปยังไดเรคทอรีที่ติดตั้ง sge [root@cent55-sge sge6_2u5]# cd /gridware/sge/ [root@cent55-sge sge]# ls -l total 136 drwxr-xr-x  2 root root  4096 Jan  8 12:40 3rd_party drwxr-xr-x  3 root root  4096 Jan  8 12:48 bin drwxr-xr-x  3 root root  4096 Jan  [...]]]></description>
			<content:encoded><![CDATA[<p>หลังจาก <a href="http://spalinux.com/2011/01/install_sun_grid_engine_on_centos_5-5">ติดตั้ง Sun Grid Engine บน CentOS 5.5</a> แล้ว บทความนี้จะกล่าวถึงวิธีการคอนฟิก sge ให้ทำหน้าที่เป็น qmaster host สำหรับจัดการเรื่อง job</p>
<p><span id="more-1231"></span>เริ่มต้น ใช้คำสั่ง cd ไปยังไดเรคทอรีที่ติดตั้ง sge</p>
<pre>[root@cent55-sge sge6_2u5]# <strong>cd /gridware/sge/</strong></pre>
<pre>[root@cent55-sge sge]# <strong>ls -l
</strong>total 136
drwxr-xr-x  2 root root  4096 Jan  8 12:40 3rd_party
drwxr-xr-x  3 root root  4096 Jan  8 12:48 bin
drwxr-xr-x  3 root root  4096 Jan  8 12:40 catman
drwxr-xr-x  2 root root  4096 Jan  8 12:40 ckpt
drwxr-xr-x  5 root root  4096 Jan  8 12:40 doc
drwxr-xr-x  2 root root  4096 Jan  8 12:40 dtrace
drwxr-xr-x  5 root root  4096 Jan  8 12:48 examples
drwxr-xr-x  2 root root  4096 Jan  8 12:40 hadoop
drwxr-xr-x  2 root root  4096 Jan  8 12:40 include
-rwxr-xr-x  1 root root   125 Dec 11  2009 install_execd
-rwxr-xr-x  1 root root   125 Dec 11  2009 install_qmaster
-rwxr-xr-x  1 root root 59960 Dec 11  2009 inst_sge
drwxr-xr-x  3 root root  4096 Jan  8 12:48 lib
drwxr-xr-x  6 root root  4096 Jan  8 12:40 man
drwxr-xr-x  4 root root  4096 Jan  8 12:40 mpi
drwxr-xr-x  3 root root  4096 Jan  8 12:40 pvm
drwxr-xr-x  3 root root  4096 Jan  8 12:40 qmon
-rwxr-xr-x  1 root root  1289 Dec 11  2009 start_gui_installer
drwxr-xr-x 10 root root  4096 Jan  8 12:40 util
drwxr-xr-x  3 root root  4096 Jan  8 12:48 utilbin</pre>
<p>รันคำสั่ง ./install_qmaster หรือ ./inst_sge -m เพื่อเริ่มคอนฟิก sge บนเครื่องนี้ ให้ทำหน้าที่เป็น qmaster host</p>
<pre>[root@cent55-sge sge]# <strong>./inst_sge -m
</strong>Sun Microsystems, Inc. ("Sun") SOFTWARE LICENSE AGREEMENT</pre>
<pre>READ THE TERMS OF THIS AGREEMENT ("AGREEMENT") CAREFULLY BEFORE OPENING
SOFTWARE MEDIA PACKAGE. BY OPENING SOFTWARE MEDIA PACKAGE, YOU AGREE TO THE
TERMS OF THIS AGREEMENT. IF YOU ARE ACCESSING SOFTWARE ELECTRONICALLY,
INDICATE YOUR ACCEPTANCE OF THESE TERMS BY SELECTING THE "ACCEPT" (OR
EQUIVALENT) BUTTON AT THE END OF THIS AGREEMENT. IF YOU DO NOT AGREE TO ALL
OF THE TERMS, PROMPTLY RETURN THE UNUSED SOFTWARE TO YOUR PLACE OF PURCHASE
FOR A REFUND OR, IF SOFTWARE IS ACCESSED ELECTRONICALLY, SELECT THE
"DECLINE" (OR "EXIT") BUTTON AT THE END OF THIS AGREEMENT. IF YOU HAVE
SEPARATELY AGREED TO LICENSE TERMS ("MASTER TERMS") FOR YOUR LICENSE TO THIS
SOFTWARE, THEN SECTIONS 1-6 OF THIS AGREEMENT ("SUPPLEMENTAL LICENSE TERMS")
SHALL SUPPLEMENT AND SUPERSEDE THE MASTER TERMS IN RELATION TO THIS
SOFTWARE.</pre>
<pre>...
...</pre>
<pre>17. Records and Documentation.? During the term of the SLA and Entitlement,
and for a period of three (3) years thereafter, You agree to keep proper
records and documentation of Your compliance with the SLA and Entitlement.
Upon Sun?s reasonable request, You will provide copies of such records and
documentation to Sun for the purpose of confirming Your compliance with the
terms and conditions of the SLA and Entitlement. This section will survive
any termination of the SLA and Entitlement. You may terminate this SLA and
Entitlement at any time by destroying all copies of the Software in which
case the obligations set forth in Section 7 of the SLA shall apply.</pre>
<pre>หน้าจอแสดง LICENSE AGREEMENT ตอบ "y" เพื่อยอมรับ</pre>
<pre>Do you agree with that license? (y/n) [n] &gt;&gt; <strong>y</strong></pre>
<p>หน้าแสดงการเริ่มต้นติดตั้ง</p>
<pre>Welcome to the Grid Engine installation
---------------------------------------</pre>
<pre>Grid Engine qmaster host installation
-------------------------------------</pre>
<pre>Before you continue with the installation please read these hints:</pre>
<pre>   - Your terminal window should have a size of at least
     80x24 characters</pre>
<pre>   - The INTR character is often bound to the key Ctrl-C.
     The term &gt;Ctrl-C&lt; is used during the installation if you
     have the possibility to abort the installation</pre>
<pre>The qmaster installation procedure will take approximately 5-10 minutes.</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>เลือก user ที่ไม่ใช่ root สำหรับรัน sge</p>
<pre>Grid Engine admin user account
------------------------------</pre>
<pre>The current directory</pre>
<pre>   /gridware/sge</pre>
<pre>is owned by user</pre>
<pre>   <span style="color: #0000ff;"><strong>sgeadmin</strong></span></pre>
<pre>If user &gt;root&lt; does not have write permissions in this directory on *all*
of the machines where Grid Engine will be installed (NFS partitions not
exported for user &gt;root&lt; with read/write permissions) it is recommended to
install Grid Engine that all spool files will be created under the user id
of user &gt;sgeadmin&lt;.</pre>
<pre>IMPORTANT NOTE: The daemons still have to be started by user &gt;root&lt;.</pre>
<pre>Do you want to install Grid Engine as admin user &gt;sgeadmin&lt; (y/n) [y] &gt;&gt;</pre>
<pre>Installing Grid Engine as admin user &gt;sgeadmin&lt;
Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>ไดเรคทอรีหลักของ sge</p>
<pre>Checking $SGE_ROOT directory
----------------------------</pre>
<pre>The Grid Engine root directory is:</pre>
<pre>   $SGE_ROOT = /gridware/sge</pre>
<pre>If this directory is not correct (e.g. it may contain an automounter
prefix) enter the correct path to this directory or hit &lt;RETURN&gt;
to use default [/gridware/sge] &gt;&gt;</pre>
<pre>Your $SGE_ROOT directory: <strong><span style="color: #0000ff;">/gridware/sge</span></strong></pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>เลือกหมายเลขพอร์ตสำหรับรัน sge_qmaster</p>
<pre>Grid Engine TCP/IP communication service
----------------------------------------</pre>
<pre>The port for sge_qmaster is currently set as service.</pre>
<pre><span style="color: #0000ff;">   sge_qmaster service set to port 10500</span></pre>
<pre>Now you have the possibility to set/change the communication ports by using the
&gt;shell environment&lt; or you may configure it via a network service, configured
in local &gt;/etc/service&lt;, &gt;NIS&lt; or &gt;NIS+&lt;, adding an entry in the form</pre>
<pre>    sge_qmaster &lt;port_number&gt;/tcp</pre>
<pre>to your services database and make sure to use an unused port number.</pre>
<pre>How do you want to configure the Grid Engine communication ports?</pre>
<pre>Using the &gt;shell environment&lt;:                           [1]</pre>
<pre>Using a network service like &gt;/etc/service&lt;, &gt;NIS/NIS+&lt;: [2]</pre>
<pre>(default: 2) &gt;&gt;</pre>
<pre>Grid Engine TCP/IP service &gt;sge_qmaster&lt;
----------------------------------------</pre>
<pre>Using the service</pre>
<pre>   sge_qmaster</pre>
<pre>for communication with Grid Engine.</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p> เลือกหมายเลขพอร์ตสำหรับรัน sge_execd</p>
<pre> Grid Engine TCP/IP communication service
----------------------------------------</pre>
<pre>The port for sge_execd is currently set as service.</pre>
<pre><span style="color: #0000ff;">   sge_execd service set to port 10501</span></pre>
<pre>Now you have the possibility to set/change the communication ports by using the
&gt;shell environment&lt; or you may configure it via a network service, configured
in local &gt;/etc/service&lt;, &gt;NIS&lt; or &gt;NIS+&lt;, adding an entry in the form</pre>
<pre>    sge_execd &lt;port_number&gt;/tcp</pre>
<pre>to your services database and make sure to use an unused port number.</pre>
<pre>How do you want to configure the Grid Engine communication ports?</pre>
<pre>Using the &gt;shell environment&lt;:                           [1]</pre>
<pre>Using a network service like &gt;/etc/service&lt;, &gt;NIS/NIS+&lt;: [2]</pre>
<pre>(default: 2) &gt;&gt;</pre>
<pre> </pre>
<pre>Grid Engine TCP/IP communication service
-----------------------------------------</pre>
<pre>Using the service</pre>
<pre>   sge_execd</pre>
<pre>for communication with Grid Engine.</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>ตั้งชื่อ cell ในที่นี้จะตั้งเป็น MyCell</p>
<p>หมายเหตุ ชื่อ cell ใช้ในการจัดกลุ่มเพื่อส่งงานระหว่าง qmaster host และ execution host</p>
<pre> Grid Engine cells
-----------------</pre>
<pre>Grid Engine supports multiple cells.</pre>
<pre>If you are not planning to run multiple Grid Engine clusters or if you don't
know yet what is a Grid Engine cell it is safe to keep the default cell name</pre>
<pre>   default</pre>
<pre>If you want to install multiple cells you can enter a cell name now.</pre>
<pre>The environment variable</pre>
<pre>   $SGE_CELL=&lt;your_cell_name&gt;</pre>
<pre>will be set for all further Grid Engine commands.</pre>
<pre>Enter cell name [default] &gt;&gt; <strong><span style="color: #000000;">MyCell</span></strong></pre>
<pre>Using cell &gt;MyCell&lt;.
Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>ตั้งชื่อ cluster ในที่นี้ตั้งเป็น MyCluster</p>
<pre>Unique cluster name
-------------------</pre>
<pre>The cluster name uniquely identifies a specific Sun Grid Engine cluster.
The cluster name must be unique throughout your organization. The name
is not related to the SGE cell.</pre>
<pre>The cluster name must start with a letter ([A-Za-z]), followed by letters,
digits ([0-9]), dashes (-) or underscores (_).</pre>
<pre>Enter new cluster name or hit &lt;RETURN&gt;
to use default [p10500] &gt;&gt; <strong>MyCluster</strong></pre>
<pre>creating directory: /gridware/sge/MyCell/common</pre>
<pre>Your $SGE_CLUSTER_NAME: MyCluster</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>ไดเรคทอรี spool ของ qmaster</p>
<pre> Grid Engine qmaster spool directory
-----------------------------------</pre>
<pre>The qmaster spool directory is the place where the qmaster daemon stores
the configuration and the state of the queuing system.</pre>
<pre>The admin user &gt;sgeadmin&lt; must have read/write access
to the qmaster spool directory.</pre>
<pre>If you will install shadow master hosts or if you want to be able to start
the qmaster daemon on other hosts (see the corresponding section in the
Grid Engine Installation and Administration Manual for details) the account
on the shadow master hosts also needs read/write access to this directory.</pre>
<pre>Enter a qmaster spool directory [<strong><span style="color: #0000ff;">/gridware/sge/MyCell/spool/qmaster</span></strong>] &gt;&gt;</pre>
<pre>Using qmaster spool directory &gt;/gridware/sge/MyCell/spool/qmaster&lt;.
Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>จะรัน sge บนเครื่อง Windows ด้วยหรือไม่</p>
<pre>Windows Execution Host Support
------------------------------</pre>
<pre>Are you going to install Windows Execution Hosts? (y/n) [n] &gt;&gt;</pre>
<p>ตรวจสอบไฟล์ permission</p>
<pre>Verifying and setting file permissions
--------------------------------------</pre>
<pre>Did you install this version with &gt;pkgadd&lt; or did you already verify
and set the file permissions of your distribution (enter: y) (y/n) [y] &gt;&gt;</pre>
<pre>We do not verify file permissions. Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>คารใช้ DNS domain ชื่อเดียวกัน</p>
<pre>Select default Grid Engine hostname resolving method
----------------------------------------------------</pre>
<pre>Are all hosts of your cluster in one DNS domain? If this is
the case the hostnames</pre>
<pre>   &gt;hostA&lt; and &gt;hostA.foo.com&lt;</pre>
<pre>would be treated as equal, because the DNS domain name &gt;foo.com&lt;
is ignored when comparing hostnames.</pre>
<pre>Are all hosts of your cluster in a single DNS domain (y/n) [y] &gt;&gt;</pre>
<pre>Ignoring domain name when comparing hostnames.</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>จะเปิดการใช้ Grid Engine JMX MBean server หรือไม่ ในที่นี้จะตอบ &#8220;n&#8221; คือไม่ใช้</p>
<pre>Grid Engine JMX MBean server
----------------------------</pre>
<pre>In order to use the SGE Inspect or the Service Domain Manager (SDM)
SGE adapter you need to configure a JMX server in qmaster. Qmaster
will then load a Java Virtual Machine through a shared library.
NOTE: Java 1.5 or later is required for the JMX MBean server.</pre>
<pre>Do you want to enable the JMX MBean server (y/n) [y] &gt;&gt; <strong>n</strong></pre>
<p>โปรแกรมจะเริ่มสร้างไฟล์ ไดเรคทอรี ต่างๆ ที่จะใช้</p>
<pre>Making directories
------------------</pre>
<pre>creating directory: /gridware/sge/MyCell/spool/qmaster
creating directory: /gridware/sge/MyCell/spool/qmaster/job_scripts
Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>เลือกวิธีการ spooling</p>
<pre>Setup spooling
--------------
Your SGE binaries are compiled to link the spooling libraries
during runtime (dynamically). So you can choose between Berkeley DB
spooling and Classic spooling method.
Please choose a spooling method (berkeleydb|classic) [berkeleydb] &gt;&gt;</pre>
<pre>The Berkeley DB spooling method provides two configurations!</pre>
<pre>Local spooling:
The Berkeley DB spools into a local directory on this host (qmaster host)
This setup is faster, but you can't setup a shadow master host</pre>
<pre>Berkeley DB Spooling Server:
If you want to setup a shadow master host, you need to use
Berkeley DB Spooling Server!
In this case you have to choose a host with a configured RPC service.
The qmaster host connects via RPC to the Berkeley DB. This setup is more
failsafe, but results in a clear potential security hole. RPC communication
(as used by Berkeley DB) can be easily compromised. Please only use this
alternative if your site is secure or if you are not concerned about
security. Check the installation guide for further advice on how to achieve
failsafety without compromising security.</pre>
<pre>Do you want to use a Berkeley DB Spooling Server? (y/n) [n] &gt;&gt;</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<pre>Berkeley Database spooling parameters
-------------------------------------</pre>
<pre>Please enter the database directory now, even if you want to spool locally,
it is necessary to enter this database directory.</pre>
<pre>Default: [<span style="color: #0000ff;">/gridware/sge/MyCell/spool/spooldb</span>] &gt;&gt;</pre>
<pre>creating directory: /gridware/sge/MyCell/spool/spooldb
Dumping bootstrapping information
Initializing spooling database</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>ขอบเขตของ group id เพิ่มเติม ที่ sge ใช้</p>
<pre>Grid Engine group id range
--------------------------</pre>
<pre>When jobs are started under the control of Grid Engine an additional group id
is set on platforms which do not support jobs. This is done to provide maximum
control for Grid Engine jobs.</pre>
<pre>This additional UNIX group id range must be unused group id's in your system.
Each job will be assigned a unique id during the time it is running.
Therefore you need to provide a range of id's which will be assigned
dynamically for jobs.</pre>
<pre>The range must be big enough to provide enough numbers for the maximum number
of Grid Engine jobs running at a single moment on a single host. E.g. a range
like &gt;20000-20100&lt; means, that Grid Engine will use the group ids from
20000-20100 and provides a range for 100 Grid Engine jobs at the same time
on a single host.</pre>
<pre>You can change at any time the group id range in your cluster configuration.</pre>
<pre>Please enter a range [<span style="color: #0000ff;">20000-20100</span>] &gt;&gt;</pre>
<pre>Using &gt;20000-20100&lt; as gid range. Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<pre>Grid Engine cluster configuration
---------------------------------</pre>
<pre>Please give the basic configuration parameters of your Grid Engine
installation:</pre>
<pre>   &lt;execd_spool_dir&gt;</pre>
<pre>The pathname of the spool directory of the execution hosts. User &gt;sgeadmin&lt;
must have the right to create this directory and to write into it.</pre>
<pre>Default: [<span style="color: #0000ff;">/gridware/sge/MyCell/spool</span>] &gt;&gt;</pre>
<p>อีเมล์สำหรับการแจ้งปัญหา</p>
<pre>Grid Engine cluster configuration (continued)
---------------------------------------------</pre>
<pre>&lt;administrator_mail&gt;</pre>
<pre>The email address of the administrator to whom problem reports are sent.</pre>
<pre>It is recommended to configure this parameter. You may use &gt;none&lt;
if you do not wish to receive administrator mail.</pre>
<pre>Please enter an email address in the form &gt;user@foo.com&lt;.</pre>
<pre>Default: [none] &gt;&gt;</pre>
<pre> </pre>
<pre>The following parameters for the cluster configuration were configured:</pre>
<pre>   execd_spool_dir        /gridware/sge/MyCell/spool
   administrator_mail     none</pre>
<pre>Do you want to change the configuration parameters (y/n) [n] &gt;&gt;</pre>
<p>การสร้างไฟล์คอนฟิก</p>
<pre>Creating local configuration
----------------------------
Creating &gt;act_qmaster&lt; file
Adding default complex attributes
Adding default parallel environments (PE)
Adding SGE default usersets
Adding &gt;sge_aliases&lt; path aliases file
Adding &gt;qtask&lt; qtcsh sample default request file
Adding &gt;sge_request&lt; default submit options file
Creating &gt;sgemaster&lt; script
Creating &gt;sgeexecd&lt; script
Creating settings files for &gt;.profile/.cshrc&lt;</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>สร้าง startup script เวลาบู๊ตเครื่อง</p>
<pre>qmaster startup script
----------------------</pre>
<pre>We can install the startup script that will
start qmaster at machine boot (y/n) [y] &gt;&gt;</pre>
<pre>cp /gridware/sge/MyCell/common/sgemaster /etc/init.d/sgemaster.MyCluster
/usr/lib/lsb/install_initd /etc/init.d/sgemaster.MyCluster</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>รันเซอร์วิส sge_qmaster</p>
<pre>Grid Engine qmaster startup
---------------------------</pre>
<pre>Starting qmaster daemon. Please wait ...
   starting sge_qmaster</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>ระบุชื่อ host สำหรับรันโปรแกรม sge_execd ในที่นี้จะใส่สองเครื่องคือ &#8220;cent55-node1&#8243; และ &#8220;cent55-node2&#8243;</p>
<pre>Adding Grid Engine hosts
------------------------</pre>
<pre>Please now add the list of hosts, where you will later install your execution
daemons. These hosts will be also added as valid submit hosts.</pre>
<pre>Please enter a blank separated list of your execution hosts. You may
press &lt;RETURN&gt; if the line is getting too long. Once you are finished
simply press &lt;RETURN&gt; without entering a name.</pre>
<pre>You also may prepare a file with the hostnames of the machines where you plan
to install Grid Engine. This may be convenient if you are installing Grid
Engine on many hosts.</pre>
<pre>Do you want to use a file which contains the list of hosts (y/n) [n] &gt;&gt;</pre>
<p>ใส่ชื่อเครื่อง cent55-node1</p>
<pre>Adding admin and submit hosts
-----------------------------</pre>
<pre>Please enter a blank seperated list of hosts.</pre>
<pre>Stop by entering &lt;RETURN&gt;. You may repeat this step until you are
entering an empty list. You will see messages from Grid Engine
when the hosts are added.</pre>
<pre>Host(s): <strong>cent55-node1
</strong>cent55-node1.spalinux.com added to administrative host list
cent55-node1.spalinux.com added to submit host list</pre>
<p>ใส่ชื่อเครื่อง cent55-node2</p>
<pre>Adding admin and submit hosts
-----------------------------</pre>
<pre>Please enter a blank seperated list of hosts.</pre>
<pre>Stop by entering &lt;RETURN&gt;. You may repeat this step until you are
entering an empty list. You will see messages from Grid Engine
when the hosts are added.</pre>
<pre>Host(s): <strong>cent55-node2
</strong>cent55-node2.spalinux.com added to administrative host list
cent55-node2.spalinux.com added to submit host list
Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>เมื่อใส่ชื่อเครื่องหมดแล้ว กด [enter] ผ่าน</p>
<pre>Adding admin and submit hosts
-----------------------------</pre>
<pre>Please enter a blank seperated list of hosts.</pre>
<pre>Stop by entering &lt;RETURN&gt;. You may repeat this step until you are
entering an empty list. You will see messages from Grid Engine
when the hosts are added.</pre>
<pre>Host(s):
Finished adding hosts. Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>ระบุชื่อเครื่องเพิ่มเติมสำหรับ shadow host ในที่นี้ไม่ได้ใช้</p>
<pre>If you want to use a shadow host, it is recommended to add this host
to the list of administrative hosts.</pre>
<pre>If you are not sure, it is also possible to add or remove hosts after the
installation with &lt;qconf -ah hostname&gt; for adding and &lt;qconf -dh hostname&gt;
for removing this host</pre>
<pre>Attention: This is not the shadow host installation
procedure.
You still have to install the shadow host separately</pre>
<pre>Do you want to add your shadow host(s) now? (y/n) [y] &gt;&gt;</pre>
<pre>Adding Grid Engine shadow hosts
-------------------------------</pre>
<pre>Please now add the list of hosts, where you will later install your shadow
daemon.</pre>
<pre>Please enter a blank separated list of your execution hosts. You may
press &lt;RETURN&gt; if the line is getting too long. Once you are finished
simply press &lt;RETURN&gt; without entering a name.</pre>
<pre>You also may prepare a file with the hostnames of the machines where you plan
to install Grid Engine. This may be convenient if you are installing Grid
Engine on many hosts.</pre>
<pre>Do you want to use a file which contains the list of hosts (y/n) [n] &gt;&gt;</pre>
<pre>Adding admin hosts
------------------</pre>
<pre>Please enter a blank seperated list of hosts.</pre>
<pre>Stop by entering &lt;RETURN&gt;. You may repeat this step until you are
entering an empty list. You will see messages from Grid Engine
when the hosts are added.</pre>
<pre>Host(s):
Finished adding hosts. Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<pre>Creating the default &lt;all.q&gt; queue and &lt;allhosts&gt; hostgroup
-----------------------------------------------------------</pre>
<pre>root@cent55-sge.spalinux.com added "@allhosts" to host group list
root@cent55-sge.spalinux.com added "all.q" to cluster queue list</pre>
<pre>Hit &lt;RETURN&gt; to continue &gt;&gt;</pre>
<p>การคอนฟิก Scheduler Tuning</p>
<pre>Scheduler Tuning
----------------</pre>
<pre>The details on the different options are described in the manual.</pre>
<pre>Configurations
--------------
1) Normal
          Fixed interval scheduling, report limited scheduling information,
          actual + assumed load</pre>
<pre>2) High
          Fixed interval scheduling, report limited scheduling information,
          actual load</pre>
<pre>3) Max
          Immediate Scheduling, report no scheduling information,
          actual load</pre>
<pre>Enter the number of your preferred configuration and hit &lt;RETURN&gt;!
Default configuration is [1] &gt;&gt;</pre>
<pre> </pre>
<pre>We're configuring the scheduler with &gt;Normal&lt; settings!
Do you agree? (y/n) [y] &gt;&gt;</pre>
<p>แนะวิธีการใช้ sge</p>
<pre>Using Grid Engine
-----------------</pre>
<pre>You should now enter the command:</pre>
<pre>   source /gridware/sge/MyCell/common/settings.csh</pre>
<pre>if you are a csh/tcsh user or</pre>
<pre>   # . /gridware/sge/MyCell/common/settings.sh</pre>
<pre>if you are a sh/ksh user.</pre>
<pre>This will set or expand the following environment variables:</pre>
<pre>   - $SGE_ROOT         (always necessary)
   - $SGE_CELL         (if you are using a cell other than &gt;default&lt;)
   - $SGE_CLUSTER_NAME (always necessary)
   - $SGE_QMASTER_PORT (if you haven't added the service &gt;sge_qmaster&lt;)
   - $SGE_EXECD_PORT   (if you haven't added the service &gt;sge_execd&lt;)
   - $PATH/$path       (to find the Grid Engine binaries)
   - $MANPATH          (to access the manual pages)</pre>
<pre>Hit &lt;RETURN&gt; to see where Grid Engine logs messages &gt;&gt;</pre>
<pre>Grid Engine messages
--------------------</pre>
<pre>Grid Engine messages can be found at:</pre>
<pre>   /tmp/qmaster_messages (during qmaster startup)
   /tmp/execd_messages   (during execution daemon startup)</pre>
<pre>After startup the daemons log their messages in their spool directories.</pre>
<pre>   Qmaster:     /gridware/sge/MyCell/spool/qmaster/messages
   Exec daemon: &lt;execd_spool_dir&gt;/&lt;hostname&gt;/messages</pre>
<pre>Grid Engine startup scripts
---------------------------</pre>
<pre>Grid Engine startup scripts can be found at:</pre>
<pre>   /gridware/sge/MyCell/common/sgemaster (qmaster)
   /gridware/sge/MyCell/common/sgeexecd (execd)</pre>
<pre>Do you want to see previous screen about using Grid Engine again (y/n) [n] &gt;&gt;</pre>
<pre> </pre>
<pre>Your Grid Engine qmaster installation is now completed
------------------------------------------------------</pre>
<pre>Please now login to all hosts where you want to run an execution daemon
and start the execution host installation procedure.</pre>
<pre>If you want to run an execution daemon on this host, please do not forget
to make the execution host installation in this host as well.</pre>
<pre>All execution hosts must be administrative hosts during the installation.
All hosts which you added to the list of administrative hosts during this
installation procedure can now be installed.</pre>
<pre>You may verify your administrative hosts with the command</pre>
<pre>   # qconf -sh</pre>
<pre>and you may add new administrative hosts with the command</pre>
<pre>   # qconf -ah &lt;hostname&gt;</pre>
<pre>Please hit &lt;RETURN&gt; &gt;&gt;</pre>
<p>ใช้คำสั่ง ps ตรวจสอบโปรเซส sge_qmaster</p>
<pre>[root@cent55-sge sge]# <strong>ps -ef | grep sge
</strong>sgeadmin  4667     1  1 13:55 ?        00:00:00 /gridware/sge/bin/lx24-amd64/sge_qmaster</pre>
<h4>การเปิด/ปิด เซอร์วิส sge_qmaster</h4>
<p>การปิดเซอร์วิส sge_qmaster</p>
<pre>[root@cent55-sge ~]# <strong>/etc/init.d/sgemaster.MyCluster stop
</strong>   shutting down Grid Engine qmaster</pre>
<p>การเปิดหรือรันเซอร์วิส qmaster</p>
<pre>[root@cent55-sge ~]# <strong>/etc/init.d/sgemaster.MyCluster start
</strong>   starting sge_qmaster</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2011/01/install_sun_grid_engine_on_centos_5-5">ติดตั้ง Sun Grid Engine บน CentOS 5.5</a></li>
<li><a href="http://spalinux.com/2011/01/configure_sun_grid_engine_execd_host">คอนฟิก Sun Grid Engine execution (execd) host</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/01/configure_sun_grid_engine_qmaster_host/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ติดตั้ง Sun Grid Engine บน CentOS 5.5</title>
		<link>http://spalinux.com/2011/01/install_sun_grid_engine_on_centos_5-5</link>
		<comments>http://spalinux.com/2011/01/install_sun_grid_engine_on_centos_5-5#comments</comments>
		<pubDate>Sat, 08 Jan 2011 18:03:59 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Cluster]]></category>
		<category><![CDATA[Grid]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Oracle Grid Engine]]></category>
		<category><![CDATA[Sun Grid Engine]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1226</guid>
		<description><![CDATA[Sun Grid Engine (SGE) หรือชื่อใหม่ Oracle Grid Engine เป็นโปรแกรมที่ใช้ควบคุม จัดการ การกระจายงาน (job) ไปรันตามเครื่องต่างๆ (distributed resource management) ในระบบ Sun Grid Engine ประกอบด้วยเครื่องที่ทำหน้าที่ควบคุมการส่ง job ที่เรียกว่า &#8220;sge qmaster&#8221; อย่างน้อยหนึ่งเครื่อง ส่วนเครื่องที่ทำหน้าที่รัน job เรียกว่า &#8220;sge execution host&#8221; หรือ &#8220;sge execd&#8221; มีหลายๆ เครื่อง ช่วยกันรันงานที่ได้รับมาจาก &#8220;qmaster&#8221; เวอร์ชั่น open source ที่สามารถดาวน์โหลดมาใช้งานได้อย่างถูกต้องล่าสุดคือ 6.2u5 ส่วนเวอร์ชั่นที่ใหม่กว่านี้ทาง Oracle ให้ทดลองใช้ได้ 90 วัน และขายเป็น commercial ใช้ google.com ค้นหา &#8220;Sun [...]]]></description>
			<content:encoded><![CDATA[<p>Sun Grid Engine (SGE) หรือชื่อใหม่ Oracle Grid Engine เป็นโปรแกรมที่ใช้ควบคุม จัดการ การกระจายงาน (job) ไปรันตามเครื่องต่างๆ (distributed resource management)</p>
<p>ในระบบ Sun Grid Engine ประกอบด้วยเครื่องที่ทำหน้าที่ควบคุมการส่ง job ที่เรียกว่า &#8220;sge qmaster&#8221; อย่างน้อยหนึ่งเครื่อง</p>
<p>ส่วนเครื่องที่ทำหน้าที่รัน job เรียกว่า &#8220;sge execution host&#8221; หรือ &#8220;sge execd&#8221; มีหลายๆ เครื่อง ช่วยกันรันงานที่ได้รับมาจาก &#8220;qmaster&#8221;</p>
<p><span id="more-1226"></span>เวอร์ชั่น open source ที่สามารถดาวน์โหลดมาใช้งานได้อย่างถูกต้องล่าสุดคือ 6.2u5 ส่วนเวอร์ชั่นที่ใหม่กว่านี้ทาง Oracle ให้ทดลองใช้ได้ 90 วัน และขายเป็น commercial</p>
<p>ใช้ google.com ค้นหา &#8220;Sun Grid Engine 6.2 Update 5 download&#8221; เพื่อดาวน์โหลดไฟล์รูปแบบ rpm สำหรับติดตั้งบน Linux x64 จาก Download Center</p>
<p>ข้อมูลไฟล์ที่เลือกดาวน์โหลดในหน้า Download Sun Grid Engine 6.2 Update 5 for Linux, English</p>
<ul>
<li>File Description: Sun Grid Engine 6.2 Update 5, Linux x64 (required), rpm format</li>
<li>File Name: sge62u5_linux24-x64_rpm.zip</li>
<li>Size: 28.16 MB</li>
</ul>
<h4>ระบบทดสอบ</h4>
<p>ในที่นี้ใช้ CentOS 5.5 (x64) โดยลง package group ตามนี้</p>
<ul>
<li>Base</li>
<li>Development Tools</li>
<li>Editors</li>
<li>GNOME Desktop Environment</li>
<li>X Window System</li>
</ul>
<h4>ติดตั้งไฟล์ rpm</h4>
<p>ตัวอย่างไฟล์ที่ดาวน์โหลด</p>
<pre>[root@cent55-sge sge]# <strong>ls -l
</strong>total 28844
-rw-r--r-- 1 root root 29533073 Jan  8 12:36 sge62u5_linux24-x64_rpm.zip</pre>
<p>แตกไฟล์ด้วยคำสั่ง unzip</p>
<pre>[root@cent55-sge sge]# <strong>unzip sge62u5_linux24-x64_rpm.zip
</strong>Archive:  sge62u5_linux24-x64_rpm.zip
  inflating: sge6_2u5/sun-sge-bin-linux24-x64-6.2-5.x86_64.rpm
  inflating: sge6_2u5/sun-sge-common-6.2-5.noarch.rpm</pre>
<p>ไฟล์ที่แตกได้จะมีสองไฟล์</p>
<pre>[root@cent55-sge sge]# <strong>cd sge6_2u5/</strong></pre>
<pre>[root@cent55-sge sge6_2u5]# <strong>ls -l</strong>
total 29048
-rw-r--r-- 1 root root 25583219 Dec 16  2009 sun-sge-bin-linux24-x64-6.2-5.x86_64.rpm
-rw-r--r-- 1 root root  4161238 Dec 16  2009 sun-sge-common-6.2-5.noarch.rpm</pre>
<p>ทุกเครื่องไม่ว่าจะเป็น qmaster host  หรือ execution host จะต้องติดตั้งไฟล์ rpm ทั้งสองนี้</p>
<p>ติดตั้งไฟล์ &#8220;sun-sge-common&#8221; ก่อน</p>
<pre>[root@cent55-sge sge6_2u5]# <strong>rpm -ivh sun-sge-common-6.2-5.noarch.rpm
</strong>Preparing...                ########################################### [100%]
   1:sun-sge-common         ########################################### [100%]</pre>
<p>ติดตั้งไฟล์ &#8220;sun-sge-bin-linux24-x64&#8243;</p>
<pre>[root@cent55-sge sge6_2u5]# <strong>rpm -ivh sun-sge-bin-linux24-x64-6.2-5.x86_64.rpm
</strong><span style="color: #ff0000;">error: Failed dependencies:</span>
        libXm.so.3()(64bit) is needed by sun-sge-bin-linux24-x64-6.2-5.x86_64
        libXp.so.6()(64bit) is needed by sun-sge-bin-linux24-x64-6.2-5.x86_64</pre>
<p>หากเจอ &#8220;error&#8221; แบบนี้ ต้องติดตั้ง library ที่ฟ้องขึ้นมาก่อน ในที่นี้ทั้งสอง library สามารถติดตั้งไฟล์ rpm จากแผ่นติดตั้ง CentOS 5.5 ได้</p>
<pre>[root@cent55-sge sge6_2u5]# <strong>mount /dev/cdrom /media
</strong>mount: block device /dev/cdrom is write-protected, mounting read-only</pre>
<pre>[root@cent55-sge sge6_2u5]# <strong>cd /media/CentOS/</strong></pre>
<p>สำหรับ &#8220;libXm.so.3&#8243; ต้องติดตั้งไฟล์ rpm ชื่อ &#8220;openmotif22-2.2.3-18.x86_64.rpm&#8221;</p>
<pre>[root@cent55-sge CentOS]# <strong>rpm -ivh openmotif22-2.2.3-18.x86_64.rpm
</strong>Preparing...                ########################################### [100%]
   1:openmotif22            ########################################### [100%]</pre>
<p>หมายเหตุ ในแผ่นดีวีดีติดตั้ง CentOS 5.5 (x64) จะมีไฟล์ rpm ติดตั้ง openmotif อยู่สองเวอร์ชั่น เนื่องจาก sge ใช้ libXm.so.3 ซึ่งมีอยู่ในไฟล์ &#8220;openmotif22-2.2.3&#8243; เลยต้องติดตั้งไฟล์เวอร์ชั่นนี้  ส่วน &#8220;openmotif-2.3.1&#8243; เวอร์ชั่นของ libXm จะเป็น &#8220;libXm.so.4&#8243; ไม่สามารถใช้กับ sge ได้</p>
<p>ใช้คำสั่ง rpm ดูไฟล์ที่จะติดตั้ง เพื่อเปรียบเทียบเวอร์ชั่นของ &#8220;libXm&#8221;</p>
<pre>[root@cent55-sge CentOS]# <strong>rpm -qilp openmotif22-2.2.3-18.x86_64.rpm | grep libXm
</strong>/usr/lib64/libXm.so.3
/usr/lib64/libXm.so.3.0.2</pre>
<pre>[root@cent55-sge CentOS]# <strong>rpm -qilp openmotif-2.3.1-2.el5_4.1.x86_64.rpm | grep libXm
</strong>/usr/lib64/libXm.so.4
/usr/lib64/libXm.so.4.0.1</pre>
<p>สำหรับ &#8220;libXp&#8221; ต้องติดตั้งไฟล์ rpm ชื่อ &#8220;libXp-1.0.0-8.1.el5.x86_64.rpm&#8221;</p>
<pre>[root@cent55-sge CentOS]# <strong>rpm -ivh libXp-1.0.0-8.1.el5.x86_64.rpm
</strong>Preparing...                ########################################### [100%]
   1:libXp                  ########################################### [100%]</pre>
<p>ทดลองติดตั้ง sge อีกครั้ง</p>
<pre>[root@cent55-sge CentOS]# <strong>cd -
</strong>/root/sge/sge6_2u5</pre>
<pre>[root@cent55-sge sge6_2u5]# <strong>rpm -ivh sun-sge-bin-linux24-x64-6.2-5.x86_64.rpm
</strong>Preparing...                ########################################### [100%]
   1:sun-sge-bin-linux24-x64########################################### [100%]</pre>
<h4>คอนฟิกเบื้องต้นสำหรับ sge</h4>
<p>สร้าง user และ group สำหรับรัน sge</p>
<pre>[root@cent55-sge sge6_2u5]# <strong>groupadd sgeadmin
</strong>[root@cent55-sge sge6_2u5]# <strong>useradd -g sgeadmin sgeadmin
</strong>[root@cent55-sge sge6_2u5]# <strong>id sgeadmin
</strong>uid=502(sgeadmin) gid=500(sgeadmin) groups=500(sgeadmin)</pre>
<p>ตั้งค่า PATH การติดตั้ง sge</p>
<pre>[root@cent55-sge sge6_2u5]# <strong>export SGE_ROOT=/gridware/sge
</strong>[root@cent55-sge sge6_2u5]# <strong>echo $SGE_ROOT</strong></pre>
<p>เปลี่ยน user group ของ PATH ที่จะติดตั้งเป็น sgeadmin</p>
<pre>[root@cent55-sge sge]# <strong>chown sgeadmin.sgeadmin /gridware/sge</strong></pre>
<p>ต้องแก้ไขไฟล์ /etc/hosts เพื่อ map ชื่อ hostname ของเครื่องที่ทำหน้าที่เป็น qmaster host จาก 127.0.0.1 เป็น IP Address ของพอร์ต LAN</p>
<pre>[root@cent55-sge sge6_2u5]# <strong>cat /etc/hosts
</strong># Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1        cent55-sge.spalinux.com cent55-sge localhost.localdomain localhost
::1              localhost6.localdomain6 localhost6</pre>
<p>สมมติว่าพอร์ต LAN ของเครื่องนี้ IP คือ 192.168.55.10 ต้องแก้ไขไฟล์นี้เป็นดังนี้</p>
<p>เพื่อความสะดวก แนะนำให้เพิ่มชื่อเครื่องและ IP address ที่จะทำหน้าที่เป็น execution host ด้วยเลย</p>
<pre>[root@cent55-sge sge6_2u5]# <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
192.168.55.10    cent55-sge.spalinux.com cent55-sge</pre>
<pre>192.168.55.11    cent55-node1.spalinux.com cent55-node1
192.168.55.12    cent55-node2.spalinux.com cent55-node2</pre>
<p> เพิ่มชื่อและหมายเลขพอร์ตสำหรับ sge ในไฟล์ /etc/services</p>
<pre>[root@cent55-sge sge6_2u5]# <strong>cat /etc/services
</strong>...
# Local services
<strong><span style="color: #0000ff;">sge_qmaster 10500/tcp
sge_execd   10501/tcp</span></strong></pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://www.oracle.com/us/products/tools/oracle-grid-engine-075549.html" target="_blank">Oracle Grid Engine</a></li>
<li><a href="http://en.wikipedia.org/wiki/Oracle_Grid_Engine" target="_blank">Oracle Grid Engine &#8211; Wikipedia</a></li>
<li><a href="http://www.globusconsortium.org/tutorial/ch3/page_4.php" target="_blank">Globus Toolkit Tutorial &#8211; Chapter 3: Deploying Sun Grid Engine (SGE)</a></li>
<li><a href="http://spalinux.com/2011/01/configure_sun_grid_engine_qmaster_host">คอนฟิก Sun Grid Engine qmaster host</a></li>
<li><a href="http://spalinux.com/2011/01/configure_sun_grid_engine_execd_host">คอนฟิก Sun Grid Engine execution (execd) host</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2011/01/install_sun_grid_engine_on_centos_5-5/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

