FBB High-performance Proxy caching server

High-performance Proxy caching server
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 :
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.
root@proxy root# rpm -qa |grep squid
squid-2.5STABLE6
root@proxy root# rpm -e squid-2.5STABLE6
Installasi semua paket squid :
root@proxy download# tar xzf malloc.tar.gz
root@proxy download# cd malloc
root@proxy malloc# vi Makefile
—-semula—–
# Use this on System V.
#CPPFLAGS = -DUSG
—————
diubah —
—-menjadi—–
# Use this on System V.
CPPFLAGS = -DUSG
—————
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 :
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 :
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.
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 :
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.
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).
maximum_object_size 128 MB
maximum_object_size_in_memory 32 KB
Jika memori 512 MB atau lebih besar silahkan cache diperbesar.
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.
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)
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.
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.
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.
memory_pools off
Penting utk relasi dg sibling dg mengukur respons-nya via ICP dan ICMP.
icp_hit_stale on
query_icmp on
Penting utk meningkatkan refresh pattern lebih lanjut.
reload_into_ims on
pipeline_prefetch on
vary_ignore_expire on
Sekali lagi Squid diperlukan utk mengambil yg jaraknya jauh, jarak dekat langsung saja
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
#!/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:
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):
/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 :
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)

Tidak ada komentar:

Posting Komentar