squid3加速web服务器

测试环境: 操作系统 :centos5.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

测试环境:

操作系统:centos5.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

makeinstall

安装完毕。

4. 配置

可能需要创建一些文件这些都是配置文件中需要调用的(这个要注意文件的属主和权限)

1) [root@www~]#cd /data/squid3/var/logs/

2) [root@www~]#touch cache.log

3) [root@www~]#chmod 755 cache.log

4) [root@www~]#chown squid:squid cache.log

5) [root@www~]#touch page_zs_access_log

6) [root@www~]#chmod 755 page_zs_access_log

7) [root@www~]#chown squid:squid page_zs_access_log

8) [root@www~]#cd /data/squid3/etc/

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

[root@www~]# vi squid.conf (192.168.3.11服务器ip地址)

visible_hostnamewww.test.com

http_port80 vhost vport

cache_mem512 MB

maximum_object_size_in_memory2048 KB

memory_replacement_policylru

cache_dirufs /tmp 512 16 256

max_open_disk_fds0

minimum_object_size0 KB

maximum_object_size32768 KB

logformatcombined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %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_lognone

cache_peer192.168.3.11 parent 81 0 no-query no-digest originserver name=www

cache_peer_domainwww www.test.com

cache_peer_accesswww allow all

http_accessallow all

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

cachedeny QUERY

cache_effective_usersquid

cache_effective_groupsquid

10)[root@www ~]#/data/squid3/sbin/squid -k parse

可以根据这个测试命令用来验证squid.conf的语法和配置(下面是OK的如果不OK会有相应的提示根据提示来修改配置文件)

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

11)[root@www ~]#/data/squid3/sbin/squid -z

用来创建缓存目录

12)vi一个squid.sh的启动脚本如下:赋予可执行权限

[root@www~]#vi squid.sh

#!/bin/sh

#

ulimit-HSn 15000

#this script starts and stops Squid

echo15000 > /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

[root@www~]#./squid.sh start就可以启动squid

查看有没有启动可以

[root@www~]#ps fax|grep squid

13750 pts/3 S+ 0:00 \_ grepsquid

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

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

通过命令lsof -i:80查看谁占用了80端口

查看squid的访问日志。

[root@www ~]# tail f /data/squid3/var/logs/page_zs_access_log

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

[root@www ~]# /data/squid3/bin/squidclient -p 80 -hlocalhost 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 ofclients accessing cache: 2

Number ofHTTP requests received: 772

Number ofICP messages received: 0

Number ofICP messages sent: 0

Number ofqueued ICP replies: 0

Number ofHTCP messages received: 0

Number ofHTCP messages sent: 0

Requestfailure ratio: 0.00

Average HTTP requests per minute sincestart: 6.6

Average ICPmessages per minute since start: 0.0

Select loopcalled: 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 hitsas % of hit requests: 5min: 0.0%,60min: 0.0%

Disk hitsas % of hit requests: 5min: 0.0%, 60min: 0.0%

StorageSwap size: 104 KB

Storage Swap capacity: 0.0% used, 100.0% free

Storage Memsize: 228 KB

Storage Memcapacity: 0.0% used, 100.0% free

Mean ObjectSize: 10.40 KB

Requestsgiven to unlinkd: 68

Median Service Times (seconds) 5 min 60 min:

HTTPRequests (All): 0.00000 0.00000

CacheMisses: 0.00000 0.00000

CacheHits: 0.00000 0.00000

NearHits: 0.00000 0.00000

Not-Modified Replies: 0.00000 0.00000

DNSLookups: 0.00000 0.00000

ICPQueries: 0.00000 0.00000

Resource usage for squid:

UPTime: 7009.125 seconds

CPUTime: 0.948 seconds

CPUUsage: 0.01%

CPU Usage,5 minute avg: 0.00%

CPU Usage,60 minute avg: 0.01%

ProcessData Segment Size via sbrk(): 2968 KB

MaximumResident Size: 0 KB

Page faultswith physical i/o: 2

Memory usage for squid via mallinfo():

Total spacein arena: 3240 KB

Ordinaryblocks: 3194 KB 17 blks

Smallblocks: 0 KB 0 blks

Holdingblocks: 11472 KB 17 blks

Free Smallblocks: 0 KB

FreeOrdinary blocks: 45 KB

Total inuse: 14666 KB 100%

Totalfree: 45 KB 0%

Totalsize: 14712 KB

Memory accounted for:

Totalaccounted: 3001 KB 20%

memPoolaccounted: 3001 KB 20%

memPoolunaccounted: 11710 KB 80%

memPoolAlloc calls: 147106

memPoolFreecalls: 145713

File descriptor usage for squid:

Maximumnumber of file descriptors: 15000

Largestfile desc currently in use: 14

Number offile desc currently in use: 8

Filesqueued for open: 0

Availablenumber of file descriptors: 14992

Reservednumber of file descriptors: 100

Store Diskfiles open: 0

Internal Data Structures:

45StoreEntries

41StoreEntries with MemObjects

40 HotObject Cache Items

10on-disk objects

6. 关于动态页面的缓存。

jsp页面。

利用Headerjsp服务器减压

在参与缓存的jsp中加入如下程序,进行“Last-Modified”和“Expires”的设置;

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

<%

longfile_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. 添加自动更新记时方式

[root@www ~]#vi refreshCatch.sh

#/bin/sh

/bin/echo>/tmp/catchmodified

Chmod+x refreshCatch.sh

然后在crontab里写一句

*/5 * * * * /data/squid3/refreshCatch.sh

郑重声明:本文版权包含图片归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们(delete@yzlfxy.com)修改或删除,多谢。

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

留言与评论(共有 0 条评论)
昵称:
匿名发表
   
验证码: