วันพฤหัสบดีที่ 6 สิงหาคม พ.ศ. 2552

Squid Dealy Pools

ไม่ว่างได้แวะเวียนเข้ามาเสียนาน เพราะงานและเรียนที่ยุ่งเหมือนใยแมงมุม เลย วันนี้มีปัญหากับ Delay Pools ที่เข้าใจยากเหลือเกิน งมความรู้ใน CyberSpace อยู่นาน เจอบทความนี้ เลยบันทึกไว้ก่อน..กันลืม ขอบคุณ คุณ shadows00 จาก Board Thaiadmin กระทู้ http://www.linuxthai.org/forum/index.php?topic=472.0 เป็นอย่างสูง


acl all src 0.0.0.0/0.0.0.0 #กำหนดทุก ip และทุก network ก็คือทุกเครื่องนั่นเอง
acl bitclient src 192.168.1.101 # กำหนดให้ใช้เครื่องไหนในร้านเพื่อให้โหลดบิตได้ (เครื่องเดียว)
acl GAMESERVER dstdom_regex patch asiasoft asianet audition cabal fsonline ghostonline ini3\. maplestory playarcade playpark ragnarok tsonline yulgang hipstreet lunaonline pangya ran.in.th raycity sa.in.th sf.gg suddenattack talesrunner winner\. #กำหนด regular expression สำหรับ domain เกมส์ออนไลน์ ซึ่ง acl นี้จะกำหนด กลุ่มคำที่ระบุถึงเกมส์ออนไลน์ทุกเกมส์
acl UNLIMITTIME time SMTWHFA 00:00-07:00 # กำหนดช่วงเวลาเพื่อกำหนดใน delay pools
acl magic_words1 urlpath_regex \.3gp$ \.aac$ \.ac3$ \.act$ \.aiff?$ \.amr$ \.asf$ \.au$ \.avi$ \.b5t$ \.bin$ \.bwt$ \.cab$ \.ccd$ \.cdi$ \.cue$ \.dat$ \.dct$ \.divx?$ \.dss$ \.exe$ \.flac$ \.fli$ \.flv$ \.gho$ \.gsm$ \.gz$ \.ifo$ \.img$ \.iso$ \.m4a$ \.mp[2-4]$ \.mov$ \.mpe$ \.mpga?$ \.mpeg$ \.mds$ \.nrg$ \.ogg$ \.pdi$ \.qt$ \.ram?$ \.ra[rw]$ \.rcd$ \.rec$ \.rmvb$ \.rmj?$ \.rpm$ \.sea$ \.shn$ \.sri$ \.swf$ \.tar$ \.tgz$ \.vo[bx]$ \.vqf$ \.wav$ \.wm[av]$ \.zip$ # กำหนดประเภทไฟล์ที่จะบีบความเร็ว ใน delay pools
acl bitword urlpath_regex passkey \.torrent # กำหนดคำ ที่จะใช้ตรวจสอบการดาวน์โหลด bitterrent
acl QUERY url_regex -i cgi-bin [^pxz]\? photos[1-9] \.D$ \.ini$ \.dll$ \.inf$ \.Xt \.xtp Loader\.exe 1st$ update.cfg\? urlinfo\.ini$ updatelist patch_lv1 notice_popup ProjectG.exe.zip$ start/ucg UCG\.DAT$ UCGA?\.exe$ version\.cfg$ # กำหนดกลุ่มคำ ที่อยู่ใน url เพื่อไม่ให้ใช้ข้อมูลใน cache และไม่ให้เก็บ cache ไฟล์ซึ่งมี url เป็นคำเหล่านี้
http_access allow bitclient bitword # อนุญาติให้เครื่อง ip ที่กำหนดใช้บิตได้
http_access deny bitword # นอกนั้นใช้บิตไม่ได้
http_access allow all # นอกนั้นให้ใช้งาน squid ได้หมด

# DELAY_POOLS
# ---------------------------------------------------------
delay_pools 1 #กำหนดให้มี delay pools จำนวน 1 pool
delay_class 1 2 # กำหนดให้ pools ที่ 1 ใช้งานแบบ class 2 คือ จำกัดความเร็วแบบรวม และ แบบแยกรายเครื่อง(ip)
delay_parameters 1 750000/750000 200000/200000 # จำกัดความเร็วของ pool ที่ 1 ไว้ที่ 750000 kbyte/sec หรือ 750Kbyte/sec และจำกัดความเร็วรายเครื่องไว้ที่ 200 Kbyte/sec
delay_access 1 allow magic_words1 !GAMESERVER !UNLIMITTIME #เงื่อนไขที่ไฟล์ใดๆ จะตกลงสู่ delay pools นี้เป็นดังนี้
เป็นไฟล์ที่มีนามสกุลตาม acl magig_word1 และ ไม่ใช่มีชื่อ domain ตามคำใน acl GAMESERVER และ ไม่ใช่อยู่ในช่วงเวลาตาม acl UNLIMITIME เราใช้ AND นะครับ นั่นคือ 3 พจน์ต้องเป็นจริง ไฟล์ที่ถูกตรวจสอบนั้นจึงจะตกเข้าไปใน delay pools นี้ เพื่อบีบความเร็ว
ดังนั้น ถ้าเป็น GAMESERVER จะไม่ตกเข้าไป รวมทั้ง ถ้าในเวลาที่ไม่จำกัดความเร็ว ก็ไม่ตกเข้าไป
delay_access 1 deny all # ส่วนไฟล์อื่น ๆ นอกจากเงื่อนไขข้างบนนั้น ไม่ให้ตกเข้าไปใน delay pools ที่ 1 นี้
# DNS OPTIONS
#----------------------------------------------------------
ipcache_size 3072 # สร้างที่เก็บค่า domain name <--> IP ไว้ 3072 ปกติ 1024

# MEMORY CACHE OPTIONS
# ---------------------------------------------------------
cache_mem 1024 MB # ใช้หน่วยความจำมาทำ cache เพื่อให้ทำงานได้เร็ว ประมาณ ครึ่งหนึ่งของ RAM ที่มี
maximum_object_size_in_memory 8 MB # ขนาดของไฟล์ที่จะ cache ในหน่วยความจำ
memory_replacement_policy heap LFUDA # กำหนดนโยบายของการแทนที่
ipcache_high 98 # เมื่อเก็บ ipcache เต็มถึง 98% จะต้องล้างออก
ipcache_low 93 # โดยล้างออกให้เหลือ 93% การล้าง cache นั้นทำงานแบบอัตโนมัติแบบ Quantum คือเอาออกเป็นก้อนครั้งเดียว
# DISK CACHE OPTIONS
# --------------------------------------------------------
cache_dir aufs /home/spool/squid 4096 16 256 # กำหนด dir ที่เก็บ cache และขนาดที่ใช้ 4GB
maximum_object_size 32 MB # ไฟล์ที่ใหญ่ที่สุดไม่เกิน 32MB
cache_replacement_policy heap LFUDA
store_dir_select_algorithm round-robin
cache_swap_high 98 # เมื่อเก็บ cache ถึง 98% ของจำนวนสูงสุดที่ระบุไว้ (4GB) ให้เริ่มล้าง cache อัตโนมัติ
cache_swap_low 93 # โดยล้าง cache ให้เหลือเพียง 93% ซึ่งการล้างออกจะล้างออกแบบ Quantum เป็นก้อนเดียวครั้งเดียวแล้วจึงเริ่มสะสมใหม่ ดังนั้นการล้างจะล้างcache ที่เก่าแล้วออก 5% โดยอัตโนมัติ หรือประมาณ 5x4000/100 = 200 MB จังหวะนี้ CPU จึงขึ้นไปถึง 100%ได้ กรณีเครื่อง CC ที่ช้าๆ
# HTTP OPTIONS
#-----------------------------------------------------------
ie_refresh on
vary_ignore_expire on

# LOGFILE OPTIONS
# ----------------------------------------------------------
cache_access_log /var/log/squid/access.log
cache_log /var/log/squid/cache.log
cache_store_log none
logfile_rotate 90
pid_filename /var/run/squid.pid
buffered_logs off
strip_query_terms off

# MISCELLANEOUS
# ----------------------------------------------------------
pipeline_prefetch on

# OPTIONS FOR FTP GATEWAYING
#-----------------------------------------------------------
ftp_passive on
ftp_sanitycheck on

# OPTIONS FOR TUNING THE CACHE
# -----------------------------------------------------------
cache deny QUERY # ไม่ให้เก็บ cache
quick_abort_min 0 KB # ไม่เก็บไฟล์ที่เสียหายหรือไม่ครบ มีการยกเลิกก่อนจะโหลดครบ
quick_abort_max 0 KB # ไม่เก็บไฟล์ที่เสียหาย หรือไม่ครบ มีการยกเลิกก่อนจะโหลดครบ
# ต่อไปนี้คือการทำ refresh pattern เพื่อกำหนดเวลาที่จะ refresh หรือ ให้ตรวจสอบหรือดึงมาใหม่ ของประเภทไฟล์ที่ไม่ได้กำหนดวันหมดอายุมา
# ตรงนี้สำคัญมาก ที่จะทำให้เกมส์ เก็บแพทหรือไม่ อยู่ตรงนี้ ให้ไปอ่านเรื่อง refresh_pattern ที่มีผู้บรรยายไว้แล้ว ผมจะไม่กล่าวซ้ำอีกrefresh_pattern -i \.(htmlhtm/)$ 60 20% 720
refresh_pattern -i \.(asp\?aspx\?php\?) 0 20% 720
refresh_pattern -i \.(aspaspxphp)$ 0 20% 720
refresh_pattern -i \.(jpggifjpegpngcssjsbmptiftiffxbmpngswf)$ 0 100% 14400
refresh_pattern -i \.(exezipgzarjlhalzhrartgztarZ)$ 4320 80% 43200 override-lastmod reload-into-ims ignore-reload
refresh_pattern ^http://patch.sf.* 4320 100% 43200 ignore-reload override-lastmod reload-into-ims
refresh_pattern ^http://update.cabal.* 4320 100% 43200 ignore-reload override-lastmod reload-into-ims
refresh_pattern ^http://download.cabal.* 4320 100% 43200 ignore-reload override-lastmod reload-into-ims
refresh_pattern ^ftp: 0 20% 4320
refresh_pattern . 0 20% 4320

# OPTIONS INFLUENCING REQUEST FORWARDING
#------------------------------------------------------------
prefer_direct on

# TIMEOUTS
# -----------------------------------------------------------
half_closed_clients off

# ADMINISTRATIVE PARAMETERS
# -----------------------------------------------------------
cache_mgr wecareyou2002@hotmail.com
visible_hostname www.wecareyou.com


ศึกษาดูนะครับพอเป็นแนวๆได้ครับ

ไม่มีความคิดเห็น:

ที่เป็นตัวฉัน

รูปภาพของฉัน
เรียนภาษาอังกฤษมา แต่ชีวิตผกผันให้ต้องมาเป็น admin ซะนี่ เล่นเอาซะมึน และงงตามลำดับ คิดอย่างเดียวว่า เป็นอะไรเป็นได้ถ้าใจอยากเป็น อุปสรรคคือแบบฝึกหัด ท้อแต่ไม่เคยถอย คิดไว้เสมอ ความพยายามอยู่ที่ไหน ความสำเร็จอยู่ที่นั่น ถ้าพยายามก่อน ก็ชนะแล้ว 50% อีก 50 % ใช้ความสามารถเอาเอง