<?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; Squid</title>
	<atom:link href="http://spalinux.com/category/squid/feed" rel="self" type="application/rss+xml" />
	<link>http://spalinux.com</link>
	<description>เพื่อชีวิตที่ผ่อนคลายของคนใช้ลีนุกซ์</description>
	<lastBuildDate>Sat, 12 May 2012 10:38:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>คอนฟิก Squid Proxy Server ให้ตรวจสอบ user, password จาก LDAP</title>
		<link>http://spalinux.com/2012/03/configure-squid-proxy-server-to-authenticate-user-with-ldap</link>
		<comments>http://spalinux.com/2012/03/configure-squid-proxy-server-to-authenticate-user-with-ldap#comments</comments>
		<pubDate>Sun, 18 Mar 2012 07:12:32 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Firewall]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[Web Server]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1712</guid>
		<description><![CDATA[จากบทความ คอนฟิก Squid Proxy Server ให้ผู้ใช้ใส่ user, password ก่อนเข้าเว็บ เป็นการตรวจสอบ user จาก Local Password หรือไฟล์ /etc/passwd, /etc/shadow ผ่าน Linux PAM ที่อยู่บนเครื่อง proxy server เอง แต่ถ้าบริษัทหรือองค์กรของเรามีการเก็บ user, password อยู่บนเซิร์ฟเวอร์เครื่องอื่น เช่นเก็บรวมเป็นศูนย์กลางบน LDAP Server เราก็สามารถคอนฟิก Squid Proxy Server ให้ตรวจสอบ user, password จาก LDAP Server ได้ วิธีการคือ แก้ไขคอนฟิกในส่วนของ auth_param basic program เปลี่ยนไปใช้ไฟล์ basic_ldap_auth สมมติว่าค่าคอนฟิกต่างๆ ของ LDAP Server มีดังนี้ ออปชั่น &#8216;-v&#8217; [...]]]></description>
			<content:encoded><![CDATA[<p>จากบทความ <a href="http://spalinux.com/2012/03/configure-squid-proxy-server-user-authentication-with-local-password">คอนฟิก Squid Proxy Server ให้ผู้ใช้ใส่ user, password ก่อนเข้าเว็บ</a></p>
<p>เป็นการตรวจสอบ user จาก Local Password หรือไฟล์ /etc/passwd, /etc/shadow ผ่าน Linux PAM ที่อยู่บนเครื่อง proxy server เอง</p>
<p>แต่ถ้าบริษัทหรือองค์กรของเรามีการเก็บ user, password อยู่บนเซิร์ฟเวอร์เครื่องอื่น เช่นเก็บรวมเป็นศูนย์กลางบน LDAP Server เราก็สามารถคอนฟิก Squid Proxy Server ให้ตรวจสอบ user, password จาก LDAP Server ได้</p>
<p><span id="more-1712"></span></p>
<p>วิธีการคือ แก้ไขคอนฟิกในส่วนของ auth_param basic program เปลี่ยนไปใช้ไฟล์ basic_ldap_auth</p>
<p>สมมติว่าค่าคอนฟิกต่างๆ ของ LDAP Server มีดังนี้</p>
<ul>
<li>ออปชั่น &#8216;-v&#8217; ระบุเวอร์ชั่นของ LDAP ที่ใช้ = 3</li>
<li>ออปชั่น &#8216;-b&#8217; ระบุ Base DN สำหรับการค้นหา = &#8220;dc=example,dc=com&#8221;</li>
<li>ออปชั่น &#8216;-f&#8217; ระบุเงื่อนไขการค้นหา uid=% คือให้ค้นหาการ username (บน LDAP Server ก็ต้องเก็บโดยใช้ชื่อฟิลด์ uid ด้วย)</li>
<li>ออปชั่น &#8216;-h&#8217; ระบุ IP Address = 192.168.1.10</li>
</ul>
<p>แต่ถ้า LDAP Server ที่คุณใช้ ต้องมีการระบุชื่อ DN และ password ที่ใช้ bind ด้วย ก็ต้องระบุ 2 ออปชั่นนี้เพิ่มเติม</p>
<ul>
<li>ออปชั่น &#8216;-D&#8217; ระบุชื่อ DN สำหรับการ bind เข้า LDAP</li>
<li>ออปชั่น &#8216;-w&#8217; ระบุ password ที่ใช้ bind เข้า LDAP</li>
</ul>
<p>ตัวอย่างการแก้ไขคอนฟิก</p>
<pre>[root@fc16-64a ~]# <strong>cat /etc/squid/squid.conf</strong>
....
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
auth_param basic children 5
auth_param basic realm Proxy Authentication
auth_param basic credentialsttl 12 hours
<span style="color: #0000ff;">auth_param basic program /usr/lib64/squid/basic_ldap_auth -v 3 -b "dc=example,dc=com" -f uid=%s -h 192.168.1.10</span></pre>
<pre>acl <span style="color: #0000ff;">user_ldap_auth</span> proxy_auth REQUIRED
# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet <span style="color: #0000ff;">user_ldap_auth</span>
...</pre>
<p>ใช้คำสั่ง service หรือ systemctl เพื่อ start หรือ reload เซอร์วิส squid</p>
<pre>[root@fc16-64a ~]# <strong>systemctl reload squid.service</strong></pre>
<p>เสร็จแล้วลองทดสอบจาก Browser</p>
<p><strong>หมายเหตุ</strong> หลังจากทดสอบเรียบร้อยใช้งานได้แล้ว เพื่อความปลอดภัยของเซิร์ฟเวอร์ หากคุณเปลี่ยนจาก basic_pam_auth มาเป็น basic_ldap_auth แล้ว ให้ยกเลิก setuid root ของไฟล์ basic_pam_auth ด้วย ใช้คำสั่ง chmod ดังนี้</p>
<pre>[root@fc16-64a ~]# <strong>ls -l /usr/lib64/squid/basic_pam_auth</strong>
-rw<span style="color: #ff0000;">s</span>r-x---. 1 root squid 15416 Sep 20 15:36 /usr/lib64/squid/basic_pam_auth</pre>
<pre>[root@fc16-64a ~]# <strong>chmod u-s /usr/lib64/squid/basic_pam_auth</strong></pre>
<pre>[root@fc16-64a ~]# <strong>ls -l /usr/lib64/squid/basic_pam_auth</strong>
-rw<span style="color: #0000ff;">x</span>r-x---. 1 root squid 15416 Sep 20 15:36 /usr/lib64/squid/basic_pam_auth</pre>
<p>&nbsp;</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2012/03/configure-squid-proxy-server-user-authentication-with-local-password">คอนฟิก Squid Proxy Server ให้ผู้ใช้ใส่ user, password ก่อนเข้าเว็บ</a></li>
<li><a href="http://spalinux.com/2010/07/install_openldap_server_on_fedora_13">ติดตั้ง OpenLDAP Server บน Fedora 13</a></li>
<li><a href="http://www.squid-cache.org/Versions/v3/3.2/manuals/basic_ldap_auth.html" target="_blank">squid: basic_ldap_auth</a></li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2012/03/configure-squid-proxy-server-to-authenticate-user-with-ldap/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>คอนฟิก Squid Proxy Server ให้ผู้ใช้ใส่ user, password ก่อนเข้าเว็บ</title>
		<link>http://spalinux.com/2012/03/configure-squid-proxy-server-user-authentication-with-local-password</link>
		<comments>http://spalinux.com/2012/03/configure-squid-proxy-server-user-authentication-with-local-password#comments</comments>
		<pubDate>Fri, 16 Mar 2012 18:18:54 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Authentication]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[Web Server]]></category>
		<category><![CDATA[pam]]></category>
		<category><![CDATA[user]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=1701</guid>
		<description><![CDATA[บทความนี้อธิบายวิธีการคอนฟิก Squid Proxy Server เพื่อให้ผู้ใช้งานต้องใส่ user, password ก่อนถึงจะใช้งานอินเตอร์เน็ตได้ โดยจะตรวจสอบ user, password กับ Local Password หรือไฟล์ /etc/passwd, /etc/shadow ผ่าน Linux PAM ที่อยู่บนเครื่อง Proxy Server เอง ทดสอบบน Fedora 16 ติดตั้ง squid-3.2.0.12-1 ติดตั้งไฟล์ rpm จากแผ่นดีวีดีติดตั้ง [root@fc16-64a ~]# mount /dev/cdrom /mnt/cdrom mount: block device /dev/sr0 is write-protected, mounting read-only [root@fc16-64a ~]# cd /mnt/cdrom/Packages/ [root@fc16-64a Packages]# rpm -i squid-3.2.0.12-1.fc16.x86_64.rpm มีหลายวิธีที่คอนฟิกให้ถาม [...]]]></description>
			<content:encoded><![CDATA[<p>บทความนี้อธิบายวิธีการคอนฟิก Squid Proxy Server เพื่อให้ผู้ใช้งานต้องใส่ user, password ก่อนถึงจะใช้งานอินเตอร์เน็ตได้</p>
<p>โดยจะตรวจสอบ user, password กับ Local Password หรือไฟล์ /etc/passwd, /etc/shadow ผ่าน Linux PAM ที่อยู่บนเครื่อง Proxy Server เอง</p>
<p><span id="more-1701"></span></p>
<p>ทดสอบบน Fedora 16 ติดตั้ง squid-3.2.0.12-1</p>
<p>ติดตั้งไฟล์ rpm จากแผ่นดีวีดีติดตั้ง</p>
<pre>[root@fc16-64a ~]# <strong>mount /dev/cdrom /mnt/cdrom</strong>
mount: block device /dev/sr0 is write-protected, mounting read-only</pre>
<pre>[root@fc16-64a ~]# <strong>cd /mnt/cdrom/Packages/</strong>
[root@fc16-64a Packages]# <strong>rpm -i squid-3.2.0.12-1.fc16.x86_64.rpm</strong></pre>
<p>มีหลายวิธีที่คอนฟิกให้ถาม user, password ก่อนใช้ proxy ได้ วิธีหนึ่งคือเพิ่มคอนฟิกออปชั่น auth_param basic มี 3 ขั้นตอนดังนี้</p>
<ol>
<li>ตั้งค่าคอนฟิกของ auth_param basic มีอยู่หลายค่า บรรทัดสำคัญคือ program ในที่นี้จะเลือกเป็น basic_pam_auth เพื่อให้ตรวจสอบกับ Linux PAM</li>
<li>สร้าง acl เป็นชนิด proxy_auth ในตัวอย่างนี้ ตั้งชื่อ acl เป็น user_pam_auth</li>
<li>สุดท้ายนำ acl ที่สร้างขึ้นไปผูกเงื่อนไขใน http_access เช่นในที่นี้ ยังคงอนุญาตให้เครื่องที่อยู่ใน localnet ใช้ proxy ได้ แต่ต้องใส่ user, password ก่อน</li>
</ol>
<p>ตัวอย่างแก้ไขไฟล์ /etc/squid/squid.conf (แสดงเฉพาะส่วนที่แก้ไขจากดีฟอลต์คอนฟิกเท่านั้น)</p>
<pre>[root@fc16-64a ~]# <strong>cat /etc/squid/squid.conf</strong>
....
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
<span style="color: #0000ff;"><strong>auth_param basic children 5</strong></span>
<span style="color: #0000ff;"><strong>auth_param basic realm Proxy Authentication</strong></span>
<span style="color: #0000ff;"><strong>auth_param basic credentialsttl 12 hours</strong></span>
<span style="color: #0000ff;"><strong>auth_param basic program /usr/lib64/squid/basic_pam_auth</strong></span></pre>
<pre><span style="color: #0000ff;"><strong>acl user_pam_auth proxy_auth REQUIRED</strong></span></pre>
<pre># Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet <strong><span style="color: #0000ff;">user_pam_auth</span></strong>
...</pre>
<p>&nbsp;</p>
<p>ใช้คำสั่ง service หรือ systemctl เพื่อ start หรือ reload เซอร์วิส squid</p>
<pre>[root@fc16-64a ~]# <strong>systemctl reload squid.service</strong></pre>
<p>ใช้คำสั่ง useradd เพิ่ม user สำหรับทดสอบ</p>
<pre>[root@fc16-64a ~]# <strong>useradd -g users user1</strong>
[root@fc16-64a ~]# <strong>passwd user1</strong>
Changing password for user user1.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.</pre>
<pre></pre>
<h4>ทดสอบจาก Browser</h4>
<p>คอนฟิก Browser ของเครื่องผู้ใช้ ให้ชี้มาที่ proxy แล้วลองเข้าเว็บดู จะมีหน้าจอให้ใส่ user, password ลองใส่ user ที่เพิ่งสร้างขึ้น</p>
<p><a href="http://spalinux.com/wp-content/uploads/2012/03/p01-user-password.png"><img class="alignnone size-full wp-image-1702" title="p01-user-password" src="http://spalinux.com/wp-content/uploads/2012/03/p01-user-password.png" alt="" width="620" height="242" /></a></p>
<p>&nbsp;</p>
<p>แม้จะพยายามใส่ user, password อย่างไร ก็ไม่สำเร็จ</p>
<p><a href="http://spalinux.com/wp-content/uploads/2012/03/p02-cache-denied.png"><img class="alignnone size-full wp-image-1703" title="p02-cache-denied" src="http://spalinux.com/wp-content/uploads/2012/03/p02-cache-denied.png" alt="" width="786" height="299" /></a></p>
<p>&nbsp;</p>
<p>ที่เป็นเช่นนี้เนื่องจาก basic_pam_auth ไ่ม่สามารถอ่านไฟล์ /etc/shadow ได้ จำเป็นต้องแก้ไขไฟล์นี้ให้เป็น setuid root</p>
<p>ใช้คำสั่ง chmod เพื่อแก้ไขไฟล์ให้เป็น setuid root</p>
<pre>[root@fc16-64a ~]# <strong>ls -l /usr/lib64/squid/basic_pam_auth</strong>
-rwxr-xr-x. 1 root root 15416 Sep 20 15:36 /usr/lib64/squid/basic_pam_auth</pre>
<pre>[root@fc16-64a ~]# <strong>chmod u+s /usr/lib64/squid/basic_pam_auth</strong></pre>
<pre>[root@fc16-64a ~]# <strong>ls -l /usr/lib64/squid/basic_pam_auth</strong>
-rw<span style="color: #ff0000;">s</span>r-xr-x. 1 root root 15416 Sep 20 15:36 /usr/lib64/squid/basic_pam_auth</pre>
<p>&nbsp;</p>
<p>แต่การใช้ setuid root แบบนี้ ค่อนข้างอันตราย user ทั่วไป บนเครื่องเซิร์ฟเวอร์ สามารถรันโปรแกรมนี้แล้วตรวจสอบไฟล์ /etc/shadow ได้</p>
<p>วิธีที่จะพอป้องกันได้ คือให้เฉพาะ squid รันไฟล์นี้ได้เท่านั่้น ตัวอย่างเช่น</p>
<pre>[root@fc16-64a ~]# <strong>chmod 750 /usr/lib64/squid/basic_pam_auth</strong>
[root@fc16-64a ~]# <strong>chgrp squid /usr/lib64/squid/basic_pam_auth</strong>
[root@fc16-64a ~]# <strong>ls -l /usr/lib64/squid/basic_pam_auth</strong>
-rwxr-x<span style="color: #0000ff;">---</span>. 1 root <span style="color: #0000ff;">squid</span> 15416 Sep 20 15:36 /usr/lib64/squid/basic_pam_auth</pre>
<pre>[root@fc16-64a ~]# <strong>chmod u+s /usr/lib64/squid/basic_pam_auth</strong>
[root@fc16-64a ~]# <strong>ls -l /usr/lib64/squid/basic_pam_auth</strong>
-rw<span style="color: #ff0000;">s</span>r-x---. 1 root squid 15416 Sep 20 15:36 /usr/lib64/squid/basic_pam_auth</pre>
<p>รีโหลดเซอร์วิสหลังแก้ไข</p>
<pre>[root@fc16-64a ~]# <strong>systemctl reload squid.service</strong></pre>
<p>ลองใส่ user, password อีกครั้ง บน browser น่าจะใช้งานได้แล้ว</p>
<p>&nbsp;</p>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://www.squid-cache.org/Versions/v3/3.2/manuals/basic_pam_auth.html" target="_blank">squid: basic_pam_auth</a></li>
<li><a href="http://spalinux.com/2008/05/configure_squid_proxy_server" target="_blank">คอนฟิก Squid Proxy Server</a></li>
<li><a title="View Details: คอนฟิก Squid Proxy Server ให้ตรวจสอบ user, password จาก LDAP" href="http://spalinux.com/2012/03/configure-squid-proxy-server-to-authenticate-user-with-ldap" rel="bookmark">คอนฟิก Squid Proxy Server ให้ตรวจสอบ user, password จาก LDAP</a></li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2012/03/configure-squid-proxy-server-user-authentication-with-local-password/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ทดสอบค่าคอนฟิก Squid Cache Size</title>
		<link>http://spalinux.com/2009/07/test_squid_cache_size_configuration</link>
		<comments>http://spalinux.com/2009/07/test_squid_cache_size_configuration#comments</comments>
		<pubDate>Sat, 25 Jul 2009 10:04:52 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[squid cache]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=896</guid>
		<description><![CDATA[บทความนี้แสดงตัวอย่างการทดสอบโดยใช้โปรแกรม wget โหลดไฟล์ผ่าน squid เพื่อดูผลของการตั้งค่า cache size ต่างๆ ว่ามีผลต่อการโหลดไฟล์ การ HIT cache อย่างไร ในแต่ละการทดสอบ มีการแสดงไฟล์ log ของ squid ด้วย คือไฟล์ access_log (/var/log/squid/access_log) เก็บข้อมูลการใช้งาน proxy ว่ามาจากเครื่อง &#8220;client&#8221; ไหน เข้าเว็บไซต์ไหน รวมทั้งบอกผลการ HIT cache หรือไฟล์ที่โหลดนั้น มีอยู่ใน cache หรือยัง store_log (/var/log/squid/store.log) เก็บรายละเอียดการสร้าง &#8220;SWAPOUT&#8221; หรือลบ &#8220;RELEASE&#8221; ไฟล์ cache เครื่องที่ใช้ทดสอบ web client: 192.168.1.2 web server: 192.168.1.1 proxy: 192.168.1.254 คอนฟิกของ squid ในส่วน [...]]]></description>
			<content:encoded><![CDATA[<p>บทความนี้แสดงตัวอย่างการทดสอบโดยใช้โปรแกรม wget โหลดไฟล์ผ่าน squid เพื่อดูผลของการตั้งค่า cache size ต่างๆ ว่ามีผลต่อการโหลดไฟล์ การ HIT cache อย่างไร</p>
<p>ในแต่ละการทดสอบ มีการแสดงไฟล์ log ของ squid ด้วย คือไฟล์</p>
<ul>
<li>access_log (/var/log/squid/access_log) เก็บข้อมูลการใช้งาน proxy ว่ามาจากเครื่อง &#8220;client&#8221; ไหน เข้าเว็บไซต์ไหน รวมทั้งบอกผลการ HIT cache หรือไฟล์ที่โหลดนั้น มีอยู่ใน cache หรือยัง</li>
<li>store_log (/var/log/squid/store.log) เก็บรายละเอียดการสร้าง &#8220;SWAPOUT&#8221; หรือลบ &#8220;RELEASE&#8221; ไฟล์ cache</li>
</ul>
<p><span id="more-896"></span></p>
<p>เครื่องที่ใช้ทดสอบ</p>
<ul>
<li>web client: 192.168.1.2</li>
<li>web server: 192.168.1.1</li>
<li>proxy: 192.168.1.254</li>
</ul>
<p>คอนฟิกของ squid ในส่วน cache size</p>
<pre>maximum_object_size_in_memory 8 KB
maximum_object_size 4096 KB
cache_dir ufs /var/spool/squid 100 16 256</pre>
<h4>คอนฟิก proxy ของโปรแกรม wget</h4>
<p>เพื่อให้โปรแกรม wget โหลดไฟล์ผ่าน proxy ต้องสร้างไฟล์ .wgetrc ใน home directory ของผู้ใช้ที่รันคำสั่ง wget แล้วใส่คอนฟิกดังนี้</p>
<pre>[root@fc11-64min ~]# <strong>cat .wgetrc</strong>
http_proxy = http://192.168.1.254:3128/</pre>
<p>คำอธิบาย</p>
<ul>
<li>192.168.1.254 คือ ip ของ proxy</li>
<li>3128 คือพอร์ตของ proxy</li>
</ul>
<h4>ทดลองโหลดไฟล์ขนาด 7k</h4>
<p>เริ่มต้นทดลองโหดลไฟล์ขนาด 7k (กิโลไบต์) ซึ่งน้อยกว่าค่า &#8220;maximum_object_size_in_memory&#8221; ที่ตั้งไว้ 8 KB</p>
<p>โหลดไฟล์ขนาด 7k ครั้งที่ 1 ขึ้น &#8220;TCP_MISS&#8221; หมายถึง squid ไม่มีไฟล์นี้อยู่ใน cache เมื่อโหลดเสร็จ squid จะเก็บไฟล์ไว้ใน cache ด้วย &#8220;SWAPOUT&#8221;</p>
<pre>[root@fc11-64min ~]# <strong>wget http://192.168.1.1/files/tfile-7k.bin</strong></pre>
<pre>==&gt; access.log &lt;==
1248507942.812     17 192.168.1.2 <strong><span style="color: #0000ff;">TCP_MISS</span></strong>/200 7417 GET http://192.168.1.1/files/tfile-7k.bin - DIRECT/192.168.1.1 application/octet-stream</pre>
<pre>==&gt; store.log &lt;==
1248507942.810 <strong><span style="color: #0000ff;">SWAPOUT</span></strong> 00 00000001 3F277563988F72945705D5ED41526CA2  200 1248507942 1248505810        -1 application/octet-stream 7000/7000 GET http://192.168.1.1/files/tfile-7k.bin</pre>
<p>โหลดไฟล์ขนาด 7k ครั้งที่ 2 ขึ้น &#8220;TCP_MEM_HIT&#8221; หมายถึง squid มีไฟล์นี้ใน cache บน memory แล้ว สามารถดึงไฟล์จาก memory ได้เลย</p>
<pre>[root@fc11-64min ~]# <strong>wget http://192.168.1.1/files/tfile-7k.bin</strong></pre>
<pre>==&gt; access.log &lt;==
1248507971.779      0 192.168.1.1 <span style="color: #0000ff;"><strong>TCP_MEM_HIT</strong></span>/200 7424 GET http://192.168.1.1/files/tfile-7k.bin - NONE/- application/octet-stream</pre>
<h4>ทดลองโหลดไฟล์ขนาด 9k</h4>
<p>ทดลองโหลดไฟล์ 9k ซึ่งมีขนาดมากกว่า &#8220;maximum_object_size_in_memory&#8221; แต่ยังน้อยกว่าค่า &#8220;maximum_object_size&#8221; ซึ่งตั้งไว้ 4096 KB (4 Mbytes)</p>
<p>โหลดไฟล์ขนาด 9k ครั้งที่ 1 ขึ้น &#8220;TCP_MISS&#8221; หมายถึง squid ไม่มีไฟล์นี้อยู่ใน cache เมื่อโหลดเสร็จ squid จะเก็บไฟล์ไว้ใน cache ด้วย &#8220;SWAPOUT&#8221;</p>
<pre>[root@fc11-64min ~]# <strong>wget http://192.168.1.1/files/tfile-9k.bin</strong></pre>
<pre>==&gt; access.log &lt;==
1248508182.804      3 192.168.1.2 <strong><span style="color: #0000ff;">TCP_MISS</span></strong>/200 12418 GET http://192.168.1.1/files/tfile-9k.bin - DIRECT/192.168.1.1 application/octet-stream</pre>
<pre>==&gt; store.log &lt;==
1248508182.804 <strong><span style="color: #0000ff;">SWAPOUT</span></strong> 00 00000002 CEFDC390A1EE023973CBADC1A78D73C7  200 1248508182 1248508174        -1 application/octet-stream 12000/12000 GET http://192.168.1.1/files/tfile-9k.bin</pre>
<p>โหลดไฟล์ขนาด 9k ครั้งที่ 2 ขึ้น &#8220;TCP_HIT&#8221; หมายถึง squid มีไฟล์นี้ใน cache แต่อยู่บน disk</p>
<pre>[root@fc11-64min ~]# <strong>wget http://192.168.1.1/files/tfile-9k.bin</strong></pre>
<pre>==&gt; access.log &lt;==
1248508281.238      0 192.168.1.2 <strong><span style="color: #0000ff;">TCP_HIT</span></strong>/200 12424 GET http://192.168.1.1/files/tfile-9k.bin - NONE/- application/octet-stream</pre>
<h4>ทดลองโหลดไฟล์ขนาด 5M</h4>
<p>ทดลองโหลดไฟล์ 5M ซึ่งมีขนาดน้อยกว่า &#8220;maximum_object_size&#8221; ซึ่งตั้งไว้ 4096 KB (4 Mbytes)</p>
<p>โหลดไฟล์ขนาด 5k ครั้งที่ 1 ขึ้น &#8220;TCP_MISS&#8221; หมายถึง squid ไม่มีไฟล์นี้อยู่ใน cache เมื่อโหลดเสร็จ เนื่องจากมีขนาดไฟล์ใหญ่กว่าขนาด &#8220;maximum_object_size&#8221; โปรแกรม squid จะไม่เก็บไฟล์ไว้ใน cache  ขึ้น &#8220;RELEASE&#8221;</p>
<pre>[root@fc11-64min ~]# <strong>wget http://192.168.1.1/files/tfile-5M.bin</strong></pre>
<pre>1248509577.012    197 192.168.1.2 <span style="color: #0000ff;">TCP_MISS</span>/200 5000422 GET http://192.168.1.1/files/tfile-5M.bin - DIRECT/192.168.1.1 application/octet-stream</pre>
<pre>==&gt; store.log &lt;==
1248509577.012 <strong><span style="color: #0000ff;">RELEASE</span></strong> -1 FFFFFFFF 81F5E27F6F4A2D2CFB41BF48899FBFE5  200 1248509576 1248505985        -1 application/octet-stream 5000000/5000000 GET http://192.168.1.1/files/tfile-5M.bin</pre>
<p>ไม่ว่าจะโหลดไฟล์ที่มีขนาดใหญ่กว่า &#8220;maximum_object_size&#8221; โปรแกรม squid จะไม่เก็บ cache ไว้เลย</p>
<h4>ขนาดรวมไฟล์ cache ทั้งหมด</h4>
<p>เมื่อเก็บไฟล์ cache มากจนกระทั่งมีขนาดไฟล์รวมทั้งหมด มากกว่าที่คอนฟิกไว้ในส่วน &#8220;cache_dir&#8221; ในที่นี้คอนฟิกไว้ 100 (100Mbytes)</p>
<p>ตรวจสอบขนาดของ cache_dir ด้วยคำสั่ง du</p>
<pre>[root@fc11-64min ~]# <strong>cd /var/spool/squid</strong>
[root@fc11-64min squid]# <strong>du -sh</strong>
105M    .</pre>
<p>เมื่อทดลองโหลดไฟล์เพิ่มเติม squid จะทำการเก็บไฟล์ใหม่ที่โหลดเสร็จ &#8220;SWAPOUT&#8221; แต่เนื่องจากขนาดมากกว่า &#8220;cache_dir&#8221; ดังนั้นจำเป็นต้องลบบางไฟล์ใน cache ออกไป ด้วย &#8220;RELEASE&#8221;</p>
<p>เช่นทดลองไฟล์ 4M เพิ่มเติม</p>
<pre>[root@fc11-64min ~]# <strong>wget http://192.168.1.1/files/tfile-4M.bin</strong></pre>
<pre>==&gt; access.log &lt;==
1248509870.685     91 192.168.1.2 <strong><span style="color: #0000ff;">TCP_MISS</span></strong>/200 4000422 GET http://192.168.1.1/files/tfile-4M.bin - DIRECT/192.168.1.1 application/octet-stream</pre>
<pre>==&gt; store.log &lt;==
1248509870.683 <strong><span style="color: #0000ff;">SWAPOUT</span></strong> 00 0000000E 93E941E788327BE1F0E0F028A1114B49  200 1248509870 1248505053        -1 application/octet-stream 4000000/4000000 GET http://192.168.1.1/files/tfile-4M.bin
1248509870.758 <strong><span style="color: #0000ff;">RELEASE</span></strong> 00 00000007 E43BBBD8932CA6266141E6BFFB46EFCC   ?         ?         ?         ? ?/? ?/? ? ?</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2009/07/edit_squid_cache_size_configuration">แก้ไขคอนฟิก Squid Cache Size</a></li>
<li><a href="http://wiki.squid-cache.org/SquidFaq/SquidLogs" target="_blank">SquidFaq/SquidLogs</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/07/test_squid_cache_size_configuration/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>แก้ไขคอนฟิก Squid Cache Size</title>
		<link>http://spalinux.com/2009/07/edit_squid_cache_size_configuration</link>
		<comments>http://spalinux.com/2009/07/edit_squid_cache_size_configuration#comments</comments>
		<pubDate>Sat, 25 Jul 2009 09:11:56 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[Proxy]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[squid cache]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=889</guid>
		<description><![CDATA[ปกติการติดตั้ง squid โดยใช้คำสั่ง rpm สามารถที่จะใช้งานได้เลย แต่เพื่อเพิ่มประสิทธิภาพการใช้งานของ squid เช่น เพิ่มขนาดของไฟล์ cache เพื่อให้สามารถเก็บไฟล์ได้มากขึ้น ซึ่งมีผลให้โอกาสที่มีการโหลดไฟล์เดียวกันซ้ำ (cache hit) มีสูงมากขึ้น ทำให้ประหยัด bandwidth ที่ต้องใช้ในการโหลดไฟล์จากอินเตอร์เน็ต บทความนี้กล่าวถึงการแก้ไขคอนฟิกของ squid ในส่วนเพื่อเพิ่มขนาดของ cache โดยจะทดสอบบน Fedora 11  คอนฟิกไฟล์ของ squid จะอยู่ที่ /etc/squid/squid.conf ขนาดไฟล์ใหญ่สุดที่จะเก็บ cache ไว้ใน memory เนื่องจากการเขียนอ่านไฟล์ลงบน memory มีความเร็วมากกว่าบน disk มาก ถ้าเรามีขนาดของ memory มาก แนะนำให้เพื่มขนาดไฟล์ใหญ่สุดที่จะเก็บ cache ไว้ใน memory เพื่อว่าถ้าการโหลดไฟล์ที่ HIT จะได้ดึงจาก memory ได้เลย โดยดีฟอลต์ ค่าคอนฟิกจะตั้งไว้แค่ 8 KB (กิโลไบต์) [...]]]></description>
			<content:encoded><![CDATA[<p>ปกติการติดตั้ง squid โดยใช้คำสั่ง rpm สามารถที่จะใช้งานได้เลย แต่เพื่อเพิ่มประสิทธิภาพการใช้งานของ squid เช่น เพิ่มขนาดของไฟล์ cache เพื่อให้สามารถเก็บไฟล์ได้มากขึ้น ซึ่งมีผลให้โอกาสที่มีการโหลดไฟล์เดียวกันซ้ำ (cache hit) มีสูงมากขึ้น ทำให้ประหยัด bandwidth ที่ต้องใช้ในการโหลดไฟล์จากอินเตอร์เน็ต</p>
<p>บทความนี้กล่าวถึงการแก้ไขคอนฟิกของ squid ในส่วนเพื่อเพิ่มขนาดของ cache โดยจะทดสอบบน Fedora 11  คอนฟิกไฟล์ของ squid จะอยู่ที่ /etc/squid/squid.conf</p>
<p><span id="more-889"></span></p>
<h4>ขนาดไฟล์ใหญ่สุดที่จะเก็บ cache ไว้ใน memory</h4>
<p>เนื่องจากการเขียนอ่านไฟล์ลงบน memory มีความเร็วมากกว่าบน disk มาก ถ้าเรามีขนาดของ memory มาก แนะนำให้เพื่มขนาดไฟล์ใหญ่สุดที่จะเก็บ cache ไว้ใน memory เพื่อว่าถ้าการโหลดไฟล์ที่ HIT จะได้ดึงจาก memory ได้เลย</p>
<p>โดยดีฟอลต์ ค่าคอนฟิกจะตั้งไว้แค่ 8 KB (กิโลไบต์) เท่านั้น หากต้องการเพิ่มค่า เช่นเพิ่มเป็น 8 MB สามารถแก้ไขคอนฟิกได้ตามตัวอย่าง</p>
<pre>#  TAG: maximum_object_size_in_memory   (bytes)
#       Objects greater than this size will not be attempted to kept in
#       the memory cache. This should be set high enough to keep objects
#       accessed frequently in memory to improve performance whilst low
#       enough to keep larger objects from hoarding cache_mem.
#
#Default:
# maximum_object_size_in_memory 8 KB
<strong><span style="color: #0000ff;">maximum_object_size_in_memory 8 MB</span></strong></pre>
<h4>ขนาดไฟล์ใหญ่สุดที่จะเก็บ cache ไว้บน disk</h4>
<p>ประโยชน์ของการใช้ squid คือเก็บไฟล์ที่มีการโหลดมาแล้ว ลงบน disk เพื่อให้ครั้งต่อไปถ้ามีผู้โหลดไฟล์นี้ซ้ำ จะได้ดึงจาก disk ได้เลย ไม่จำเป็นต้องไปดาวน์โหลดจากอินเตอร์เน็ตอีกครั้ง</p>
<p>แต่ squid มีคอนฟิกที่ระบุขนาดของแต่ละไฟล์ใหญ่ที่สุด ที่จะเก็บ cache ลงบน disk โดยค่าดีฟอลต์ตั้งไว้แค่ 4096 KB หรือ 4 MB เท่านั้น หมายความว่า ถ้ามีการโหลดไฟล์ขนาดใหญ่กว่านี้  squid จะไม่ทำการเก็บไฟล์ ทำให้ผู้ใช้ที่โหลดไฟล์เดียวกัน ต้องไปดาวน์โหลดใหม่จากอินเตอร์เน็ตทุกครั้ง</p>
<p>ถ้าคุณมีขนาดของ disk ค่อนข้างใหญ่ แนะนำให้เพิ่มค่าคอนฟิกนี้ เช่น ถ้าต้องการเก็บไฟล์ที่มีขนาดใหญ่ถึง 16 MB สามารถแก้ไขคอนฟิกได้ดังนี้</p>
<pre>#  TAG: maximum_object_size     (bytes)
#       Objects larger than this size will NOT be saved on disk.  The
#       value is specified in kilobytes, and the default is 4MB.  If
#       you wish to get a high BYTES hit ratio, you should probably
#       increase this (one 32 MB object hit counts for 3200 10KB
#       hits).  If you wish to increase speed more than your want to
#       save bandwidth you should leave this low.
#
#       NOTE: if using the LFUDA replacement policy you should increase
#       this value to maximize the byte hit rate improvement of LFUDA!
#       See replacement_policy below for a discussion of this policy.
#
#Default:
# maximum_object_size 4096 KB
<strong><span style="color: #0000ff;">maximum_object_size 16 MB</span></strong></pre>
<h4>ขนาดไฟล์ cache รวมทั้งหมดที่เก็บไว้บน disk</h4>
<p>เมื่อมีการใช้งานไปเรื่อยๆ ขนาดของ cache ที่เก็บไว้บน disk ก็มีขนาดเพิ่มขึ้นเรื่อยๆ ไปถึงจุดหนึ่ง เป็นค่าผลรวมขนาดไฟล์ทั้งหมดสูงสุดที่ squid จะอนุญาตให้มีการเก็บไฟล์ไว้ ถ้าไฟล์ใหม่เพิ่มมาอีก ที่เกินจากกนี้ จำเป็นต้องลบบางไฟล์ใน cache ออกไป เพื่อเก็บไฟล์ใหม่นี้ได้</p>
<p>โดยดีฟอลต์ squid อนุญาตให้เก็บไฟล์ cache ได้รวมทั้งหมด ไม่เกิน 100 MB เท่านั้น ถ้ามีขนาด disk ขนาดใหญ่ แนะนำให้เพิ่มค่าคอนฟิกนี้ เช่น เพิ่มให้สามารถเก็บไฟล์ cache ได้ทั้งหมด 200 GB สามารถแก้ไขคอนฟิกได้ดังนี้</p>
<pre>#  TAG: cache_dir
#       Usage:
#
#       cache_dir ufs Directory-Name Mbytes L1 L2 [options]
#</pre>
<pre>#Default:
# cache_dir ufs /var/spool/squid 100 16 256
<strong><span style="color: #0000ff;">cache_dir ufs /var/spool/squid 200000 16 256</span></strong></pre>
<p>หมายเหตุ ขนาดตัวเลขที่ระบุ มีหน่วยเป็น MBytes</p>
<h4>รีโหลดเซอร์วิส squid หลังแก้ไขคอนฟิก</h4>
<p>หลังแก้ไขไฟล์ /etc/squid/squid.conf ทุกครั้ง ต้องรันคำสั่ง service เพื่อรีโหลดคอนฟิกใหม่ให้มีผล</p>
<pre>[root@fc11-64min ~]# <strong>service squid reload</strong></pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2008/05/configure_squid_proxy_server">คอนฟิก Squid Proxy Server</a></li>
<li><a href="http://spalinux.com/2009/07/test_squid_cache_size_configuration">ทดสอบค่าคอนฟิก Squid Cache Size</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2009/07/edit_squid_cache_size_configuration/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

