1 / 73

交 通 大 學 計 算 機 中 心 陳 昌 盛 E-mail: cschen@cc.nctu.tw

WWW Proxy/Cache 系統的 建置與管理. 交 通 大 學 計 算 機 中 心 陳 昌 盛 E-mail: cschen@cc.nctu.edu.tw. TANet Web-proxy Tutorial Course, 88.05.14. 課程大綱. WWW Proxy/Caching 系統簡介 ( p3-p23) Squid 2.x 的建置與設定 ( p23-p44) 其他相關的系統管理課題 ( p45-p53) 附錄 ( p54-). 相關的資訊來源. 相關網站

faith
Télécharger la présentation

交 通 大 學 計 算 機 中 心 陳 昌 盛 E-mail: cschen@cc.nctu.tw

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WWW Proxy/Cache 系統的建置與管理 交 通 大 學 計 算 機 中 心 陳 昌 盛 E-mail: cschen@cc.nctu.edu.tw TANet Web-proxy Tutorial Course, 88.05.14

  2. 課程大綱 • WWW Proxy/Caching 系統簡介 (p3-p23) • Squid 2.x 的建置與設定 (p23-p44) • 其他相關的系統管理課題 (p45-p53) • 附錄 (p54-)

  3. 相關的資訊來源 • 相關網站 • http://www.auth.gr/Squid/ ( squid home page) • http://cache.is.co.za (squid.conf 設定檔) • http://squid.nlanr.net ( FAQ) • http://proxy.nctu.edu.tw • RFC 1016, 2186, 2187 • Mailing List • squid-users-request@ircache.net • http://proxy.nctu.edu.tw/mailing

  4. WWW Proxy 系統簡介 • Web Proxy/Caching 介紹 • TANet 骨幹頻寬分割使用 ( 24M bps) • 163.28.0.0 server 專用 channel ( 16M bps ) • 關於 Squid

  5. Web Caching - 基礎篇 • 什麼是 web caching ? • 什麼是 browser caching • 什麼是 proxy caching ? • Transparent Proxy • http accelerator vs proxy/caching • accelerator : 加快 remote 取 local 資料 • caching : 加快 local 取 remote 資料 • Redirector • 改寫 URL, 管制連線對象

  6. Web caching server 運作基本觀念 • Web caching 的基本運作原理 • hit:文件檔在 cache 中 • miss:文件檔不在 cache 中 • refresh_hit, refresh_miss • positive caching vs negative caching

  7. Web caching 相關protocol 的運作 • TCP connection 的使用時機 • browsers/cache 到另一個 web server 或 cache 取回資料 • UDP connection 的使用時機 • 某一 cache server 用以, 查詢其他的 neighbor cache , 有無一筆該站想要的資訊 • ICP query ( index 資料)

  8. Internet 2a 3b TANet Gateway X 2b • 163.28.xxx.yyy Proxy/caching server HD cache 1a 4b 1b PC client • TANet 區域網路使用者 Fig. 1 Proxy/caching server 運作示意圖

  9. Internet TANet Gateway 電子期刊等專用 Proxy server 163.28.xxx.yyy • No Cache allowed PC client • 限制使用對象 (必須註冊) Fig. 2 電子期刊專用 Proxy server 運作圖

  10. Internet 5 TANet Gateway 4 6 3 7a Router/Layer4 SW Proxy 2 HD cache 7b 1 PC client Fig. 3 Transparent Proxy/caching 運作示意圖

  11. Internet 2c TANet Gateway 1a 1b Local www server 1c HD cache httpd accelerator 2b 2a Port 80 • Inside firewall • Redirector on 163.28.xxx.yyy Fig. 4 www accelerator server 運作圖

  12. Proxy Cache Metric (參考數字) • From IRCACHE project • Hit ratio (25% - 30%) • byte hit ratio ( 20%, 通常低於前一項) • http://www.ircache.net/ • NCTU Proxy network • Hit ratio ( 30%-35%) • byte hit ratio ( 60%-70%) • http://proxy.nctu.edu.tw/ • http://www.edu.tw/moecc/index.htm ( 選文宣刊物)

  13. (T) (P) (C) Fig.5 Proxy.NCTU.edu.tw 的使用情況 (1998/11/27)

  14. 全球 Proxy Cache 網路架構 • 美國 NLANR 的 IRCACHE 網路 • http://www.ircache.net • 其他各地, 可以從上面網頁連上 • 臺灣地區 proxy cache 網路 • http://cache.sinica.edu.tw/cache/index.html

  15. Fig.6 IRCACHE 的架構, from http://www.ircache.net

  16. Internet TANet gateway MOE Proxy-N Proxy-NCTU Fig. 7 TANet 骨幹的 Proxy Network ( 163.28.0.0 )

  17. Squid Cache Hierarchy • Parent/child cache • parent 靠近網路骨幹 , child 在較偏遠端 • parent 替 child 解決 cache miss • siblings ( 同一層 --> 原意, 兄弟姐妹) • siblings 相互支援 ( loading 分攤 ) • 有一套固定的運作方式 (下一頁)

  18. Squid Cache Resolution Algorithm • Send ICP queries to all appropriate siblings • Wait for all replies to arrive with a configurable timeout (the default is two seconds). • Begin fetching the object upon receipt of the first HIT reply, or • Fetch the object from the first parent which replied with MISS (subject to weighting values), or • Fetch the object from the source

  19. Internet TANet Gateway 3b 4 5 HD cache 6b 2 Proxy server DNS server 3a 1 6a • 163.28.xxx.yyy PC client Fig. 8 Proxy/caching 與 DNS server 搭配運作圖

  20. What is Squid ? (1) • Squid 從美國的 Harvest 計劃而來(ARPA 支援). • Squid 是一個高效能的 proxy caching server 系統軟體 • supporting FTP, gopher, and HTTP data objects • Squid handles all requests in a single, non-blocking, I/O-driven process.

  21. What is Squid ? (2) • Squid supports SSL, extensive access controls, and full request logging. • 使用 ICP 通信協定 ( Internet Cache Protocol) • squid caches 可以安排成階層式(hierarchy) 或 網狀(mesh)的網路 .

  22. What is Squid ? (3) • Squid keeps meta data and especially hot objects cached in RAM • caches DNS lookups, supports non-blocking DNS lookups, • and implements negative caching of failed requests.

  23. Proxy 系統的建置與管理 • Proxy server 選定與安裝 • Cache hierarchy ( neighbor sites ) • Access control • Gateway program ( Gopher, Ftp, …) • Cache administration & Expiration • Cache 存放空間的管理 • 系統記錄與製做統計報告

  24. WWW Proxy server 的規畫 • WWW Proxy server 的規畫 • Memory, Disk, Network, CPU, UPS system • 最重要的系統資源是主記憶體 (physical memory). • 硬碟系統 (disk), 通常是系統主要效能的瓶頸.

  25. NCTU Proxy server 的規畫 • Hardware( 3 套) • 300 Mhz Pentium II CPU • 512MB RAM • 10 * 4GB UW-SCSI ( IBM ) • 共約 120 GB • 100M Network Interface Card ( Intel ) • Software • FreeBSD-2.2.8-stable • squid 2.2

  26. 取得 Proxy server Squid 軟體 • Squid software 的取得 • ftp://squid.nlanr.net (原始站) • ftp://ftp.nctu.edu.tw/WWW/Proxy/Squid/squid-2/* • Squid Server 的安裝 • FAQ • http://www.auth.gr/Squid/FAQ/FAQ.html • User Guide • http://www.auth.gr/SquidUsers/

  27. Squid 2.x 的組成 • Squid - 主要 server 程式 • dnsserver - 外掛的 DNS 查詢程式 • 附帶的管理與用戶單連線工具程式

  28. Squid-2 的建置與設定 • Getting and Compiling Squid % tar xzf squid-2.2-src.tar.gz % cd squid-2.2.RELEASE % ./configure --prefix=/home/squid % make

  29. Squid 中典型的系統目錄 • 範例 ( /home/squid/ ) • bin, cgi-bin, etc, logs, scripts • 主要設定檔安置目錄 ( /home/squid/etc/* ) • squid.conf, mime.conf, mib.txt, icons/*, errors/* • 系統記錄檔存放目錄 ( /home/squid/logs/* ) • access.log, cache.log, ... • Squid port • http_port : 3128 • icp_port: 3130

  30. How do I start Squid 2.x ? • 編輯 squid.conf • /usr/local/squid/bin/squid -z • 首先將 cache swap 目錄造出來 • /usr/local/squid/bin/RunCache & • 執行 RunCache 這個批次檔, 開始啟動 squid 這一組程式

  31. Squid.conf 設定的項目分類 (1) • 網路相關的設定選項 • 影響 “neighbor 選擇法則” 運作的選項 • 影響 cache size 設定的選項 • 記錄檔 (log) 路徑名稱與cache directors • “外部支援程式“相關的選項 • 調整 (tuning) caching 效能的選項 • timeouts

  32. Squid.conf 的設定項目分類(2) • 存取管制 (Access control) • Proxy 系統管理 (Administrative parameters) • Options for the cache registration service • httpd-accelerator options • 其它雜項設定 (Miscellaneous) • 限制各別站臺的使用頻寬 (Delay Pool parameters )

  33. Squid 的功能, 補充說明 • Ipcache, FQDNcache • Ipcache: Hostname to IP-Number mapping • FQDNCache : IP-Number to Hostname mapping • Cache Digest ( 2.x ) • a summary of the contents of an Internet Object Caching Server • an indication of whether or not particular URLs are in the cache • X-Forwarded-For • X-Forwarded-For: 128.138.243.150, unknown, 192.52.106.30

  34. Squid.conf 中, 需要定義的參數 - “proxy.nctu.edu.tw” 上的實例 • 大多數的參數使用內定值 (default ) • 底下就列出需要重新定義者 • Cache_peer proxy.edu.tw sibling 3128 3130 no-netdb-exchange • cache_mem 128M • cache_swap_low 93 • cache_swap_high 95 • cache_mem_low 90 • cache_mem_high 95 • maximum_object_size 16384 KB

  35. Squid.conf (cont.) • ipcache_size 20480 ( hostname --> IP addr. ) • ipcache_low 90 • ipcache_high 95 • fqdnsize 20480 ( IP addr ---> FQDN ) • cache_dir (可以再加) • cache_dir /home/squid/cache 100 16 256 • cache_dir /da1s1e 4000 32 32 • logfile_rotate 10

  36. 增建一個 cache directory (Squid.conf) • 增建某一個 cache directory的程序 • 編輯squid.conf, 增加一筆cache_dir 項目行 • 將該directory 初始化, 執行 • # squid -z • 通知Squid 重新分配 cache 的分佈, 執行 • # squid -k reconfigure • 不必停掉執行中的 squid 程式

  37. 移除某一個cache directory(Squid.conf) • 移除某一個 cache directory • 編輯squid.conf, 刪掉該筆cache_dir 項目行 • 將執行中的 squid 重新執行 (shutdown and restart) • # squid -k shutdown • # 重新執行 squid ( 使用RunCache 會自動重跑 ) • 刪除原系統中, 已不用的 cache directory • 必須中斷執行中的 squid 程式

  38. 不想 cache 臨近地區的data (squid.conf) • 使用 no_cache 這個選項功能 • 編輯 squid.conf ( squid-2) • 範例 1 ( IP address) • acl Local dst 140.113.0.0/16 • no_cache deny Local • 範例 2( domain name) • acl Local_D dstdomain edu.tw • no_cache deny Local_D

  39. Squid cache replacement algorithm • LRU (Least Recent Used) 是最基本原則 • Low water mark (90%), High water mark(95%) • 優先移除者 • negative cached, private key • 最後一次存取時間超過 LRU 的期限 (threshold) • 不可移除者 • 有其他用戶正需求這一個檔 • 正從上游站, 取過來的檔

  40. 關於 Access Control 的設定 • acl, http_access, icp_access • allow/deny • And/Or Logics • All elements of an acl entry are OR'ed together. • All elements of an access entry are AND'ed together. e.g. http_access and icp_access. • src/srcdomain, dst/dstdomain

  41. squid.conf (cont.)- access control [1] • 設立 Cache Manager • acl manager proto cache_object • acl localhost src 127.0.0.1/255.255.255.255 • acl Proxy src proxy.nctu.edu.tw proxy2.nctu.edu.tw proxy3.nctu.edu.tw • acl purge method purge • acl FTP proto FTP • acl all src0.0.0.0/0.0.0.0

  42. squid.conf (cont.)- access control [2] • acl twdn dstdomaintw twnic.net hinet.net acer.net wownet.net seeder.net silkera.net neto.net timenet.net tw.aunet.net • acl TANet src 163.28.0.0/16 proxy.thu.edu.tw • acl HCdn srcdomain nthu.edu.tw nchc.gov.tw srrc.gov.tw chu.edu.tw nhctc.edu.tw hceb.edu.tw hc.edu.tw hcc.edu.tw cic.edu.tw mhit.edu.tw firdi.org.tw hchcc.gov.tw lctc.edu.tw ymit.edu.tw chinmin.edu.tw thctc.edu.tw

  43. squid.conf (cont.)- access control (3) • Http_access • http_access allow manager Proxy • http_access deny manager • … • http_access deny all • icp_access • icp_access allow TANet • …. • icp_access deny all

  44. ACL ban list ( 管制) • 範例 1 ( 找 keyword, 用 regular expression) • acl Cooking1 url_regex cooking • acl Recipe1 url_regex recipe • http_access deny Cooking1 • http_access deny Recipe1 • http_access allow all • 範例 2 ( 用 domain name) • acl Cooking2 dstdomain gourmet-chef.com • http_access deny Cooking2 • http_access allow all

  45. Syslog maintenance • /home/squid/etc/squid.conf • logfile_rotate 3 • Crontab entry for log-rotate • 0 0 * * * /bin/kill -USR1 `cat /home/squid/logs/squid.pid` • 每天執行一次, 以避免記錄檔越來越大, 無法處理

  46. 相關管理的工具程式 • wget • <ping, traceroute, nslookup> on proxy server homepage • cache manager CGI ( cachemgr.cgi) • 使用 Apache 為例 • srm.conf, squid.conf, access.conf • auto-proxy configuration support

  47. 設定 Cache Manager ( Apache)- 參考 FAQ 9.1 - 9.9 • /home/squid/etc/srm.conf ScriptAlias /Squid/cgi-bin/ /home/squid/cgi-bin • /home/squid/etc/access.conf < Location /Squid/cgi-bin/cachemgr.cgi> order deny,allow deny form all allow from proxy.nctu.edu.tw,proxy2.nctu.edu.tw </Location>

  48. 設定 Cache Manager ( Apache)- 參考 FAQ 9.1 - 9.9 (cont.) • /home/squid/etc/squid.conf acl manager proto cache_object acl localhost srt 127.0.0.1/255.255.255.255 acl all src 0.0.0.0/0.0.0.0 # http_access deny manager !localhost http_access allow all

  49. Sample - access.log(1) 912355210.560 10097 super.Dorm9.NCTU.edu.tw TCP_MISS/000 0 GET http://adforce.i mgis.com/? - DIRECT/adforce.imgis.com - 912355210.712 0 ccproxy.nsysu.edu.tw UDP_MISS/000 76 ICP_QUERY http://lygo. com/ly/p/bandn/thumbnails/9780553574753.gif - NONE/- - 912355210.712 0 w3-gate2.ntu.edu.tw UDP_DENIED/000 82 ICP_QUERY http://www. tvb.com.hk/drama/image/home/top_link/newsong_d.gif - NONE/- - 912355210.712 0 proxy.ncku.edu.tw UDP_HIT/000 70 ICP_QUERY http://www.penth ousemag.com/reading/images/c3.gif - NONE/- - 912355210.718 10171 proxy.nthu.edu.tw TCP_REFRESH_HIT/304 265 GET http://www.be seen.com/ads/r03_howlow.gif - DIRECT/www.beseen.com - 912355211.482 358 bill.Dorm-GD1.NCTU.edu.tw TCP_HIT/200 1762 GET http://www.j girls.com/jconsole/index.html - NONE/- text/html 912355211.482 358 hilbert.Dorm-GD1.NCTU.edu.tw TCP_IMS_HIT/304 225 GET http:/ /www.bannersolutions.com/images/ad_info.gif - NONE/- image/gif

  50. Sample -cache.log 1998/11/30 06:10:34| Starting Squid Cache version 2.1.PATCH1 for i386-unknown-freebsd2.2.7... 1998/11/30 06:10:34| Process ID 18654 1998/11/30 06:10:34| With 1024 file descriptors available 1998/11/30 06:10:34| Performing DNS Tests... 1998/11/30 06:10:34| Successful DNS name lookup tests... 1998/11/30 06:10:34| helperOpenServers: Starting 20 'dnsserver' processes 1998/11/30 06:10:34| Unlinkd pipe opened on FD 29 1998/11/30 06:10:34| Swap maxSize 32768000 KB, estimated 1638400 objects 1998/11/30 06:10:34| Target number of buckets: 40960 1998/11/30 06:10:34| Using 65536 Store buckets, replacement runs every 1 second 1998/11/30 06:10:34| Max Mem size: 131072 KB 1998/11/30 06:10:34| Max Swap size: 32768000 KB 1998/11/30 06:10:34| Store logging disabled 1998/11/30 06:10:34| Rebuilding storage in Cache Dir #0 (CLEAN)

More Related