Beranda » » Caching Dynamic Content dan Youtube Menggunakan Squid pada OpenWrt

Caching Dynamic Content dan Youtube Menggunakan Squid pada OpenWrt

Oleh Taufik Pay pada Thursday, October 24, 2013 | 2:35 AM

Dengan menggunakan squid, kita dapat melakukan efisiensi penggunaan bandwidth dengan melakukan dynamic content caching – termasuk didalamnya melakukan caching video youtube.


Untuk melakukan dynamic content caching firmware OpenWrt Attitude Adjustment (12.09) dan paket Squid 2.7 stable9 yang tersedia di http://downloads.openwrt.org/attitude_adjustment/12.09/.

Tanpa banyak basa-basi...

Yang belum tahu Squid silahkan klik disini.

Packages yang diperlukan:
- Squid 2.7 stable9
- Perl

Berikut cara Caching Dynamic Content dan Youtube Menggunakan Squid pada OpenWrt:

Install paket Squid melalui Putty

BusyBox vx.xx.x (201x-02-22 23:42:42 CET) built-in shell (ash)
Enter 'help' for a list of built-in commands.
  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 ATTITUDE ADJUSTMENT (bleeding edge, rxxxxx) ----------
  * 1/4 oz Vodka      Pour all ingredents into mixing
  * 1/4 oz Gin        tin with ice, strain into glass.
  * 1/4 oz Amaretto
  * 1/4 oz Triple sec
  * 1/4 oz Peach schnapps
  * 1/4 oz Sour mix
  * 1 splash Cranberry juice
 -----------------------------------------------------
root@openwrt:~$ opkg update
Downloading http://downloads.openwrt.org/attitude_adjustment/12.09/x86/generic/packages/Packages.gz.
Updated list of available packages in /var/opkg-lists/attitude_adjustment.
root@openwrt:~$ opkg install squid

Selanjutnya install paket Perl

root@openwrt:~$ opkg install perl

Lakukan penyesuaian pada file "squid.conf" yang berada di dalam folder /etc/squid, sehingga menjadi seperti ini:

http_port 3128 transparent
icp_port 0
server_http11 on

pid_filename /var/run/squid.pid
mime_table /etc/squid/mime.conf
logfile_daemon /usr/lib/squid/logfile-daemon
unlinkd_program /usr/lib/squid/unlinkd
pinger_program /usr/lib/squid/pinger
error_directory /usr/share/squid/errors/English
icon_directory /usr/share/squid/icons
coredump_dir /mnt/sdb1/squid/cache
netdb_filename /mnt/sdb1/squid/cache/swap.state
access_log /mnt/sdb1/squid/log/access.log
cache_log /mnt/sdb1/squid/log/cache.log
cache_store_log /mnt/sdb1/squid/log/store.log

cache_mgr taufik.ph0814@gmail.com
visible_hostname proxy.neocomputer

dns_nameservers 8.8.8.8 127.0.0.1
dns_testnames 127.0.0.1

cache_mem 16 MB
cache_swap_low 98
cache_swap_high 99
maximum_object_size_in_memory 1 KB
minimum_object_size 128 bytes
maximum_object_size 350 MB

# sesuaikan direktori cache
cache_dir ufs /mnt/sdb1/squid/cache 6000 14 256

acl all src all
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8
acl localnet src 192.168.1.0/24

acl SSL_ports port 81
acl SSL_ports port 443
acl SSL_ports port 563

acl Safe_ports port 21 # ftp
acl Safe_ports port 70 # gopher
acl Safe_ports port 80 # http
acl Safe_ports port 210 # wais
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 443 # https
acl Safe_ports port 488 # gss-http
acl Safe_ports port 563
acl Safe_ports port 591 # filemaker
acl Safe_ports port 631
acl Safe_ports port 777 # multiling http
acl Safe_ports port 901
acl Safe_ports port 1025-65535 # unregistered ports

acl purge method PURGE
acl connect method CONNECT

acl shoutcast rep_header X-HTTP09-First-Line ^ICY.[0-9]

http_access allow manager localhost
http_access deny manager
http_access allow purge localhost
http_access deny purge
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet
http_access allow localhost
http_access deny all

upgrade_http0.9 deny shoutcast

acl youtube url_regex -i youtube.*
acl youtube url_regex -i youtube.*(ptracking|stream_204|player_204|gen_204).*$
acl youtube url_regex -i \.c\.(youtube|google)\.com\/(get_video|videoplayback|videoplay).*$

acl store_rewrite_list urlpath_regex \/(get_video|videoplayback\?id|videoplayback.*id|videoplay\?|videodownload\?)

acl store_rewrite_list urlpath_regex \.(3gp|mp(3|4)|flv|(m|f)4v|on2|fid|avi|mov|wm(a|v)|(mp(e?g|a|e|1|2))|mk(a|v)|jp(e?g|e|2)|gif|png|tiff?|bmp|tga|svg|ico|swf|exe|ms(i|u|p)|cab|psf|mar|bin|z(ip|[0-9]{2})|r(ar|[0-9]{2})|7z|alx|cod|jad|jar|apk)\?

acl store_rewrite_list_path urlpath_regex \.(3gp|mp(3|4)|flv|(m|f)4v|on2|fid|avi|mov|wm(a|v)|(mp(e?g|a|e|1|2))|mk(a|v)|jp(e?g|e|2)|gif|png|tiff?|bmp|tga|svg|ico|swf|exe|ms(i|u|p)|cab|psf|mar|bin|z(ip|[0-9]{2})|r(ar|[0-9]{2})|7z|alx|cod|jad|jar|apk)$

acl store_rewrite_list_domain url_regex ^http:\/\/([a-zA-Z-]+[0-9-]+)\.[A-Za-z]*\.[A-Za-z]*
acl store_rewrite_list_domain url_regex (([a-z]{1,2}[0-9]{1,3})|([0-9]{1,3}[a-z]{1,2}))\.[a-z]*[0-9]?\.[a-z]{3}

acl store_rewrite_list_domain_CDN url_regex (cbk|mt|khm|mlt|tbn)[0-9]?.google\.co(m|\.uk|\.id)
acl store_rewrite_list_domain_CDN url_regex ^http:\/\/([a-z])[0-9]?(\.gstatic\.com|\.wikimapia\.org)
acl store_rewrite_list_domain_CDN url_regex ^http:\/\/(www\.ziddu\.com.*\.[^\/]{3,4})\/(.*)
acl store_rewrite_list_domain_CDN url_regex ^http:\/\/[.a-z0-9]*\.photobucket\.com.*\.[a-z]{3}$
acl store_rewrite_list_domain_CDN url_regex streamate.doublepimp.com.*\.js\?
acl store_rewrite_list_domain_CDN url_regex \.rapidshare\.com.*\/[0-9]*\/.*\/[^\/]*
acl store_rewrite_list_domain_CDN url_regex \.doubleclick\.net.*
acl store_rewrite_list_domain_CDN url_regex photos-[a-z]\.ak\.fbcdn\.net
acl store_rewrite_list_domain_CDN url_regex quantserve\.com
acl store_rewrite_list_domain_CDN url_regex yieldmanager
acl store_rewrite_list_domain_CDN url_regex cpxinteractive

acl dontrewrite url_regex (get_video|video\?v=|videoplayback\?id|videoplayback.*id).*begin\=[1-9][0-9]*
acl dontrewrite url_regex \.(asp|aspx|cgi|jsp|js|php)\?
acl dontrewrite url_regex threadless.*\.jpg\?r=
acl dontrewrite url_regex (redbot\.org|yimg\.com)

acl getmethod method GET

storeurl_rewrite_children 12
storeurl_rewrite_concurrency 200

storeurl_access allow speedtest
storeurl_access allow youtube
storeurl_access allow store_rewrite_list
storeurl_access allow store_rewrite_list_domain
storeurl_access allow store_rewrite_list_path
storeurl_access allow store_rewrite_list_domain_CDN
storeurl_access deny dontrewrite
storeurl_access deny !getmethod
storeurl_access deny all

storeurl_rewrite_program /etc/squid/storeurl.pl

hierarchy_stoplist (ini|ui|lst|inf||mh-|sc-)$ (afs.dat|update.txt|vdf.info.gz|captcha|reset.css|gamenotice|ickernew.css)
acl QUERY urlpath_regex -i \.(ini|ui|lst|inf|mh-|sc-)$
acl QUERY urlpath_regex -i (afs.dat|captcha|reset.css|update.txt|gamenotice|vdf.info.gz)
cache deny QUERY

refresh_pattern -i (get_video\?|videoplayback\?|videoplay\?|videodownload\?) 43200 999999% 43200 override-expire ignore-reload ignore-private negative-ttl=0

refresh_pattern -i \.(gif|png|jpeg|jpg|bmp|tif|tiff|ico|swf)$ 43200 90% 43200 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-auth ignore-private

refresh_pattern -i \.(xml|html|htm|js|jsp|txt|css|php|asp)$ 21900 75% 43200 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-auth

refresh_pattern -i \.(flv|x-flv|mov|avi|qt|mpg|mpeg|wmv)$ 21900 80% 43200 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache
refresh_pattern -i \.(wav|mp3|mp4|au|mid)$ 43200 70% 43200 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-auth ignore-private
refresh_pattern -i \.(iso|deb|rpm|zip|tar|tgz|ram|rar|bin|ppt|doc)$ 43080 90% 43200 ignore-no-cache ignore-auth
refresh_pattern -i \.(zip|gz|arj|lha|lzh)$ 21080 100% 43200 override-expire ignore-no-cache ignore-auth
refresh_pattern -i \.(rar|tgz|tar|exe|bin|alx|cod|jad|jar|apk)$ 21080 100% 43200 override-expire ignore-no-cache ignore-auth ignore-reload
refresh_pattern -i \.(hqx|pdf|rtf|doc|swf)$ 43080 100% 43200 override-expire ignore-no-cache ignore-auth
refresh_pattern -i \.(inc|cab|ad|txt|dll)$ 43080 100% 43200 override-expire ignore-no-cache ignore-auth

refresh_pattern cgi-bin 0 0% 0
refresh_pattern . 0 20% 4320

header_access From deny all
header_access Server deny all
header_access Link deny all
header_access Via deny all
header_access X-Forwarded-For deny all

max_filedescriptors 65536
range_offset_limit 128 KB
read_ahead_gap 32 KB
reload_into_ims on
strip_query_terms on
negative_ttl 2 minutes
logfile_rotate 1
maximum_single_addr_tries 2
retry_on_error on
vary_ignore_expire on
client_db on 
ipcache_size 2048
ipcache_low 98
ipcache_high 99
quick_abort_min 0
quick_abort_max 0
quick_abort_pct 75
fqdncache_size 4096
pipeline_prefetch on
forwarded_for off
icp_hit_stale on
query_icmp on
emulate_httpd_log off
half_closed_clients off
buffered_logs on
Selanjutnya, ambil url redirectornya (credits mas ucok_karnadi)

cd /etc/squid
wget http://tempat-sampah.googlecode.com/svn/storeurl.pl
chmod +x /etc/squid/storeurl.pl
Cek konfigurasi Squid
root@OpenWrt:~# squid -k parse
Jika tidak ada error lanjutkan untuk menjalankan Squid
root@OpenWrt:~# squid -f /etc/squid/squid.conf -z
root@OpenWrt:~# squid -f /etc/squid/squid.conf
Akses internet via proxy, bisa dengan cara mengubah settingan di browser (pengguna firefox bisa pakai plugin foxyproxy) atau bisa dipaksa pakai firewall.

8 comments:

  1. Do you like live sex webcams? Then visit Chaturbate.

    ReplyDelete
  2. If you are looking for a reputable contextual advertising network, I recommend you check out Propeller Ads.

    ReplyDelete
  3. Are you making money from your exclusive shared links?
    Did you know Mgcash will pay you an average of $0.50 per link unlock?

    ReplyDelete
  4. link donwloadnya http://tempat-sampah.googlecode.com/svn/storeurl.pl
    mati

    ReplyDelete
  5. eToro is the ultimate forex broker for rookie and advanced traders.

    ReplyDelete
  6. Do you need free Google+ Circles?
    Did you know you can get them AUTOMATICALLY & TOTALLY FREE by registering on Like 4 Like?

    ReplyDelete
  7. BlueHost is ultimately the best web-hosting company for any hosting plans you might require.

    ReplyDelete
  8. If you're looking for a reputable Cost Per Sale ad company, I recommend that you take a look at Click Bank.

    ReplyDelete