Kamis, 03 November 2011

Caching Youtube 2

1. buat script untuk manipulasi youtube.
#!/usr/bin/perl
$|=1;
while (<>) {
@X = split;
$url = $X[0];
$url =~s@^http://(.*?)/get_video\?(.*)video_id=(.*?)&.*@squid://videos.youtube.INTERNAL/ID=$3@;
$url =~s@^http://(.*?)/get_video\?(.*)video_id=(.*?)$@squid://videos.youtube.INTERNAL/ID=$3@;
$url =~s@^http://(.*?)/videoplayback\?(.*)id=(.*?)$@squid://videos.google.INTERNAL/ID=$3@;
$url =~s@^http://(.*?)/videoplayback\?(.*)id=(.*?)&.*@squid://videos.google.INTERNAL/ID=$3@;
print "$url\n"; }
 
2. di squid.conf:

acl store_rewrite_list url_regex ^http://(.*?)/get_video\?
acl store_rewrite_list url_regex ^http://(.*?)/videoplayback\?

refresh_pattern ^http://(.*?)/get_video\? 10080 90% 999999 override-expire ignore-no-cache ignore-private
refresh_pattern ^http://(.*?)/videoplayback\? 10080 90% 999999 override-expire ignore-no-cache ignore-private
 
 contoh :


#squid.conf SQUID-2.7.STABLE6


# ACCESS CONTROLS
acl all src all
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl localnet src 192.168.100.0/255.255.255.0
acl localnet src 192.168.0.0/255.255.255.0
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443 563
acl Safe_ports port 80 # http
acl Safe_ports port 88 # to my local webserver
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 PURGE method PURGE
acl snmppublic snmp_community public
acl QUERY urlpath_regex cgi-bin \?
acl store_rewrite_list url_regex ^http://(.*?)/get_video\?
acl store_rewrite_list url_regex ^http://(.*?)/videoplayback\?
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access allow localnet
http_access allow PURGE localhost
http_access deny PURGE
http_access deny all
http_reply_access allow manager
http_reply_access allow all
icp_access deny all
# NETWORK OPTIONS
http_port 8080 transparent
# zph
zph_mode tos
zph_local 0×30
zph_parent 0
zph_option 136
# MEMORY CACHE OPTIONS
cache_mem 16 MB
maximum_object_size_in_memory 32 KB
memory_replacement_policy heap GDSF
# DISK CACHE OPTIONS
cache_replacement_policy heap LFUDA
cache_dir aufs /cache 50000 16 256
maximum_object_size 128l MB
cache_swap_low 98
cache_swap_high 99
# LOGFILE OPTIONS
access_log none
logfile_daemon /usr/local/lib/squid/logfile-daemon
cache_log /var/log/squid/cache.log
cache_store_log none
mime_table /usr/local/squid/etc/mime.conf
pid_filename /var/run/squid.pid
netdb_filename /usr/local/squid/var/logs/netdb.state

# OPTIONS FOR FTP GATEWAYING
ftp_user user@ableh.org
ftp_passive on
# OPTIONS FOR EXTERNAL SUPPORT PROGRAMS
unlinkd_program /usr/local/lib/squid/unlinkd
pinger_program /usr/local/lib/squid/pinger
# OPTIONS FOR URL REWRITING
storeurl_rewrite_program /etc/squid/store_url_rewrite_1.pl
storeurl_rewrite_children 1
storeurl_rewrite_concurrency 10
storeurl_access allow store_rewrite_list
storeurl_access deny all
# OPTIONS FOR TUNING THE CACHE
## For squid-2.6
## We recommend you to use the following two lines.
# acl QUERY urlpath_regex cgi-bin \?
# cache deny QUERY
cache allow store_rewrite_list
cache deny QUERY
refresh_pattern ^http://(.*?)/get_video\? 10080 90% 999999 override-expire ignore-no-cache ignore-private
refresh_pattern ^http://(.*?)/videoplayback\? 10080 90% 999999 override-expire ignore-no-cache ignore-private
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320
# HTTP OPTIONS
request_header_max_size 20 KB
reply_header_max_size 20 KB
request_body_max_size 0 KB
via on
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
ie_refresh on
vary_ignore_expire on
# TIMEOUT
connect_timeout 3 minute
request_timeout 7 minute
persistent_request_timeout 5 minute
# ADMINISTRATIVE PARAMETERS
cache_mgr admin-proxy@ableh.org
cache_effective_user nobody
cache_effective_group nogroup
visible_hostname proxy.ableh.org
# PERSISTENT CONNECTION HANDLING
client_persistent_connections off
server_persistent_connections off
# SNMP OPTIONS
snmp_access allow snmppublic localhost
snmp_access deny all
# ICP OPTIONS
icp_port 3130
log_icp_queries off
# DNS OPTIONS
check_hostnames on
allow_underscore on
ignore_unknown_nameservers off
ipcache_size 2048
ipcache_low 98
ipcache_high 99
fqdncache_size 8192
# MISCELLANEOUS
memory_pools off
cachemgr_passwd blablabla info config *
client_db off
reload_into_ims on
coredump_dir /cache
pipeline_prefetch on

#######

Di url ini: http://wiki.squid-cache.org/ConfigExamples/DynamicContent/YouTube/Discussion
Simpan file diff yang ada di bagian bawah halaman sebagai squid.diff:
— src/client_side.c 2008-10-30 07:37:56 +0800
+++ src/client_side.c 2008-11-05 23:44:55 +0800
@@ -2399,6 +2399,18 @@
is_modified = 0;
}
}
+ /* bug fix for 302 moved_temporarily loop bug when using storeurl*/
+ if (mem->reply->sline.status == HTTP_MOVED_TEMPORARILY) {
+ const char *cloc = httpHeaderGetStr(&e->mem_obj->reply->header, HDR_LOCATION);
+ if (!strcmp(http->uri,cloc)) {
+ debug(33, 1) (“Loop Detected: %s Redirect to: %s\n”,
+ http->uri,cloc);
+ http->log_type = LOG_TCP_MISS;
+ clientProcessMiss(http);
+ return;
+ }
+ }
+ /* bug fix end here*/
stale = refreshCheckHTTPStale(e, r);
debug(33, 2) (“clientCacheHit: refreshCheckHTTPStale returned %d\n”, stale);
if (stale == 0) {
Setelah extract source squid, lakukan patch dengan option dry-run untuk tes file diff:
# tar jxf squid-2.7.STABLE6.tar.bz2
# cd squid-2.7.STABLE6
# patch -p0 –dry-run < ../squid.diff
patching file src/client_side.c
Hunk #1 succeeded at 2407 with fuzz 2 (offset 8 lines).
#
Kalau hasil patch dg option –dry-run seperti di atas berarti patch bisa dipakai, patch kedua kalinya dengan menghilangkan option –dry-run:
# patch -p0 < ../squid.diff
patching file src/client_side.c
Hunk #1 succeeded at 2407 with fuzz 2 (offset 8 lines).
#
Setelah itu baru configure lalu make squid.

Tidak ada komentar:

Posting Komentar