วันอังคารที่ 13 กันยายน พ.ศ. 2554

การทำ Delay Pools ใน Squid


Delay pools ทำหน้าที่ใช้เพื่อควบคุมปริมาณการใช้Trafficในเครือข่ายหรือควบคุมการวิ่งของข้อมูล
 เพื่อไม่ให้ Bandwidth เต็มหรือพูดอีกอย่างหนึ่งได้ว่าใช้ squid เป็นการทำ Traffic Shaper
Proxy
ทำหน้าที่เป็นที่พักข้อมูลที่ถูกดึงมาจาก Server ภายนอก ไม่ว่าจะเป็นภาพ , เสียง , เอกสาร , html เป็นต้น 
การใช้ Proxy server โดยทั่วไปผู้บริหารระบบจะทำการกำหนดให้เครื่อง client ในเครึอข่ายค้นหาไฟล์หรือข้อมูลจาก proxy server ก่อนที่จะไปค้นหา server ภายนอก เพื่อเป็นการประหยัด ช่องทางการจารจร เพื่อให้การเล่นอินเทอร์เน็ตจัดการได้เร็วขึ้นโดยการทำงานของ proxy server จะถูกจัดการโดยโปรแกรม squid
Squid
คือโปรแกรมที่ทำหน้าที่เป็น Proxyและ Cache เซิร์ฟเวอร์ที่มีประสิทธิภาพสูง เราสามารถค่า configuration ต่าง ๆ ของ squid เพื่อทำเป็น Proxy server เช่น การกำหนดขนาดของพื้นที่ที่ใช้ในการเก็บข้อมูล ทั้งในดีสก์และในแรม นอกจากนี้แล้ว เรายังสามารถทำการบริหารช่องทางที่เรียกว่า Bandwidth โดยใช้ squid ได้อีกด้วยโดยใช้ delay pools
Delay pools
Delay pools ทำหน้าที่ใช้เพื่อควบคุมปริมาณการใช้Traffic หรือการวิ่งของข้อมูลเพื่อไม่ให้ Bandwidth เต็มหรือพูดอีกอย่างหนึ่งได้ว่าเป็นการทำ Traffic Shaper
การกำหนดค่า Squid
ใช้คำสั่ง# vi /etc/squid/squid.conf
http_port 8080 #เป็นตัวกำหนด squid เพื่อฟังการร้องขอมากจาก client โดยกำหนดมาที่ port 8080
# หลีกเลี่ยงการเก็บ cgi scripts ลงในแคช 
acl QUERY urlpath_regex cgi-bin 
no_cache deny QUERY
#ส่วนนี้ใช้ทำ transparent proxy 
httpd_accel_host virtual httpd_accel_port 0 
httpd_accel_with_proxy on 
httpd_accel_uses_host_header on
# ขนาดแรมที่มีอยู่จริงในเครื่องหาร 3 

cache_mem 350 MB #กำหนดขนาดหรือการจองพื้นที่ใน Ram มาทำเป็น cache memory เพราะว่า CPU สามารถดึงข้อมูลใน Ram ได้เร็วกว่าใน Disk
# ที่เก็บ log files ถ้าไม่เก็บล็อกไฟล์ก็ /dev/null แทนไดเร็กทอรีนั้น ๆ 
cache_dir diskd /cache 1000 16 256 Q1=72 Q2=64 #หมายเลข 1000 นี้เป็นขนาดดิสก์ที่ squid ที่จองไว้ใช้ทำดิสก์แคชมีขนาด 1000 เมกะไบต์
cache_access_log /var/log/squid/access.log #มีไว้เก็บข้อมูลการร้องขอ client สำหรับทุก ๆ http และ icpquery 
cache_store_log /var/log/squid/store.log #แสดงถึง log-file ที่เก็บไว้ใน cache 
cache_log /var/log/squid/cache.log #เก็บขนาดของ object ที่ถูกดาวโหลดเข้าใน server
# กำหนดวิธีการแทนที่ข้อมูลเดิมในแคช 
cache_replacement_policy GDSF #เป็นวิธีการแทนที่ไฟล์ที่เก็บไว้ใน cache 
dns_testnames 202.29.14.1 
logfile_rotate 10 #กำหนดให้ logfile ทำงานแบบครบ 10 ไฟล์ค่อยแทนของเดิม
#acl = Access List เป็นการตั้งส่วนควบคุมการใช้งาน Proxy/cache เซิร์ฟเวอร์ 
acl all src 0.0.0.0/0.0.0.0 #all เป็นชื่อ ที่กำหนดให้ต้นทางคือทุกเครื่อง 
acl manager proto cache_object 
acl localhost src 127.0.0.1/255.255.255.255 # localhost เป็นชื่อคือต้นทางคือเครื่องตัวเอง 
acl rinet src 202.29.14.0/255.255.255.0 # rinet เป็นชื่อ ที่ใช้กำหนดให้ต้นทางคือ ip ในเน็ตเวิร์คขององค์กร 
acl SSL_ports port 443 563 
acl Safe_ports port 80 # http 
acl Safe_ports port 21 # ftp 
acl Safe_ports port 443 563 # https, snews 
acl Safe_ports port 70 # gopher 
acl Safe_ports port 210 # wais 
acl Safe_ports port 1025-65535 # unregistered ports 
acl Safe_ports port 280 # http-mgmt 
acl Safe_ports port 488 # gss-http 
acl Safe_ports port 591 # filemaker 
acl Safe_ports port 777 # multiling http 
acl CONNECT method CONNECT
#อนุญาตหรือไม่อนุญาต acl ที่ตั้งไว้ http_access allow manager 
http_access allow localhost 
http_access allow rinet 
http_access deny !Safe_ports 
http_access deny CONNECT !SSL_ports 
http_access deny all
icp_access allow localhost 
icp_access allow rinet
#ส่วน acl ก่อนการทำ Delay pools 
acl magic_words1 url_regex -i 202.29.14.1 
#กำหนด acl กลุ่มที่มีสิทธิ์ทุกอย่าง acl magic_words2 url_regex -i ftp .exe .mp3 .vqf .tar.gz .gz .rpm .zip .rar .avi .mpeg .mpe .mpg .qt .ram .rm .iso .raw .wav .mov #กำหนด acl กลุ่มที่ต้องควบคุม traffic คือไฟล์บางประเภทที่ใหญ่ ๆ
การกำหนดค่า Squid(Delay Pool)
# สำหรับ delay pool ที่คุณต้องการ --enable-delay-pools 
delay_pools 2 #กำหนดให้มี 2 pool ที่ต้องใช้
#สมมุติมี link ขนาด 2Mbits ซึ่ง 2 mbits == 256 kbytes ต่อวินาที เราจะจำกัดให้ใช้ได้ไม่เกิน 5 KB/s ต่อโหนด 
delay_class 1 2 #กำหนดให้ pool ที่ 1 เป็น class 2 ที่ถูกกำหนดค่าไว้ใน magic_word2 แบบจำกัด 
delay_parameters 1 256000/256000 5000/256000 
delay_access 1 allow magic_words2 #กลุ่มที่ดาวน์โหนดไฟล์ต่าง ๆ ที่กำนดไว้ 
delay_access 1 allow rinet #กลุ่มที่มี ip ต้นทางเป็นเครือข่ายภายใน
# -1/-1 หมายความว่าไม่มีการจำกัดขนาดของ traffic. 
delay_class 2 2 #กำหนดให้ pool ที่ 2 เป็น class 2 ที่ถูกกำหนดค่าไว้ใน magic_word1 แบบไม่จำกัด 
delay_parameters 2 -1/-1 -1/-1 
delay_access 2 allow magic_words1
# ไม่จำกัดขนาด 
reply_body_max_size 0 allow all
#ส่วน snmp เพื่อเอาไว้ใช้วัดการใช้งาน traffic 
acl snmppublic snmp_community public 
snmp_access allow snmppublic localhost 
snmp_access deny all
# Change domain 
cache_mgr test@hotmail.com
cachemgr_passwd secret_password all 
visible_hostname proxy1.ribr.ac.th 
unique_hostname proxy1.ribr.ac.th
#************************** End of squid.conf file ***************************
สร้าง Cache Directory
ใช้คำสั่ง#mkdir /cache
#cdmod 755 /cache/
#chown -R squid:squid /cache/
#mkdir /var/log/squid/
#chmod 755 /var/log/squid/
#chown -R squid:squid /cache/
#squid -z
#service squid start
ถ้าถูกต้องจะขึ้น[OK] ที่บรรทัด startting squid
ใช้คำสั่ง#tail -f/var/log/squid/access.log เพื่อติดตามการทำงานของ squid ูว่ามีการร้องขอใช้ proxy หรือยัง
ลองหาดาวน์โหลดไฟล์พวก .zip ดูว่าความเร็วในการดาวน์โหลดไม่เกิน 5 Kb จริงหรือไม่ ...
ที่มา : www squid-cache.org, www.thaifast.comwww.thaicert.nedtec.or.thwww.squid.visolve.com,www.tng.prirate.dk/how -squid.html

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