Squid High Performance : Setidaknya untuk Aku :)

Posted on

Farm Server

Udah beberapa hari ini otak atik trial and error untuk mencari settingan terbaik untuk squid proxy server ku di dalam Box FreeBSD dengan jumlah user dibelakangnya… em… mungkin ratusan client πŸ˜€

Begenilah namanya juga orang yang belajar selalu harus banyak trial and error untuk meng-uji hasil oprekannya… :p untuk dokumentasi menginstall squid di FreeBSD kayaknya gak ada aku buat coz tau sendirilah FreeBSD cantiknya gimana… bila bersanding dengan Ports-nya…

Sebenarnya ini jauh dari sempurna… butuh waktu dan referensi lagi untuk meng-explore-nya lagi agar lebih bisa dikatakan high performance. Aku seh udah cukup dengan settingan apa yang aku dapatkan sekarang… mungkin kedepanya sejalan dengan waktu dapat dikembangkan lagi agar kinerjanya lebih baik lagi tentunya…

Inilah yang aku gunakan untuk Box Proxy BSD-ku :

# ============================================== #
# NETWORK OPTIONS
# ============================================== #
http_port 3128 transparent
icp_port 3130
snmp_port 3401
# ============================================== #
# OPTIONS WHICH AFFECT THE NEIGHBOUR SELECTION ALGORITHM
# ============================================== #
dead_peer_timeout 30 seconds
mcast_icp_query_timeout 10
log_icp_queries on
connect_timeout 2 minutes
peer_connect_timeout 30 seconds
request_timeout 30 seconds
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
no_cache deny QUERY
# ============================================== #
# OPTIONS WHICH AFFECT THE CACHE SIZE
# ============================================== #
cache_mem 8 MB
cache_swap_low 90
cache_swap_high 95
maximum_object_size 4096 KB
maximum_object_size_in_memory 8 KB
ipcache_size 1024
ipcache_low 90
ipcache_high 95
fqdncache_size 1024
cache_replacement_policy heap GDSF
memory_replacement_policy heap GDSF
# =============================================== #
# LOGFILE PATHNAMES AND CACHE DIRECTORIES
# =============================================== #
cache_dir diskd /cache1 12600 29 256 Q1=64 Q2=72
cache_dir diskd /cache2 12600 29 256 Q1=64 Q2=72
cache_dir diskd /cache3 12600 29 256Β  Q1=64 Q2=72
cache_dir diskd /cache4 12600 29 256 Q1=64 Q2=72
cache_access_log /var/log/squid/access.log
cache_log /var/log/squid/cache.log
cache_store_log /dev/null
mime_table /usr/local/etc/squid/mime.conf
# =============================================== #
# HTTPD-ACCELERATOR OPTIONS
# =============================================== #
log_ip_on_direct on
dns_nameservers 202.134.0.155 202.134.1.10 203.130.209.242 202.134.2.5
# =============================================== #
# MISCELLANEOUS
# =============================================== #
logfile_rotate 7
digest_generation on
digest_bits_per_entry 10
digest_rebuild_period 30 minute
digest_rewrite_period 30 minute
digest_swapout_chunk_size 6000 bytes
client_persistent_connections on
server_persistent_connections on
pipeline_prefetch on
store_dir_select_algorithm round-robin
nonhierarchical_direct off
prefer_direct off
# =============================================== #
# ADMINISTRATIVE PARAMETERS
# =============================================== #
cache_mgr [email protected]
cachemgr_passwd 123456 all
cache_effective_user nobody
cache_effective_group nobody
visible_hostname proxy.dodol.net
# =============================================== #
# OPTIONS FOR EXTERNAL SUPPORT PROGRAMS
# ============================================== #
unlinkd_program /usr/local/libexec/squid/unlinkd
pinger_program /usr/local/libexec/squid/pinger
# ============================================== #
# ACCESS CONTROLS
# ============================================== #
acl all src 0/0
acl localnet src 192.168.1.0/24
acl localhost src 127.0.0.0/8
# ============================================== #
# ACL Different access
# ============================================== #
acl SSL_ports port 443 563
acl Safe_ports port 21 80 280 448 591 777 443 563 808 70 210 4190-65535
acl CONNECT method CONNECT
acl purgemethod method purge
acl snmp snmp_community snmpcomunity
acl manager proto cache_object
# ============================================== #
# BLOCKING CONTENTS
# ============================================== #
acl bad url_regex “/usr/local/etc/squid/blocker/bad.acl”
acl mikocok urlpath_regex msdownload/update/v3-19990518/cabpool
http_access deny bad
http_access deny mikocok
# ============================================== #
# Access Denied
# ============================================== #
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
# ============================================== #
# Internet Access
# ============================================== #
http_access allow manager !localhost
http_access allow purgemethod localhost
http_access allow localnet
http_access deny all
# ============================================== #
# htttp access user
# SNMP – MRTG Setting
# ============================================== #
snmp_access allow snmp localhost
snmp_access deny all
# ============================================== #
# TRAFFIC SHAPPING
# ============================================== #
acl lokal url_regex -i 192.168.1.
acl lambat url_regex -i “/usr/local/etc/squid/blocker/limit.txt”
## Delay Pool
# -1/-1 >> no limits untuk local traffic.
delay_pools 2
delay_class 1 2
delay_parameters 1 -1/-1 -1/-1
delay_access 1 allow lokal
delay_access 1 deny all
# Bandwidth 2,8 Mbps >> (((2,8*1024)*1024)/8) >> 367001.6 B/s
# Alokasi 367 KB/s >> network, 3 KB/s >> download lambat
delay_class 2 2
delay_parameters 2 367000/367000 3000/367000
delay_access 2 allow lambat
delay_access 2 deny all
# Dilarang Download file lebih dari 700 MB
reply_body_max_size 700000000 allow all
# Dilarang Upload file lebih dari 5 MB
request_body_max_size 5 MB
# =============================================== #

Aku sendiri cukup sampai situ aza konfigurasi untuk squid proxy server ku… Alhamdulillah Traffic udah bisa dikendalikan dengan normal… πŸ™‚

Untuk Isi file-file bad.acl dan file limit.txt dapat di edit dan disesuaikan dengan kondisi dan situasi…
Disini Aku sendiri membuat file bad.acl yang berisi site content yang akan aku block disisi user/client, ambil contoh seperti site-site porno, content/extensi tertentu, banner-banner, … pokoknya apa lah yang dikira terlarang atau tidak boleh di akses oleh user/client.

Contoh isi file bad.acl bisa seperti ini :

^http://www\.submit-it.*
^http://ads01.*
^http://www\.eads.*
^http://ads\.
^http://ad\.
^http://ads02\.
^http://adaver.*\.
^http://adforce\.
/images/[Aa][Dd]/
/reklame/
/[Bb]anners/
17tahun
miyabi
sex
\.3[Gg][Pp]$

Dan lain-lain lah… disesuaikan saja…

Dan untuk file kedua, πŸ™‚ maksutnya file limit.txt adalah file yang berisi daftar extensi untuk file-file yang dibatasi downloadnya. Jadi, apabila user/client mendownload file yang extensinya masuk dalam daftar didalam file limit.txt makan speed atau kecepatan download user akan dibatasi dengan menggunakan delay pool. πŸ˜€

Contoh isi dari file limit.txt :

\.[Gg][Zz]$
\.[Rr][Pp][Mm]$
\.[Zz][Ii][Pp]$
\.[Rr][Aa][Rr]$
\.[Mm][Pp][Ee]$
\.[Qq][Tt]$
\.[Rr][Aa][Mm]$
\.[Ii][Ss][Oo]$
\.[Rr][Aa][Ww]$
\.[Ww][Aa[Vv]$
\.[Dd][Ee][Bb]$
\.[Cc][Aa][Bb]$
\.[Rr][Mm]$
\.[Mm][Pp]$
\.[Mm][Pp][Gg]$
\.[Mm][Pp][Ee][Gg]$
\.[Ww][Mm][Vv]$
\.[Ww][Mm][Aa]$
\.[Mm][Oo][Vv]$
\.[Aa][Vv][Ii]$
\.[Mm][Pp][Gg]$
\.[Mm][Pp][Ee][Gg]$
\.[Ee][Xx][Ee]$
\.[Mm][Pp]3$
\.[Mm][Pp]4$
\.[Vv][Qq][Ff]$
\.[Ee][Xx][Ee]$
\.[Tt][Aa][Rr].[Gg][Zz]$
\.[Bb][Zz]2$

Selebihnya silahkan disesuaikan ! πŸ˜€

Kenapa dibatasi ? Ini terkait dengan stabilitas dan normalisasi penggunaan bandwidth… agar user/client tidak se-enaknya menggunaakn bandwidth secara penuh yang akan berakibar tergangunya interkoneksi internet user yang lain.

Sebenarnya ini bertujuan untuk mendidik user/client untuk dapat menggunakan bandwidth mereka dengan bijak. Maklumlah di Indonesia bandwidth masih merupakan barang mahal… dan tidak semua orang dapat menikmatinya…

20 comments

  1. mas gmn caranya agar bs batasin donlod berdasarkan waktu?aq ingin batasin donlod dari jam 12 siang-11mlm….lwt dr jam itu bebas donlod.mohon bantuannya.

  2. Coba ini, dibatesin sampe 5KB/s :

    acl LTIME time SMTWHFA 12:00-23:00
    acl lambat url_regex -i “/usr/local/etc/squid/blocker/limit.txt”

    delay_pools 1

    delay_class 1 1
    delay_parameters 1 5000/5000
    delay_access 1 allow download LTIME
    delay_access 1 deny all

  3. Mas Aditya spec hardware nya seperti apa ya?
    Terus FreeBSD nya pake versi berapa?

    Thank’s

  4. assalamualikum wr. wb
    mas adit
    saya ada problem dikit neh…

    diwarnet saya pake server ubuntu 8.04, squid udah berjalan dengan baik, untuk membatasi download udah pake delay pool n berhasil..

    ada masalah pada saat client melalukan upload, di ping diserver mencapai 6000-8000ms (browsing langsung macet) padahal cuma upload sebesar 1MB, saya udah pake manajemen bandwith dengan HTB juga masih tembus pada saat upload,, mgkin ada perintah di squid untuk memperlambat upload
    mohon saran….tanks

  5. aku pake freebsd7 stable.Bagaimana caranya mengetahui versi dari squid tersebut . Dan dalam hal mengconfigurasi squid tersebut harus di install dulu ???
    terus untuk penulisan script diatas di directory mana ??
    mohon penjelasannya !!!

  6. untuk tau versi squid apa yang ada dalam ports default freebsd, silahkan cek :

    #whereis squid
    squid: /usr/ports/www/squid
    # cd /usr/ports/www/squid
    # cat distinfo

    Yups, untuk dapat mengkonfigurasi squid tentu anda harus menginstallnya terlebih dahulu… πŸ™‚

    jika anda mengisntallnya melalui ports biasnya directory konfigurasi squid berada pada /usr/local/etc/squid

  7. Mas Adit
    saya rencana mo setting lan, topologi spt ini
    inet — monowall — switch — client
    l—— proxy
    net sudah bisa ke klien, cuma setting transparant proxy nya
    di gui monowall belum ketemu, aku belum ngerti banget di command
    keinginan topologi itu mau pk captive portal monowal tapi di client gak usah setting apa2
    dapet link ini http://m0n0.ch/wall/list/showmsg.php?id=301/52 <– setting di inbound atau outbound nat ? bingung ….
    mohon pencerahan dan bantuannya
    boleh minta ym nya utk tanya2
    terima kasih

  8. inet β€” monowall β€” switch β€” client
    ………………………………..lβ€”β€” proxy
    atau
    inet — proxy — monowall — switch — client

    topologi spt itu menurut mas adit gimana ?
    mungkin ada topologi yg lebih bagusan mnrt mas adit

    terimakasih

  9. Aslm…mas aditya….lam kenal ne….
    aq baru aja terjun pengen kenal ma freeBSD….
    aq dah coba2 slama ne buat proxy+webproxy+blokir situs xxx tp always g jln…..sama skali….
    mohon pencerahanya dari awal cara buat smpe akhir….

    berikut spek PC dll….

    P4 3GH RAM 1GB HD 80Gb
    ISP dari SAPIDI 2 jalur

    untuk pengaturan bandwidth + routingnya aq pke MIKETEK, trus untuk blokir + webproxynya aq pengennya di di direc ke PC lain dengan OS freeBSD 7………

  10. mas aditya,
    ni aku baru kenal sama freebsd
    mohon dikasih tahu mengenai gimana cara buat proxy sekaligus proxy supaya maksimal
    untuk firewallnya pake pf
    kalo bisa lengkap ya πŸ™‚
    kalo terlalu banyak kirim ke email-ku aja
    thanks sebelumnya

  11. aditya,
    pohon pertanyaan sedikit. saya telah meiginstall squid proxy 2.6 stable ke dalam centos v5.4 saya. proxy tersebut berjalan sempurna tetapi mempunyai sedikit problem dimana delay pool saya seperti tidak berjaya untuk defined acl saya (delay_access 1 allow perdanet)
    tetapi jika saya menukar kepada (delay_access 1 allow all) ia kelihatan berjaya sepertimana yang saya mahukan.

    Ini ialah config squid.conf saya:

    http_port 3128 transparent
    hierarchy_stoplist cgi-bin ?

    acl QUERY urlpath_regex cgi-bin ?
    cache deny QUERY

    acl apache rep_header Server ^Apache
    broken_vary_encoding allow apache
    cache_mem 256 MB
    maximum_object_size 4096 KB
    cache_dir ufs /var/spool/squid 1024 16 256
    access_log /var/log/squid/access.log squid
    cache_log /var/log/squid/cache.log
    refresh_pattern ^ftp: 1440 20% 10080
    refresh_pattern ^gopher: 1440 0% 1440
    refresh_pattern . 0 20% 4320

    acl localhost src 127.0.0.1/255.255.255.255
    acl perdanet src 172.16.5.0/255.255.255.0
    acl all src 0.0.0.0/0.0.0.0
    acl manager proto cache_object
    acl to_localhost dst 127.0.0.0/8

    acl SSL_ports port 443
    acl Safe_ports port 80 # http
    acl Safe_ports port 21 # ftp
    acl Safe_ports port 443 # https
    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

    http_access allow manager localhost
    http_access deny manager
    http_access deny !Safe_ports
    http_access deny CONNECT !SSL_ports
    acl Badsites url_regex “/usr/local/etc/restricted-sites.squid”
    http_access deny Badsites
    http_access allow localhost
    http_access allow perdanet
    http_access deny all

    http_reply_access allow all
    cache_effective_user squid
    cache_effective_group squid
    visible_hostname localhost
    store_avg_object_size 13 KB

    # Delay Pools
    delay_pools 1
    delay_class 1 3
    delay_access 1 allow perdanet
    delay_access 1 deny all
    delay_parameters 1 64000/64000 5000/12000 5005/12000

    delay_initial_bucket_level 50
    coredump_dir /var/spool/squid

Leave a Reply to Didit Cancel reply

Your email address will not be published. Required fields are marked *