SQUID | High-performance Proxy caching server
wawan bahtiar, System Administration
PT. Cakra Lintas Nusantara
sysadmin[at]cakralintas.net.id
Publish © 2005 Wawan Bahtiar a/n PT. Cakra Lintas Nusantara, Amacom Building, Jl. By Pass Ngurah Rai 274 Jimbaran, Bali Indonesia.
Diperbolehkan untuk diperbanyak, disebarluaskan dan atau perubahan pada dokumen ini, asal dengan menyertakan penulis dan konten hak milik.
Daftar isi :
1. Pendahuluan
1.1 Apa itu Squid ?
1.2 Apa itu Internet Object caching ?
2. Installasi Squid
3. Konfigurasi dan Optimasi squid
4. Paramater lain Tunning System Squid
5. Penutup
1. Pendahuluan
1.1 Apa itu Squid ?
Squid adalah high-performance proxy caching server untuk web klien, yang sudah mendukung FTP, ghoper, dan HTTP data object. Berbeda dengan software caching yang lama, squid menangani semua permintaan tunggal (single), non-blocking, I/O-driven proses.
Squid menyimpan meta data dan terutama hot-object yang di simpan di RAM, menyimpan DNS lookups, mendukung non-blocking DNS lookups, dan implementasi negative-caching jika permintaan gagal.
Squid mendukung SSL, access kontrol yang banyak, dan full request logging. Dengan menggunakan lightweight internet cache protokol, squid cache dapat dibuat dalam suatu hirarki atau mesh untuk meningkatkan penghematan bandwidth.
Squid terdiri dari program server utama squid, sebuah Domain Name System lookup (program dnsserver), beberapa program tambahan untuk permintaan menulis ulang dan melakukan authentication, dan beberapa tools management client. Ketika squid dijalankan, itu akan menambah jumlah proses dnsserver, masing-masing bertugas sendiri-sendiri, blocking Domain Name System (DNS) lookup. Ini akan mengurangi waktu tunggu DNS lookups.
1.2 Apa itu Internet Object caching ?
Internet Object caching adalah suatu cara untuk menyimpan hasil permintaan internet-object. (seperti, data yang ada dari HTTP, FTP, dan ghoper protokol) untuk membuat sistem dekat dengan permintaan daripada ke sumber aslinya. Web browser dapat menggunakan lokal squid cache sebagai proxy HTTP server, ini akan mengurangi waktu akses seperti halnya penghematan bandwidth.
2. Installasi Squid
Paket-paket yang dibutuhkan :
- compiler gcc dan tool pendukung compiler (development program)
- malloc, program memori utilisasi
- Squid source program (tarball)
Download paket dan install :
1 2 3 4 | root@proxy root# mkdir /download root@proxy download# cd /download root@proxy download# wget http://www.squid-cache.org/Versions/v2/2.5/squid-2.5.STABLE14.tar.gz root@proxy download# wget ftp://ftp.gnu.org/gnu/malloc.tar.gz |
Sebelum installasi squid, pastikan program squid lama anda yang mungkin sudah terinstall di sistem untuk di uninstall dulu.
1 2 3 | root@proxy root# rpm -qa |grep squid squid-2.5STABLE6 root@proxy root# rpm -e squid-2.5STABLE6 |
Installasi semua paket squid :
1 2 3 | root@proxy download# tar xzf malloc.tar.gz root@proxy download# cd malloc root@proxy malloc# vi Makefile |
—-semula—–
1 2 3 | # Use this on System V. #CPPFLAGS = -DUSG ————— |
diubah —
—-menjadi—–
1 2 3 | # Use this on System V. CPPFLAGS = -DUSG ————— |
1 2 3 | root@proxy malloc# make root@proxy malloc# cp libmalloc.a /usr/lib/libgnumalloc.a root@proxy malloc# cp malloc.h /usr/include/gnumalloc.h |
Tunning system sebelum installasi squid (ini maksudnya, untuk mengaktifkan langsung pada saat kompile squid), tujuannya untuk menaikkan File Deskriptor (FD) , memperbesar proses penggunaan file :
1 2 3 4 5 6 7 | root@proxy malloc# vi /etc/security/limits.conf * Soft nofile 8192 * Hard nofile 8192 root@proxy malloc# ulimit -HSn 8192 root@proxy malloc# ulimit -n 8192 |
Installasi Core Squid program :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | root@proxy malloc# cd /download root@proxy download# tar squid-2.5.STABLE10.tar.gz root@proxy download# cd squid-2.5.STABLE10 root@proxy squid-2.5.STABLE10# ./configure \ –prefix=/usr –exec-prefix=/usr –bindir=/usr/bin \ –sbindir=/usr/sbin –libexecdir=/usr/libexec \ –datadir=/usr/share/squid –sysconfdir=/etc/squid \ –sharedstatedir=/usr/com –localstatedir=/var \ –libdir=/usr/lib –includedir=/usr/include \ –infodir=/usr/share/info –mandir=/usr/share/man \ –libexecdir=/usr/lib/squid \ –enable-gnuregex \ –enable-async-io=24 \ –with-aufs-threads=24 \ –with-pthreads \ –with-aio \ –with-dl \ –enable-storeio=aufs \ –enable-removal-policies=heap \ –enable-icmp \ –enable-delay-pools \ –disable-wccp \ –enable-snmp \ –enable-ssl \ –enable-cache-digests \ –enable-default-err-languages=English \ –enable-err-languages=English \ –enable-poll \ –enable-linux-netfilter \ –disable-ident-lookups \ –disable-hostname-checks \ –enable-underscores \ –enable-cachemgr-hostname=localhost |
Catatan: 7 baris paling atas adalah penyesuaian konfigurasi dari sistem yang ada di redhat/fedora. dan untuk opsi-opsi silahkan kompile jika dibutuhkan, kalau tidak dibutuhkan jangan dimasukkan pada saat kompile.
1 2 3 4 5 | root@proxy squid-2.5.STABLE10# mkdir /var/log/squid root@proxy squid-2.5.STABLE10# chown -R squid:squid /var/log/squid root@proxy squid-2.5.STABLE10# make all && make install root@proxy squid-2.5.STABLE10# strip /usr/lib/squid/* root@proxy squid-2.5.STABLE10# strip /usr/sbin/squid |
3. Konfigurasi dan Optimasi squid
Konfigurasi squid :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | http_port 3128 icp_port 3130 ssl_unclean_shutdown on hierarchy_stoplist cgi-bin ? acl QUERY urlpath_regex cgi-bin \? no_cache deny QUERY cache_mem 6 MB cache_swap_low 98 cache_swap_high 99 maximum_object_size 128 MB maximum_object_size_in_memory 32 KB ipcache_size 8192 ipcache_low 98 ipcache_high 99 fqdncache_size 8192 cache_replacement_policy heap LFUDA memory_replacement_policy heap GDSF cache_dir aufs /cache1 5000 10 256 cache_dir aufs /cache2 5000 10 256 cache_dir aufs /cache3 5000 10 256 cache_access_log /var/log/squid/access.log #cache_access_log none cache_log /var/log/squid/cache.log cache_store_log none emulate_httpd_log off pid_filename /var/run/squid.pid mime_table /etc/squid/mime.conf log_fqdn off memory_pools off client_netmask 255.255.255.255 ftp_user squid@newhack.org ftp_list_width 32 ftp_passive on ftp_sanitycheck on refresh_pattern ^ftp: 10080 95% 241920 reload-into-ims override-lastmod refresh_pattern . 180 95% 120960 reload-into-ims override-lastmod quick_abort_min 0 quick_abort_max 0 quick_abort_pct 98 negative_ttl 2 minutes half_closed_clients off read_timeout 15 minutes client_lifetime 2 hours pconn_timeout 60 seconds request_timeout 1 minutes shutdown_lifetime 10 seconds positive_dns_ttl 60 seconds negative_dns_ttl 30 seconds acl all src 0.0.0.0/0.0.0.0 acl manager proto cache_object acl localhost src 127.0.0.1 acl lan src 192.168.0.0/24 192.168.1.0/24 acl to_localhost dst 127.0.0.0/8 acl PURGE method PURGE acl POST method POST acl IpAddressOnly url_regex ^http://[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/$ acl IpAddressOnly url_regex ^http://[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ acl GETONLY method GET acl VIRUS urlpath_regex winnt/system32/cmd.exe? 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 snmppublic snmp_community public # Hotmail workaround header_access Accept-Encoding deny all http_access allow localhost http_access allow lan http_access allow manager lan http_access allow PURGE localhost http_access deny manager http_access deny !Safe_ports http_access deny CONNECT !SSL_ports http_access deny PURGE http_access deny VIRUS http_access deny all http_reply_access allow all icp_access allow lan icp_access deny all miss_access allow lan miss_access deny all cachemgr_passwd passwordku all cache_mgr proxy@newhack.org cache_effective_user squid cache_effective_group squid visible_hostname proxies3.newhack.org unique_hostname proxy.newhack.org httpd_accel_host virtual httpd_accel_port 80 httpd_accel_with_proxy on httpd_accel_uses_host_header on httpd_accel_no_pmtu_disc on logfile_rotate 7 forwarded_for on icp_hit_stale on log_icp_queries off query_icmp on buffered_logs off strip_query_terms off icon_directory /usr/share/squid/icons error_directory /usr/share/squid/errors/English store_avg_object_size 13 KB store_objects_per_bucket 10 client_db on snmp_port 3401 snmp_access allow snmppublic lan snmp_access deny all coredump_dir /cache1 reload_into_ims on pipeline_prefetch on ie_refresh on vary_ignore_expire on |
Tips Optimasi Squid :
Jika ada beberapa situs terdekat yg mungkin hanya 1 hop, di-by pass saja supaya kerja Squid benar-benar utk yg jaraknya jauh (hopnya banyak).
hierarchy_stoplist cgi-bin ? localhost domain-anda.com isp-anda.com domainku.web.id
acl QUERY urlpath_regex cgi-bin \? localhost domain-anda.com isp-anda.com domainku.web.id
no_cache deny QUERY
Dari pengalaman dan rekomendasi 6 MB akan lebih cepat dan biarkan Squid bekerja lebih keras lagi.
1 2 3 | cache_mem 6 MB cache_swap_low 98 cache_swap_high 99 |
Maksimum obyek di hardisk dan di memori diupayakan lebih besar shg byte hit lebih tinggi (bisa dinaikkan lagi jika hardisk berkecepatan tinggi dan jumlahnya banyak dg memori yg lebih besar pula).
1 2 | maximum_object_size 128 MB maximum_object_size_in_memory 32 KB |
Jika memori 512 MB atau lebih besar silahkan cache diperbesar.
1 2 3 | ipcache_size 2048 ipcache_low 98 ipcache_high 99 |
Untuk heap replacement saya memakai LFUDA utk cache hardisk dan GDSF utk cache memori dg alasan di hardisk diprioritaskan obyek yg ukuran besar-besar dan di memori obyek yg ukurannya kecil-kecil utk disimpan.
1 2 | cache_replacement_policy heap LFUDA memory_replacement_policy heap GDSF |
Idealnya ruang di hardisk yg anda pakai hanya sekitar 70% dari total krn semakin penuh Squid akan semakin pelan mencari tempat kosong, mis. utk cache 1 GB maka yg dipakai hanya 700MB (jangan 1GB dipakai semuanya). Jangan lupa hanya 1 direktori per drive krn faktor penghambat adalah kecepatan spindle hardisk lho, bukan terus dg memperbanyak direktori pada 1 hd akan mempercepat (hd orde milidetik, memori orde nanodetik). Jadi mending hardisknya banyak tapi ukurannya kecil-kecil daripada hanya 1 berukuran besar. Terus jika OS-nya Linux pakailah FS-nya Reiser (versi 4 tercepat) dg metode akses aufs. Diskd optimal di FreeBSD tetapi tidak di Linux lho. Jangan lupa di partisi tsb noatime dan notail diaktifkan spy tidak menambah ekstra write saat menulis atau membaca. Intinya hardisk adalah faktor penghambat terbesar di Squid.
saran kira2 70% dari 16GB
cache_dir aufs /cachez 12000 28 256
atau (utk ruang 4GB-an per hardisk)
1 2 3 4 | cache_dir aufs /cachehardisk1 3000 8 256 cache_dir aufs /cachehardisk2 3000 8 256 cache_dir aufs /cachehardisk3 3000 8 256 cache_dir aufs /cachehardisk4 3000 8 256 |
Logging untuk info yg vital saja dan diusahakan file-file log ada di hardisk tersendiri spy tidak mempengaruhi kecepatan direktori cache utamanya.
1 2 3 4 | log_fqdn off log_icp_queries off cache_log none cache_store_log none |
Dengan memaksa sedikit supaya akses obyek lebih intensif di lokal Squid dan waktu simpan ditambah sebelum proses validasi terjadi (mis. validasi terjadi per 3 jam dg penyimpanan obyek terlama 3 bulan, utk ftp bisa lebih lama lagi).
refresh_pattern ^ftp: 10080 95% 241920 reload-into-ims override-lastmod
refresh_pattern . 180 95% 120960 reload-into-ims override-lastmod
Toleransi aborting dihilangkan saja.
1 2 3 | quick_abort_min 0 quick_abort_max 0 quick_abort_pct 98 |
Mematikan dan merekonfigurasi Squid jangan terlalu cepat krn bisa mengakibatkan integritas file kacau.
shutdown_lifetime 10 seconds
Tidak perlu reservasi memori.
1 | memory_pools off |
Penting utk relasi dg sibling dg mengukur respons-nya via ICP dan ICMP.
1 2 | icp_hit_stale on query_icmp on |
Penting utk meningkatkan refresh pattern lebih lanjut.
1 2 3 | reload_into_ims on pipeline_prefetch on vary_ignore_expire on |
Sekali lagi Squid diperlukan utk mengambil yg jaraknya jauh, jarak dekat langsung saja
1 2 3 4 5 6 7 8 9 | acl local-dst dst semuaalamatlokal semuaalamatipygdekat acl local-domain dstdomain localhost domain-anda.com isp-anda.com domainku.web.id always_direct allow localhost local-dst local-domain always_direct deny all Sys-V init squid : root@proxy root# vi /etc/init.d/squid |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | #!/bin/bash # squid This shell script takes care of starting and stopping # Squid Internet Object Cache # # chkconfig: – 90 25 # description: Squid – Internet Object Cache. Internet object caching is \ # a way to store requested Internet objects (i.e., data available \ # via the HTTP, FTP, and gopher protocols) on a system closer to the \ # requesting site than to the source. Web browsers can then use the \ # local Squid cache as a proxy HTTP server, reducing access time as \ # well as bandwidth consumption. # pidfile: /var/run/squid.pid # config: /etc/squid/squid.conf PATH=/usr/bin:/sbin:/bin:/usr/sbin export PATH # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 # check if the squid conf file is present [ -f /etc/squid/squid.conf ] || exit 0 if [ -f /etc/sysconfig/squid ]; then . /etc/sysconfig/squid fi # don’t raise an error if the config file is incomplete # set defaults instead: SQUID_OPTS=${SQUID_OPTS:-”-DY”} SQUID_PIDFILE_TIMEOUT=${SQUID_PIDFILE_TIMEOUT:-20} SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100} # determine the name of the squid binary [ -f /usr/sbin/squid ] && SQUID=squid [ -z "$SQUID" ] && exit 0 prog=”$SQUID” # determine which one is the cache_swap directory CACHE_SWAP=`sed -e ’s/#.*//g’ /etc/squid/squid.conf | \ grep cache_dir | awk ‘{ print $3 }’` [ -z "$CACHE_SWAP" ] RETVAL=0 start() { for adir in $CACHE_SWAP; do if [ ! -d $adir/00 ]; then echo -n “init_cache_dir $adir… ” $SQUID -z -F -D >> /var/log/squid/squid.out 2>&1 fi done echo -n $”Starting $prog: ” ulimit -HSn 2048 /bin/nice –20 $SQUID $SQUID_OPTS >> /var/log/squid/squid.out 2>&1 RETVAL=$? if [ $RETVAL -eq 0 ]; then timeout=0; while : ; do [ ! -f /var/run/squid.pid ] || break if [ $timeout -ge $SQUID_PIDFILE_TIMEOUT ]; then RETVAL=1 break fi sleep 1 && echo -n “.” timeout=$((timeout+1)) done fi [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SQUID [ $RETVAL -eq 0 ] && echo_success [ $RETVAL -ne 0 ] && echo_failure echo return $RETVAL } stop() { echo -n $”Stopping $prog: ” $SQUID -k check >> /var/log/squid/squid.out 2>&1 RETVAL=$? if [ $RETVAL -eq 0 ] ; then $SQUID -k shutdown & rm -f /var/lock/subsys/$SQUID timeout=0 while : ; do [ -f /var/run/squid.pid ] || break if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then echo return 1 fi sleep 2 && echo -n “.” timeout=$((timeout+2)) done echo_success echo else echo_failure echo fi return $RETVAL } reload() { $SQUID $SQUID_OPTS -k reconfigure } restart() { stop start } condrestart() { [ -e /var/lock/subsys/squid ] && restart || : } rhstatus() { status $SQUID $SQUID -k check } probe() { return 0 } case “$1″ in start) start ;; stop) stop ;; reload) reload ;; restart) restart ;; condrestart) condrestart ;; status) rhstatus ;; probe) exit 0 ;; *) echo $”Usage: $0 {start|stop|status|reload|restart|condrestart}” exit 1 esac exit $? |
4. Paramater lain Tunning System Squid :
Edit di /etc/sysctl.conf, dan tambahkan di bawah ini:
1 2 3 | root@proxy root# vi /etc/sysctl.conf # add port outgoing net.ipv4.ip_local_port_range = 1024 32768 |
Tunning di fstab :
edit di /etc/fstab, harusnya seperti ini yg harus sama yg di ubah (biasanya ada tambahan noatime/notail, untuk jenis mounting yg lain biarkan saja, jangan diubah):
1 2 3 4 5 6 7 8 9 | /dev/hda1 / reiserfs defaults,noatime 1 1 /dev/hda6 /boot reiserfs defaults,noatime 1 2 /dev/hda7 /var reiserfs defaults,noatime 1 2 /dev/hda8 /usr reiserfs defaults,noatime 1 2 /dev/hda9 /home reiserfs defaults,noatime 1 2 /dev/sda1 /cache01 reiserfs noatime,notail 0 0 /dev/sda2 /cache02 reiserfs noatime,notail 0 0 /dev/sdb1 /cache03 reiserfs noatime,notail 0 0 /dev/sdb2 /cache04 reiserfs noatime,notail 0 0 |
Check yg melakukan koneksi ke squid :
1 | root@proxy root# tail -f /var/log/squid/access.log |
5. Penutup
Terimakasih :
http://forum.linux.or.id (mas dani, fish, fai, firewaxx, dan semua barudak forum.linux.or.id)
http://www.squid-cache.org/Doc/FAQ/FAQ.html
nb.
Telah dicoba dan dibuktikan oleh saya pribadi menggunakan OS Trustix Secure Linux dan Ubuntu Server
//Dengan Spek PC :
Processor CoreDuo 3.0Ghz
Memory DDR2 2GB
HDD 40GB | OS System
SCSI ;
9,2GB 10K RPM | Cache1
9,2GB 10K RPM | Cache2
9,2GB 10K RPM | Cache3
Copas : http://newhack.or.id/2007/11/05/squid-high-performance-proxy-caching-server/
This entry was posted on Tuesday, February 23rd, 2010 at 4:52 pm and is filed under Linux OS. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.




