歡迎您光臨本站 註冊首頁

squid3加速web伺服器

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

squid3加速web伺服器

測試環境:

     操作系統:centos 5.0   

     Web 伺服器: apache2 + tomcat 5.5

     Jdk  : j2se 1.5.5

  

1. 下載squid-3.0.STABLE9.tar.gz (測試時最新的版本)。

http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE9.tar.gz

2. 添加用戶及組

# useradd squid -M -c "Squid user" -d /dev/null -s /sbin/nologin

3. 解壓並編譯安裝

tar squid-3.0.STABLE9.tar.gz

cd squid-3.0.STABLE9

./configure --prefix=/data/squid3 --disable-carp --with-aufs-threads=32 --with-pthreads --enable-storeio='ufs,aufs, null' --enable-disk-io='AIO,Blocking' --enable-removal-policies='heap,lru'  --disable-wccp --enable-kill-parent-hack --disable-snmp --disable-poll --disable-select --enable-auth=basic --with-aio  --disable-ident-lookup --with-filedescriptors=65536  

編譯參數不做詳細介紹請查相關文檔

Make

make install

安裝完畢。

  

4. 配置

可能需要創建一些文件這些都是配置文件中需要調用的(這個要注意文件的屬主和許可權)

1) #cd /data/squid3/var/logs/

2) #touch cache.log

3) #chmod 755 cache.log

4) #chown squid:squid cache.log

5) #touch page_zs_access_log

6) #chmod 755 page_zs_access_log

7) #chown squid:squid page_zs_access_log

  

8) #cd /data/squid3/etc/

9) 配置squid 配置文件 squid.conf

# vi squid.conf                 (192.168.3.11 為伺服器的ip 地址)

visible_hostname www.test.com

http_port 80 vhost vport

cache_mem 512 MB

maximum_object_size_in_memory 2048 KB

memory_replacement_policy lru

cache_dir ufs /tmp 512 16 256

max_open_disk_fds 0

minimum_object_size 0 KB

maximum_object_size 32768 KB

logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh

access_log /data/squid3/var/logs/page_zs_access_log combined

pid_filename/data/squid3/var/logs/squid.pid

cache_store_log none

cache_peer 192.168.3.11 parent 81 0 no-query no-digest originserver name=www

cache_peer_domain www www.test.com

cache_peer_access www allow all

http_access allow all

acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe

cache deny QUERY

cache_effective_user squid

cache_effective_group squid

  

10) #/data/squid3/sbin/squid -k parse

可以根據這個測試命令用來驗證squid.conf 的語法和配置(下面是OK 的如果不OK 會有相應的提示根據提示來修改配置文件)

2008/10/14 21:14:56| Processing Configuration File: /data/squid3/etc/squid.conf (depth 0)

11) #/data/squid3/sbin/squid -z

用來創建緩存目錄

  

12) vi 一個squid.sh 的啟動腳本如下:賦予可執行許可權

#vi squid.sh

#!/bin/sh

#

ulimit -HSn 15000

# this script starts and stops Squid

echo 15000 > /proc/sys/fs/file-max

case "$1" in

start)

          /data/squid3/sbin/squid -s

          echo -n ' Squid'

          ;;

stop)

          /data/squid3/sbin/squid -k shutdown

          ;;

esac

  

#chmod +x squid.sh

5. 啟動squid

#./squid.sh start 就可以啟動squid 了

  

查看有沒有啟動可以

#ps fax|grep squid

13750 pts /3    S+     0:00                      \_ grep squid

30474 ?        Ss     0:00 /data/squid3/sbin/squid -s

30476 ?        S      0:01 \_ (squid) -s

  

通過命令lsof -i:80 查看誰佔用了80 埠

  

  

查看squid 的訪問日誌。

# tail – f /data/squid3/var/logs/page_zs_access_log

  

查看命中率及其他相關信息

# /data/squid3/bin/squidclient -p 80 -h localhost mgr:info

HTTP/1.0 200 OK

Server: squid/3.0.STABLE9

Mime-Version: 1.0

Date: Tue, 14 Oct 2008 13:22:40 GMT

Content-Type: text/plain

Expires: Tue, 14 Oct 2008 13:22:40 GMT

Last-Modified: Tue, 14 Oct 2008 13:22:40 GMT

X-Cache: MISS from www.6558855.com

Via: 1.0 www.6558855.com (squid/3.0.STABLE9)

Connection: close

  

Squid Object Cache: Version 3.0.STABLE9

Start Time:     Tue, 14 Oct 2008 11:25:50 GMT

Current Time:   Tue, 14 Oct 2008 13:22:40 GMT

Connection information for squid:

        Number of clients accessing cache:      2

        Number of HTTP requests received:       772

        Number of ICP messages received:        0

        Number of ICP messages sent:    0

        Number of queued ICP replies:   0

        Number of HTCP messages received:       0

        Number of HTCP messages sent:   0

        Request failure ratio:   0.00

         Average HTTP requests per minute since start:   6.6

        Average ICP messages per minute since start:    0.0

        Select loop called: 7081542 times, 0.990 ms avg

Cache information for squid:

        Hits as % of all requests:      5min: 0.0%, 60min: 89.7%

        Hits as % of bytes sent:        5min: -0.0%, 60min: -0.0%

        Memory hits as % of hit requests:       5min: 0.0%, 60min: 0.0%

        Disk hits as % of hit requests: 5min: 0.0%, 60min: 0.0%

        Storage Swap size:      104 KB

         Storage Swap capacity:   0.0% used, 100.0% free

        Storage Mem size:       228 KB

        Storage Mem capacity:    0.0% used, 100.0% free

        Mean Object Size:       10.40 KB

        Requests given to unlinkd:      68

Median Service Times (seconds)  5 min    60 min:

        HTTP Requests (All):   0.00000  0.00000

        Cache Misses:          0.00000  0.00000

        Cache Hits:            0.00000  0.00000

        Near Hits:             0.00000  0.00000

        Not-Modified Replies:  0.00000  0.00000

        DNS Lookups:           0.00000  0.00000

        ICP Queries:           0.00000  0.00000

Resource usage for squid:

        UP Time:        7009.125 seconds

        CPU Time:       0.948 seconds

        CPU Usage:      0.01%

        CPU Usage, 5 minute avg:        0.00%

        CPU Usage, 60 minute avg:       0.01%

        Process Data Segment Size via sbrk(): 2968 KB

        Maximum Resident Size: 0 KB

        Page faults with physical i/o: 2

Memory usage for squid via mallinfo():

        Total space in arena:    3240 KB

        Ordinary blocks:         3194 KB     17 blks

        Small blocks:               0 KB      0 blks

        Holding blocks:         11472 KB     17 blks

        Free Small blocks:          0 KB

        Free Ordinary blocks:      45 KB

        Total in use:           14666 KB 100%

        Total free:                45 KB 0%

        Total size:             14712 KB

Memory accounted for:

        Total accounted:         3001 KB  20%

        memPool accounted:       3001 KB  20%

        memPool unaccounted:    11710 KB  80%

        memPoolAlloc calls:    147106

        memPoolFree calls:     145713

File descriptor usage for squid:

        Maximum number of file descriptors:   15000

        Largest file desc currently in use:     14

        Number of file desc currently in use:    8

        Files queued for open:                   0

        Available number of file descriptors: 14992

        Reserved number of file descriptors:   100

        Store Disk files open:                    0

Internal Data Structures:

            45 StoreEntries

            41 StoreEntries with MemObjects

            40 Hot Object Cache Items

            10 on-disk objects

  

  

  

6. 關於動態頁面的緩存。

       如 jsp 頁面。

       利用Header 為jsp 伺服器減壓

     在參與緩存的jsp 中加入如下程序,進行「Last-Modified 」和「Expires 」的設置;

  

<%@ page import="java.io.*"%>

<%

long file_lmodified = new File("/tmp/catchmodified".lastModified();

response.setBufferSize(16);

response.setDateHeader("Last-Modified", file_lmodified);

response.setDateHeader("Expires", System.currentTimeMillis() / 1000 * 1000 + 300000);

response.flushBuffer();

%>

  

  

7. 添加自動更新記時方式

  

     # vi refreshCatch.sh

#/bin/sh

/bin/echo >/tmp/catchmodified

Chmod +x refreshCatch.sh

然後在crontab 里寫一句

*/5 * * * *  /data/squid3/refreshCatch.sh
《解決方案》

squid3是重寫的

現在穩定么,性能怎麼樣?
《解決方案》

能達到什麼效果,?得試試.:D
《解決方案》

試試...
《解決方案》

還是蠻不錯的,不過最好用引用 起來

[火星人 ] squid3加速web伺服器已經有664次圍觀

http://coctec.com/docs/service/show-post-17711.html