Anda di halaman 1dari 7

Maintenance Squid Proxy

Server Linux

Panduan ini ditunjukkan bagi user yang sudah familiar dengan linux. Apabila masih baru mengenal maka user
diharap membaca panduan dasar linux pada beberapa link di bawah ini:

1. http://id.wikibooks.org/wiki/Gnu_%28Linux_Untuk_Awam%29/Perintah-perintah_dasar
2. http://yoyok.wordpress.com/2007/07/13/perintah-dasar-linux-dan-sering-dipergunakan/
3. http://www.ubuntu-id.org/doc/edgy/xubuntu/desktopguide/id/linux-basics.html
4. http://www.neoteker.or.id/networking/70-perintah-dasar-linux.pdf

Perintah yang wajib ditulis oleh user dituliskan dalam font bold monospace hasil eksekusi perintah
ditampilkan dalam font normal monospace. Contoh, untuk menampilkan tanggal dengan date

opr@Proxy:$ date
Mon Nov  2 14:57:25 WIT 2009

Perhatian !!!
Hati-hati jika memasukkan command di linux sebagai user root atau super user. Demi keamanan maka hanya
user opr yang bisa menjalankan perintah root. Perintah untuk ini akan didahului oleh perintah sudo. Hindari
masuk ke sistem sebagai root !

Reboot linux
Untuk reboot server linux jalankan perintah ini:

opr@Proxy:~$ sudo /sbin/reboot

Shutdown linux
Untuk shutdown server linux jalankan perintah ini:

opr@Proxy:~$ sudo /sbin/shutdown ­h now

Melihat proses squid yang sedang berjalan


Squid proxy server dijalankan otomatis setiap kali server linux booting. Untuk melihat apakah proses squid
sedang berjalan:

opr@Proxy:~$ sudo /etc/rc.d/rc.squid stat 
squid is running.

Alternatif lain untuk melihat squid yang sedang berjalan:

opr@Proxy:~$ sudo ps aux|grep squid|head ­n 5 
root      2956  0.0  0.0   5872   964 ?        Ss   Oct12   0:00 /usr/local/sbin/squid ­D 
nobody    2958  0.5 10.8 375736 365704 ?       Sl   Oct12 158:50 (squid) ­D 
nobody   31331  0.0  0.0   3552  1484 ?        Ss   Nov01   0:00 /usr/bin/perl /etc/squid/
store_url_rewrite_1.pl 
nobody   31332  0.0  0.0   3552  1488 ?        Ss   Nov01   0:00 /usr/bin/perl /etc/squid/
store_url_rewrite_1.pl 

1
nobody   31333  0.0  0.0   3552  1488 ?        Ss   Nov01   0:00 /usr/bin/perl /etc/squid/
store_url_rewrite_1.pl

Dari hasil output di atas terlihat nomor proses squid yakni yang bercetak merah yakni 2958. Alternati lain bisa
dari perintah di bawah ini:

opr@Proxy:~$ cat /var/run/squid.pid 
2958

Nomor proses squid tidak selalu sama.

Melihat log squid


Log squid ditaruh di direktori /var/log/squid. Hanya file cache.log yang disimpan, hal ini untuk tidak memperberat
kerja harddisk untuk menulis log. Untuk melihat log squid cache.log jalankan perintah ini:

opr@Proxy:~$ sudo tail /var/log/squid/cache.log 
2009/11/02 13:09:30| httpReadReply: Excess data from "GET 
http://www2.cbox.ws/box/jsv4_1.php?r=10" 
2009/11/02 13:29:23| logfileOpen: opening log 
/usr/local/squid/var/logs/netdb.state 
2009/11/02 13:29:23| logfileClose: closing log 
/usr/local/squid/var/logs/netdb.state 
2009/11/02 13:29:23| NETDB state saved; 0 entries, 17 msec 
2009/11/02 13:42:52| squidaio_queue_request: WARNING ­ Queue congestion 
2009/11/02 13:47:11| httpReadReply: Excess data from "GET 
http://webcs.msg.yahoo.com/crossdomain.xml" 
2009/11/02 14:30:43| logfileOpen: opening log 
/usr/local/squid/var/logs/netdb.state 
2009/11/02 14:30:43| logfileClose: closing log 
/usr/local/squid/var/logs/netdb.state 
2009/11/02 14:30:43| NETDB state saved; 0 entries, 0 msec
 
Perintah tail akan memperlihatkan 10 baris terakhir dari log cache.log. Untuk melihat semua baris log cache.log:

opr@Proxy:~$ sudo less /var/log/squid/cache.log
2009/11/01 04:00:01| storeDirWriteCleanLogs: Starting... 
2009/11/01 04:00:01|     65536 entries written so far. 
2009/11/01 04:00:01|    131072 entries written so far. 
2009/11/01 04:00:01|    196608 entries written so far. 
2009/11/01 04:00:01|    262144 entries written so far. 
2009/11/01 04:00:01|    327680 entries written so far. 
2009/11/01 04:00:01|    393216 entries written so far. 
2009/11/01 04:00:01|    458752 entries written so far. 
2009/11/01 04:00:01|    524288 entries written so far. 
2009/11/01 04:00:01|    589824 entries written so far. 
2009/11/01 04:00:01|    655360 entries written so far. 
2009/11/01 04:00:01|    720896 entries written so far. 
2009/11/01 04:00:01|    786432 entries written so far. 
2009/11/01 04:00:01|    851968 entries written so far. 
2009/11/01 04:00:01|    917504 entries written so far. 
2009/11/01 04:00:01|    983040 entries written so far. 

2
2009/11/01 04:00:01|   1048576 entries written so far. 
2009/11/01 04:00:01|   1114112 entries written so far. 
2009/11/01 04:00:02|   1179648 entries written so far. 
2009/11/01 04:00:02|   1245184 entries written so far. 
2009/11/01 04:00:02|   1310720 entries written so far. 
2009/11/01 04:00:02|   1376256 entries written so far. 
2009/11/01 04:00:02|   1441792 entries written so far. 
2009/11/01 04:00:02|   1507328 entries written so far. 
2009/11/01 04:00:05|   Finished.  Wrote 1537099 entries. 
2009/11/01 04:00:05|   Took 4.5 seconds (341715.0 entries/sec). 
... dst ...

Saat di dalam perintah less gunakan key berikut :


1. PgDown : bergerak ke depan 1 layar
2. PgUp : bergerak ke belakang 1 layar
3. g : bergerak ke awal baris
4. G : bergerak ke akhir baris
5. h : menampilkan menu lengkap
6. q : keluar dari perintah less

Konfigurasi squid
File konfigurasi squid di simpan di file /etc/squid/squid.conf. Konfigurasi squid yang umum adalah:
● Memori
cache_mem 64 MB 
maximum_object_size_in_memory 128 KB 
memory_replacement_policy heap GDSF

● Cache
cache_replacement_policy heap LFUDA 
cache_dir aufs /cache 55000 16 256 
maximum_object_size 128 MB

Singkatnya besar alokasi object cache squid di harddisk lokal sebesar 55GB dengan cache memori untuk hot
objects sebesar 64MB.

Mematikan squid
Dalam keadaan normal squid tidak boleh dimatikan (shutdown). Untuk maintenance squid, sebelum shutdown
squid, jalankan disable-proxy pada mikrotik RB439, tunggu selama 30 menit untuk menuntaskan proses koneksi
yang masih berlangsung antara squid dengan client. Apabila perlu jalankan perintah di bawah ini untuk melihat
apakah masih ada client yang terkoneksi dengan squid meski disable-proxy sudah dijalankan:

opr@Proxy:~$ sudo lsof ­Pni|grep squid|grep ESTABLISH
squid      2958   nobody    8u  IPv4 41384218       TCP 192.168.100.1:8080­
>192.168.0.46:1200 (ESTABLISHED) 
squid      2958   nobody    9u  IPv4 41388065       TCP 192.168.100.1:8080­
>192.168.0.113:1693 (ESTABLISHED) 
squid      2958   nobody   10u  IPv4 41387946       TCP 192.168.100.1:8080­
>192.168.0.40:4991 (ESTABLISHED) 
...

Jika masih ada baris yang mengandung kata ESTABLISHED, sebaiknya tunggu beberapa menit dan lakukan

3
perintah di atas sampai benar-benar tidak ada koneksi client yang ESTABLISHED dengan squid. Saatnya untuk
mematikan squid:

opr@Proxy:~$ sudo /etc/rc.d/rc.squid stop
Stoping squid:
.

Saat ekseskusi perintah di atas, squid tidak langsung shutdown melainkan menunggu paling lama selama 60
detik untuk mematikan program child-nya.

Menjalankan squid
Untuk menjalankan squid lakukan perintah ini:

opr@Proxy:~$ sudo /etc/rc.d/rc.squid start
Starting squid:
.

Melihat perfomansi squid


Untuk melihat perfomansi squid saat mana squid sedang running jalankan perintah sbb:

opr@Proxy:~$ squidclient ­p 8080 mgr:info@paitonprb 
HTTP/1.0 200 OK 
Server: squid/2.7.STABLE6 
Date: Mon, 02 Nov 2009 11:16:54 GMT 
Content­Type: text/plain 
Expires: Mon, 02 Nov 2009 11:16:54 GMT 
X­Cache: MISS from proxy.kopkar56.org 
X­Cache­Lookup: MISS from proxy.kopkar56.org:8080 
Via: 1.0 proxy.kopkar56.org:8080 (squid/2.7.STABLE6) 
Connection: close 

Squid Object Cache: Version 2.7.STABLE6 
Start Time: Sun, 11 Oct 2009 23:19:08 GMT 
Current Time: Mon, 02 Nov 2009 11:16:54 GMT 
Connection information for squid: 
Number of clients accessing cache: 0 
Number of HTTP requests received: 15774919 
Number of ICP messages received: 0 
Number of ICP messages sent: 0 
Number of queued ICP replies: 0 
Request failure ratio: 0.00 
Average HTTP requests per minute since start: 509.6 
Average ICP messages per minute since start:0.0 
Select loop called: 304691825 times, 6.096 ms avg 
Cache information for squid: 
Request Hit Ratios: 5min: 28.8%, 60min: 28.7% 
Byte Hit Ratios: 5min: 13.3%, 60min: 18.4% 
Request Memory Hit Ratios: 5min: 9.1%, 60min: 19.8% 
Request Disk Hit Ratios: 5min: 32.8%, 60min: 48.6% 
Storage Swap size: 55190048 KB 
Storage Mem size: 65304 KB 
Mean Object Size: 34.07 KB 
Requests given to unlinkd: 0 
Median Service Times (seconds)  5 min    60 min: 
HTTP Requests (All):   0.64968  0.58309 
Cache Misses:          0.72387  0.72387 
Cache Hits:            0.00000  0.00000 
Near Hits:             0.72387  0.68577 

4
Not­Modified Replies:  0.00000  0.00000 
DNS Lookups:           0.03868  0.03868 
ICP Queries:           0.00000  0.00000 
Resource usage for squid: 
UP Time: 1857465.836 seconds 
CPU Time: 9317.350 seconds 
CPU Usage: 0.50% 
CPU Usage, 5 minute avg: 0.31% 
CPU Usage, 60 minute avg: 0.40% 
Process Data Segment Size via sbrk(): 352632 KB 
Maximum Resident Size: 0 KB 
Page faults with physical i/o: 5 
Memory usage for squid via mallinfo(): 
Total space in arena:  352632 KB 
Ordinary blocks:       347883 KB 244815 blks 
Small blocks:               0 KB      0 blks 
Holding blocks:         12896 KB      5 blks 
Free Small blocks:          0 KB 
Free Ordinary blocks:    4748 KB 
Total in use:          360779 KB 99% 
Total free:              4748 KB 1% 
Total size:            365528 KB 
Memory accounted for: 
Total accounted:       263265 KB 
memPoolAlloc calls: 2031869438 
memPoolFree calls: 2027702844 
File descriptor usage for squid: 
Maximum number of file descriptors:   4096 
Largest file desc currently in use:    189 
Number of file desc currently in use:  140 
Files queued for open:                   0 
Available number of file descriptors: 3956 
Reserved number of file descriptors:   100 
Store Disk files open:                   2 
IO loop method:                     epoll 
Internal Data Structures: 
1626112 StoreEntries 
 12029 StoreEntries with MemObjects 
 11969 Hot Object Cache Items 
1620098 on­disk objects 

Baris-baris yang berwarna merah itu memperlihatkan perfomansi squid:


Request Hit Ratios: 5min: 28.8%, 60min: 28.7% 
Byte Hit Ratios: 5min: 13.3%, 60min: 18.4% 
Request Memory Hit Ratios: 5min: 9.1%, 60min: 19.8% 
Request Disk Hit Ratios: 5min: 32.8%, 60min: 48.6% 

Baris-baris yang berwarna biru itu memperlihatkan jumlah object yang disimpan squid di memori dan harddisk:
1626112 StoreEntries 
 12029 StoreEntries with MemObjects 
 11969 Hot Object Cache Items 
1620098 on­disk objects 

Penjelasan rinci bisa dibaca di http://wiki.squid-cache.org/SquidFaq/SquidMemory/


atau di http://wiki.squid-cache.org/SquidFaq

Melihat pemakaian partisi untuk cache squid

opr@Proxy:/etc/squid$ df 
Filesystem           1K­blocks      Used Available Use% Mounted on 
/dev/root               482214    211863    245452  47% / 
/dev/sda2              4814968   2038300   2532080  45% /usr 
/dev/sda3               972436    200360    722680  22% /var 

5
/dev/sda5              9621848   1709532   7423540  19% /home 
/dev/sda7            144879346  55871934  81646029  41% /cache 
/dev/sda8            144879346     38287 137479676   1% /video 
tmpfs                  1685004         0   1685004   0% /dev/shm

Terlihat pada baris yang berwarna biru partisi /dev/sda7 telah terpakai 41% sebanyak 55,871,934KB atau
ekuivalen dengan 55GB (lihat isi baris cache_dir di atas). Ini menunjukkan squid telah mengisi penuh cachenya
sebesar 55GB. Object internet / cache yang lama dan jarang diakses serta cache yang negative_hit secara
otomatis akan dihapus oleh squid. Lebih lanjut silahkan baca situs wiki squid pada link di atas.

Maintenance squid bila browsing stuck (ada tulisan WARNING ­ Queue congestion di cache.log)


Bilamana browsing menjadi lambat atau stuck dan banyak tulisan “WARNING ­ Queue congestion” di file /var/
log/squid/cache.log maka perlu dilakukan perbaikan squid dengan cara sbb:
1. Jalankan disable-proxy di mikrotik RB439.
2. Matikan squid dengan cara yang telah diterangkan di atas.
3. Hapus paksa file /cache/swap.state
opr@Proxy:~$ sudo rm ­f /cache/swap.state
4. Hidupkan squid.
5. Catat waktunya
opr@Proxy:~$ date > waktu­hidupkan­squid
6. Setelah squid hidup maka dia akan memperbaiki struktur cache yang corrupt, yang dilakukannya
adalah:
○ Membuat file /cache/swap.state.new
○ Mengosongkan isi file /cache/swap.state (isinya adalah 0 byte)
opr@Proxy:~$ ls ­l /cache/swap.state 
-rw-r----- 1 nobody nogroup 0 2009-11-02 17:59 /cache/swap.state
7. Squid selesai memperbaiki struktur cache dengan hasil berupa:
○ File /cache/swap.state.new hilang
○ File /cache/swap.state tidak lagi 0 byte
Proses pembentukan atau perbaikan struktur cache squid memakan waktu yang lama tergantung besar
alokasi cache_dir. Waktu yang dibutuhkan bisa 2 sampai 5 jam. Sehingga untuk monitor apakah proses
perbaikan sudah selesai tinggal melihat apakah file /cache/swap.state.new sudah hilang:
opr@Proxy:~$ ls ­l /cache/swap.state.new 
/bin/ls: cannot access /cache/swap.state.new: No such file or directory
8. Jika file /cache/swap.state sudah berisi maka hasilnya seperti ini
opr@Proxy:~$ ls ­l /cache/swap.state 
­rw­r­­­­­ 1 nobody nogroup 78957504 2009­11­02 20:48 /cache/swap.state
Tampilan di atas, sebagai contoh, memperlihatkan file /cache/swap.state baru selesai dibuat pada
tanggal 02/11/2009 jam 20:48. Jika anda bandingkan hasil keluaran file waktu-hidupkan-squid dan
waktu file /cache/swap.state selesai dibuat maka terlihat waktu yang diperlukan squid untuk
memperbaiki struktur cache.
opr@Proxy:~$ cat waktu­hidupkan­squid 
Mon Nov  2 18:00:00 WIT 2009
9. Hidupkan squid kembali, tunggu sekitar 15 menit, kemudian matikan squid.
10. Hidupkan squid kembali.
11. Jalankan enable-proxy di mikrotik RB439.

6
Menghapus content cache object tertentu
Kita bisa menghapus content cache squid object tertentu. Misalkan ada user yang upload data gambar terbaru
di blog atau homepagenya dan sewaktu dilihat di browser ternyata gambarnya masih yang lama. Rupanya user
tersebut tidak memberi nama lain untuk gambar yang baru dan squid masih menyimpan object cache gambar
tersebut di harddisk lokal. Untuk memaksa agar browser bisa menampilkan gambar yang baru, misal alamatnya
adalah http://user.blog.com/images/gambar.jpg, ada 2 cara:

1. Click tombol reload di browser user.


2. Paksa squid untuk menghapusa content object cache yang masih tersimpan jika cara 1 di atas tidak
berhasil :

opr@Proxy:~$ squidclient ­p 8080 ­m PURGE http://user.blog.com/images/gambar.jpg
HTTP/1.0 200 OK
Server: squid/2.7.STABLE6
Date: Wed, 04 Nov 2009 05:55:32 GMT
Content­Length: 0
Expires: Wed, 04 Nov 2009 05:55:32 GMT
X­Cache: MISS from proxy.kopkar56.org
X­Cache­Lookup: NONE from proxy.kopkar56.org:8080
Via: 1.0 proxy.kopkar56.org:8080 (squid/2.7.STABLE6)
Connection: close

Bila telah muncul baris HTTP/1.0 200 OK berarti contect tersebut telah dihapus dari cache squid.

Untuk mengetahui secara detail bagaiman squid menyimpan object cache silahkan buka link di bawah ini:
http://forum.linux.or.id/viewtopic.php?f=16&t=1364

Anda mungkin juga menyukai