Thursday, December 9, 2010

Konfigurasi Squid 3 di Ubuntu

Buat yang mau tau cara compilenya silahkan kemari. oke langsung saja ikuti langkah-langkah berikut:
 

Rubah Owner Direktori cache nya, dalam hal ini saya memakai partisi /cache yang sebelumnya (waktu install) sudah dipersiapkan. buat yang belom bikin partisi cache tinggal disesuaikan saja :P

sudo chown -R proxy:proxy /cache
Edit file /etc/squid/squid.conf dengan editor masing-masing.
Note: sesuaikan konfigurasi OPTIONS WHICH AFFECT THE CACHE SIZE dan LOGFILE PATHNAMES AND CACHE DIRECTORIES dengan keadaan di kompi anda masing-masing.


sudo gedit /etc/squid/squid.conf


#######################
# HIGH PERFORMANCE SQUID 3.1.9
# Config date : 02 Desember 2010
#######################

# ACCESS CONTROLS
# —————

acl QUERY urlpath_regex -i cgi-bin \? \.php$ \.asp$ \.shtml$ \.cfm$ \.cfml$ \.phtml$ \.php3$ localhost
acl all src
acl localnet src 10.0.0.0/8
acl localnet src 172.16.0.0/12
acl localnet src 192.168.0.0/16
acl localhost src 127.0.0.1/32
acl safeports port 21 70 80 210 280 443 488 563 591 631 777 901 81 3128 1025-65535
acl sslports port 443 563 81
acl manager proto cache_object
acl purge method PURGE
acl connect method CONNECT
acl ym dstdomain .messenger.yahoo.com .psq.yahoo.com
acl ym dstdomain .us.il.yimg.com .msg.yahoo.com .pager.yahoo.com
acl ym dstdomain .rareedge.com .ytunnelpro.com .chat.yahoo.com
acl ym dstdomain .voice.yahoo.com
acl ymregex url_regex yupdater.yim ymsgr myspaceim

http_access deny ym
http_access deny ymregex
http_access allow manager localhost
http_access deny manager
http_access allow purge localhost
http_access deny purge
http_access deny !safeports
http_access deny CONNECT !sslports
http_access allow localhost
http_access allow localnet
http_access deny all

# NETWORK OPTIONS
# —————

http_port 3128

# OPTIONS WHICH AFFECT THE CACHE SIZE
# ———————————–

cache_mem 8 MB
maximum_object_size_in_memory 32 KB
memory_replacement_policy heap GDSF
cache_replacement_policy heap LFUDA
cache_dir aufs /cache 6000 14 256
maximum_object_size 128000 KB
cache_swap_low 95
cache_swap_high 99

# LOGFILE PATHNAMES AND CACHE DIRECTORIES
# —————————————

access_log none
cache_log /cache/cache.log
#cache_log /dev/null
cache_store_log none
logfile_rotate 5
log_icp_queries off

# OPTIONS FOR TUNING THE CACHE
# —————————-

cache deny QUERY
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i \.(gif|png|jp?g|ico|bmp|tiff?)$ 10080 95% 43200 override-expire override-lastmod reload-into-ims ignore-no-cache ignore-private
refresh_pattern -i \.(rpm|cab|deb|exe|msi|msu|zip|tar|gz|tgz|rar|bin|7z|doc?|xls?|ppt?|pdf|nth|psd|sis)$ 10080 90% 43200 override-expire override-lastmod reload-into-ims ignore-no-cache ignore-private
refresh_pattern -i \.(avi|iso|wav|mid|mp?|mpeg|mov|3gp|wm?|swf|flv|x-flv|axd)$ 43200 95% 432000 override-expire override-lastmod reload-into-ims ignore-no-cache ignore-private
refresh_pattern -i \.(html|htm|css|js)$ 1440 75% 40320
refresh_pattern -i \.index.(html|htm)$ 0 75% 10080
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 1440 90% 10080

quick_abort_min 0 KB
quick_abort_max 0 KB
quick_abort_pct 100
store_avg_object_size 13 KB

# HTTP OPTIONS
# ————
vary_ignore_expire on

# ANONIMITY OPTIONS
# —————–

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

# TIMEOUTS
# ——–

forward_timeout 240 second
connect_timeout 30 second
peer_connect_timeout 5 second
read_timeout 600 second
request_timeout 60 second
shutdown_lifetime 10 second

# ADMINISTRATIVE PARAMETERS
# ————————-

cache_mgr ninja
cache_effective_user proxy
cache_effective_group proxy
httpd_suppress_version_string on
visible_hostname ninja

# DNS OPTIONS
# ———–

dns_timeout 10 seconds
dns_nameservers 180.131.144.144 180.131.144.145

# MISCELLANEOUS
# ————-

memory_pools off
client_db off
reload_into_ims on
coredump_dir /cache
pipeline_prefetch on
offline_mode off

### END CONFIGURATION ###



kemudian simpan dan keluar. eksekusi perintah berikut di terminal


sudo squid -k parse

kalo ada warning seperti berikut abaikan aja:

Processing Configuration File: /etc/squid/squid.conf (depth 0)
WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP
WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP
WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP
WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP
WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP


Bila tidak ada error, eksekusi perintah berikut.

sudo squid -z
 

4. Buat script init.d agar squid bisa dijalankan:

sudo gedit /etc/init.d/squid
 

copas script berikut kedalam file /etc/init.d/squid


#! /bin/sh
#
# squid3        Startup script for the SQUID HTTP proxy-cache.
#
# Version:    @(#)squid3.rc  1.0  07-Jul-2006  luigi@debian.org
#
### BEGIN INIT INFO
# Provides:          squid3
# Required-Start:    $network $remote_fs $syslog
# Required-Stop:     $network $remote_fs $syslog
# Should-Start:      $named
# Should-Stop:       $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Squid HTTP Proxy version 3.1.9
### END INIT INFO

NAME=squid
DESC="Squid HTTP Proxy 3.1.9"
DAEMON=/usr/sbin/squid
PIDFILE=/var/run/$NAME.pid
CONFIG=/etc/squid/squid.conf
SQUID_ARGS="-D -YC -f $CONFIG"

[ ! -f /etc/default/squid ] || . /etc/default/squid

. /lib/lsb/init-functions

PATH=/bin:/usr/bin:/sbin:/usr/sbin

[ -x $DAEMON ] || exit 0


find_cache_dir () {
        w="     " # space tab
        res=`sed -ne '
                s/^'$1'['"$w"']\+[^'"$w"']\+['"$w"']\+\([^'"$w"']\+\).*$/\1/p;
                t end;
                d;
                :end q' < $CONFIG`
        [ -n "$res" ] || res=$2
        echo "$res"
}

find_cache_type () {
    w="     " # space tab
    res=`sed -ne '
        s/^'$1'['"$w"']\+\([^'"$w"']\+\).*$/\1/p;
        t end;
        d;
        :end q' < $CONFIG`
    [ -n "$res" ] || res=$2
    echo "$res"
}

start () {
    cache_dir=`find_cache_dir cache_dir /var/spool/squid3`
    cache_type=`find_cache_type cache_dir ufs`

    #
    # Create spool dirs if they don't exist.
    #
    if [ "$cache_type" = "coss" -a -d "$cache_dir" -a ! -f "$cache_dir/stripe" ] || [ "$cache_type" != "coss" -a -d "$cache_dir" -a ! -d "$cache_dir/00" ]
    then
        log_warning_msg "Creating $DESC cache structure"
        $DAEMON -z
    fi

    umask 027
    ulimit -n 1024
    cd $cache_dir
    start-stop-daemon --quiet --start \
        --pidfile $PIDFILE \
        --exec $DAEMON -- $SQUID_ARGS < /dev/null
    return $?
}

stop () {
    PID=`cat $PIDFILE 2>/dev/null`
    start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON
    #
    #    Now we have to wait until squid has _really_ stopped.
    #
    sleep 2
    if test -n "$PID" && kill -0 $PID 2>/dev/null
    then
        log_action_begin_msg " Waiting"
        cnt=0
        while kill -0 $PID 2>/dev/null
        do
            cnt=`expr $cnt + 1`
            if [ $cnt -gt 24 ]
            then
                log_action_end_msg 1
                return 1
            fi
            sleep 5
            log_action_cont_msg ""
        done
        log_action_end_msg 0
        return 0
    else
        return 0
    fi
}

case "$1" in
    start)
    log_daemon_msg "Starting $DESC" "$NAME"
    if start ; then
        log_end_msg $?
    else
        log_end_msg $?
    fi
    ;;
    stop)
    log_daemon_msg "Stopping $DESC" "$NAME"
    if stop ; then
        log_end_msg $?
    else
        log_end_msg $?
    fi
    ;;
    reload|force-reload)
    log_action_msg "Reloading $DESC configuration files"
    start-stop-daemon --stop --signal 1 \
        --pidfile $PIDFILE --quiet --exec $DAEMON
    log_action_end_msg 0
    ;;
    restart)
    log_daemon_msg "Restarting $DESC" "$NAME"
    stop
    if start ; then
        log_end_msg $?
    else
        log_end_msg $?
    fi
    ;;
    *)
    echo "Usage: /etc/init.d/$NAME {start|stop|reload|force-reload|restart}"
    exit 3
    ;;
esac

exit 0



kemudian di chmod agar bisa dieksekusi:


sudo chmod +x /etc/init.d/squid

dilanjutkan dengan merestart squidnya:
 

sudo /etc/init.d/squid restart

terakhir, set squid agar aktif saat boot

sudo update-rc.d squid defaults

langkah terakhir setting browser kesayangan anda, saya kasih contoh firefox

buka FF -> edit -> preferences -> advanced

di tab advanced masuk ke network

setel offline storage ke 0 lalu clear now

masuk ke connection -> setting

pilih manual proxy configuration, di HTTP Proxy setel 127.0.0.1 port 3128.


untuk memudahkan koneksi messenger lebih baik jangan setting messenger tuk melewati port squid jadi silahkan di cek bener2 n pastikan pilihan ke no proxy di messenger.



Referensi: http://rhesa.itvps.org/2010/08/konfigurasi-squid-3-di-ubuntu/