Sunday, October 25, 2009

FreeBSD 6.2 Proxy Squid server

Tulisan ini merupakan hutang dari postingan terdahulu. Sebenarnya langkah-langkah instalasinya hilang dari memory otak. Hanya saja kemaren ingat lagi setelah disodori komputer dengan dual processor P3 733Mhz dan RAM 512Mb plus 1 scsi HDD 18 Gb.
Komputer ini built-up dengan merk HP series Netserver E800

Tak ada hambatan sama sekali saat komputer di set untuk booting awal lewat CD. Langkah biasa saja yaitu masuk ke BIOS dengan pencet tombol F2 dan pilih boot order.
Hanya saja, Netserver ini agak lama untuk boot karena dia harus meload dulu driver scsi-nya dan RAM checker. butuh sekitar 3 menit untuk benar-2 masuk dan boot lewat CD.

Oke..untuk instalasi pilih saja opsi kern-developer karena nantinya kita akan mendownload langsung sourcenya dan mengcompilenya dengan berbagai opsi dibawah.

Squid
Squid merupakan web proxy yang sangat populer dan tentunya sangat berkelas dan digunakan di berbagai institusi baik kecil ataupun perusahaan besar dan tentunya ISP di seluruh dunia. Juga personal seperti saya ini tentunya juga boleh pakai :)
Squid akan meningkatkan kemampuan web browsing dan menghemat bandwidth, juga memiliki Access Control Lists (ACLs) yang sangat kaya yang dapat dikonfigurasi sebagai filter yang powerfull dan juga bisa sebagai firewall.

, saat ini dibangun dari sumbangan para sukarelawan. Tim hanya terdiri dari sedikit orang tetapi mereka sangat berbakat dan tentunya juga para developer program yang profesional.

Untuk informasi lebih lanjut sila ikuti URL berikut:

http://www.-cache.org/Intro/helping.dyn

Instalasi manual ini menggunakan -2.6.STABLE18. Tetapi tentu saja dapat digunakan untuk versi lainnya dan juga tidak hanya untuk karena dapat digunakan untuk keluarga Linux ataupun BSD. Dan dengan sedikit modifikasi bisa dipakai untuk Solaris dengan mengganti ‘make’ menjadi ‘gmake’ dan tentu saja pastikan ‘/usr/sfw/bin’ ada di PATH.

Berikut asumsi yang digunakan di server;

2 cache partisi /cache0 dan /cache1 dengan ukuran masing-masing 6 GB dan dipartisi saat instalasi OS.
User dan Group telah dibikin di OS
Incoming TCP connections di Port 3128

How-To ini menerangkan bagaimana jalan sebagai di di -6.2/Linux untuk melayani ribuan user dan dapat juga dikombinasikan dengan tanpa menjalankan web proxy . NAT yang dipakai di menggunakan DST-NAT dan cukup 2 LAN card disisi (1 WAN dan 1 LAN).

Instalasi
Oke kita mulai instalasi squidnya.

(1.) Karena kita mau langsung server FreeBSD yang unduh squidnya maka package ‘wget’ harus ada. Dan tentunya konfigurasi jaringan sudah oke dan telah terhubung ke internet.
cd /usr/ports/ftp/wget < < href="http://simplyeko.com/tag/freebsd">FreeBSD
make install << href="http://simplyeko.com/tag/freebsd">FreeBSD untuk mengunduh wget langsung dari repository

Ketikkan perintah diatas secara berurutan dan tunggu sampai selesai.

(2) Download di /usr/local/src

cd /usr/local/src
wget http://www.-cache.org/Versions/v2/2.6/-2.6.STABLE18.tar.gz

(2.) Dekompress squidnya

tar zxvf -2.6.STABLE18.tar.gz

(3.) Konfigurasi dengan parameter berikut

–bindir=/usr/local/sbin \
–sysconfdir=/usr/local/etc/ \
–datadir=/usr/local/etc/ \
–libexecdir=/usr/local/libexec/ \
–localstatedir=/usr/local/ \
–enable-removal-policies=heap,lru \
–enable-storeio=diskd,aufs,coss,ufs,null \
–enable-time-hack \
–with-large-files \
–enable-large-cache-files \
–prefix=/usr/local \
–disable-ident-lookups \
–enable-cache-digests \
–enable-underscores \
–enable-kill-parent-hack \
–enable-follow-x-forwarded-for

(4.) Jika semua berjalan dengan baik -tanpa error-, jalankan

make all
make install

(5.) Sekarang kita tune konfigurasi .conf sesuai kebutuhan

cd /usr/local/etc/
mv .conf .default.conf

(6.) Gunakan .conf berikut

############## Start of .conf ###########

cache_effective_user
cache_effective_group

#hosts_file /etc/hosts

#Only if you have other proxies running and want to use them as sibling peers
#Uncomment them
#cache_peer proxy1.example.com sibling 3128 3130 proxy-only
#cache_peer proxy2.example.com sibling 3128 3130 proxy-only
#cache_peer proxy6.example.com sibling 3128 3130 proxy-only

#Remove 127.0.0.1 if you don’t have a local caching name server
dns_nameservers 127.0.0.1 IP.OF.ISP.DNSSERVER

#debug_options ALL,1 33,2 28,9

acl all src 0.0.0.0/0.0.0.0

#offline_mode off

icp_query_timeout 1000

high_memory_warning 500 MB

#If you have 2 or more different links, use them for load-balancing
#tcp_outgoing_address IP.Address.2nd.Router

visible_hostname proxy.example.com

httpd_suppress_version_string on

cache_mem 64 MB

#cache_replacement_policy heap LFUDA
cache_replacement_policy heap GDSF
memory_replacement_policy heap GDSF

cache_swap_low 90
cache_swap_high 95

maximum_object_size 131072 KB

########New test — Default is 8
maximum_object_size_in_memory 64 KB

#minimum_object_size 1 KB
#store_avg_object_size 20 KB

tcp_recv_bufsize 65535 bytes

ipcache_size 8192

fqdncache_size 8192

##If this proxy is also your gateway and if you want to block MSN messenger
##Uncomment the ACLs below

#acl msn-type req_mime_type -i ^application/x-msn-messenger$
#acl msn-type req_mime_type -i ^application/x-msnmsgrp2p
#http_access deny msn-type

#acl msnmessenger url_regex -i gateway.dll
#http_access deny msnmessenger
#acl msn req_mime_type -i ^application/x-msn-messenger
#http_access deny all msn

acl msnmess url_regex http://207.46.111.55/gateway/gateway.dll?
deny_info TCP_RESET msnmess
http_access deny msnmess

#forwarded_for on
#request_header_max_size 24 KB
#negative_dns_ttl 1 minutes
#positive_dns_ttl 1 hours
#negative_dns_ttl 60 seconds
#connect_timeout 60 seconds
#request_timeout 60 seconds
#pconn_timeout 30 seconds
high_page_fault_warning 10
high_response_time_warning 2000
client_persistent_connections off
server_persistent_connections on
half_closed_clients off

#If you need the high performace COSS storage scheme
#cache_dir coss /cache1//coss 9216 max-size=131072 max-stripe-waste=16384 block-size=1024
#cache_dir coss /cache2//coss 9216 max-size=131072 max-stripe-waste=16384 block-size=1024

#Diskd storage scehme
cache_dir diskd /cache0 6144 16 256 Q1=72 Q2=64
cache_dir diskd /cache1 6144 16 256 Q1=72 Q2=64

#Used for COSS only
#cache_swap_log /var//%s

log_icp_queries off
cache_store_log none
cache_access_log /var/log//access.log
cache_log /var/log//cache.log

emulate_httpd_log on

acl spammers dstdomain .maxonlinejob.com .max-online.biz .maxjob.info
deny_info TCP_RESET spammers
http_access deny spammers

ftp_user ftpuser@example.com
cache_mgr squidadmin@example.com

#Block some comme Microsoft bugs
acl msnbug url_regex http://msgr.dlservice.microsoft.com/download/1/A/4/1A4FEB1A-18E0-423A-B898-F697402E4F7F/I nstall_Messenger.exe
deny_info TCP_RESET msnbug
http_access deny msnbug

acl msnbug2 url_regex http://msgr.dlservice.microsoft.com/download/4/b/c/4bc83bb2-18dd-486f-943f-332a9b3e01dc/Install_MSN_Messenger_DL.exe
deny_info TCP_RESET msnbug2
http_access deny msnbug2

#No cache for the following sites
acl newssites dstdomain .cnn.com .bbcnews.com
no_cache deny newssites

refresh_pattern windowsupdate.com/.*\.(cab|exe) 4320 100% 43200 reload-into-ims
refresh_pattern update.microsoft.com/.*\.(cab|exe) 4320 100% 43200 reload-into-ims
refresh_pattern download.microsoft.com/.*\.(cab|exe) 4320 100% 43200 reload-into-ims

#Try to cache some google Earth stuff
acl QUERY urlpath_regex cgi-bin \? intranet
acl forcecache url_regex -i kh.google keyhole.com
no_cache allow forcecache
no_cache deny QUERY

#Don’t cache dynamic content
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
no_cache deny QUERY

refresh_pattern -i kh.google 1440 20% 10080 override-expire override-lastmod reload-into-ims ignore-reload
refresh_pattern -i keyhole.com 1440 20% 10080 override-expire override-lastmod reload-into-ims ignore-reload

refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320

#Only if you want your box to cache aggressively, not recommended

#refresh_pattern -i \.gif$ 600 50% 10080
#refresh_pattern -i \.jpe?g$ 600 50% 10080
#refresh_pattern -i \.tif?f$ 600 50% 10080
#refresh_pattern -i \.png$ 600 50% 10080
#refresh_pattern -i \.mov$ 600 50% 10080
#refresh_pattern -i \.qt$ 600 50% 10080
#refresh_pattern -i \.avi$ 600 50% 10080
#refresh_pattern -i \.mpe?g$ 600 50% 10080
#refresh_pattern -i \.wav$ 600 50% 10080
#refresh_pattern -i \.au$ 600 50% 10080
#refresh_pattern -i \.aif?f$ 600 50% 10080
#refresh_pattern -i \.ps$ 360 30% 10080
#refresh_pattern -i \.pdf$ 360 30% 10080
#refresh_pattern -i \.gz$ 360 30% 10080
#refresh_pattern -i \.Z$ 360 30% 10080
#refresh_pattern -i \.zip$ 360 30% 10080
#refresh_pattern . 180 50% 10180

#Configure downloading even after aborted requests.
quick_abort_min 0 KB
quick_abort_max 0 KB
#quick_abort_pct 99

negative_dns_ttl 2 minutes

acl mynetwork src 192.168.0.0/24 172.16.0.0/24 10.0.0.0/24

acl nimda urlpath_regex .*/winnt/system32/cmd.exe.* .*/MSADC/root.exe..c.dir$ .*/scripts/root.exe..c.dir$
acl Newvirus urlpath_regex .*/Cgi-bin/!Vip.exe.* .*/LE/isapitest.dll.*
acl BadURL urlpath_regex -i cmd.exe
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl SSL_ports port 443 563 2082 2083 2086 2087 2093 2095 2096
acl Safe_ports port 80 21 443 563 70 210 8000 11999 2082 2083 2086 2087 2095 2096 8082 8090
acl CONNECT method CONNECT
acl worm dst 63.251.5.47 65.74.168.210
acl worm1 dstdomain kyamzaa.virtualave.net/com.exe
acl worm2 dstdomain kyamazza.virtualave.net/dos.exe

acl VIRUS urlpath_regex winnt/system32/cmd.exe?
acl VIRUS urlpath_regex ^/osa..gif
acl VIRUS urlpath_regex ^/./fils.php
acl VIRUS urlpath_regex ^/./999.jpg
acl VIRUS urlpath_regex ^/w.php
acl YAHOOATTACK urlpath_regex akamai.*yahoo.*config/login
acl INADDR_ANY dst 0.0.0.0/32
acl IpAddrProbeUA browser ^Mozilla/4.0.\(compatible;.MSIE.5.5;.Windows.98\)$
acl IpAddrProbeURL url_regex //[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/$

acl codered url_regex \/default\.ida$
http_access deny codered

acl gator_url url_regex \.gator.com
acl gator_domain_start dstdomain gator.com
http_access deny gator_url
http_access deny gator_domain_start

acl brazvir url_regex http://www.instituto.com.br/attackDoS.php
http_access deny brazvir

acl worm_url url_regex ^http://www.tradeexit.com/link1.html$
acl worm_url url_regex ^http://www.tradeexit.com/link2.html$
acl worm_url url_regex ^http://www.revistaprofashional.com.br/put?
acl worm_url url_regex ^http://www.putassp.com/put?
http_access deny worm_url

#Block uncessary microsoft updates
acl microsoft_url_1 urlpath_regex msdownload/update/v3-19990518/cabpool
http_access deny microsoft_url_1

###################
##virus
#acl mblock url_regex -i musicindiaonline.com

acl dangurl urlpath_regex -i \.id[aq]\?.{100,} # CodeRED
acl dangurl urlpath_regex -i /readme\.(eml|nws|exe) # NIMDA

#Remove transparent if you don’t want to run transparently
http_port 3128 transparent

http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access deny BadURL
http_access deny nimda
http_access deny Newvirus
deny_info TCP_RESET worm
http_access deny worm
http_access deny worm1
http_access deny worm2
http_access deny Codered
http_access allow mynetwork

http_access deny IpAddrProbeUA IpAddrProbeURL
deny_info TCP_RESET IpAddrProbeURL
acl OriginsThatComplainOfAbuse dstdomain .fencing101.com
http_access deny OriginsThatComplainOfAbuse
deny_info TCP_RESET OriginsThatComplainOfAbuse
acl soedirman dstdomain soedirman.gudangupload.com
http_access deny soedirman
http_access deny VIRUS
http_access deny YAHOOATTACK
http_access deny INADDR_ANY

acl PURGE method PURGE
http_access allow PURGE localhost
http_access deny PURGE

deny_info TCP_RESET all
http_access deny all

icp_access allow mynetwork
icp_access deny all

miss_access allow all

append_domain .example.com

#Always direct allow to yahoo.com and hotmail.com
acl yahoo dstdomain login.yahoo.com
acl yahoo dstdomain mail.yahoo.com
acl hotmail dstdomain hotmail.com
always_direct allow yahoo
always_direct allow hotmail

ie_refresh on
######## End of .conf ###############

(6.) Initialize direktory cache-nya

/usr/local/sbin/ -z

(7.) Jalankan

/usr/local/sbin/ start

(8.) Pastikan langkah 7 dimasukkan ke /etc/rc.local biar saat boot up langsung menjalankan squidnya.
(9.) Karena ini , maka tak ada yang perlu di set di sisi client. Tinggal belokkan semua request ke port 80 di ke port 3128 proxy server

Kalau semua berjalan dengan oke, silahkan parameter di .conf diutak-atik dengan menambahka delay pool ataupun menghilangkan tanda # di depannya. Jangan lupa untuk menjalankan ‘/usr/local/sbin/ -k reconfigure’ agar menggunakan .conf yang baru di update.


Source : http://simplyeko.com