一. 环境介绍
由于环境有限就在一台机器上既做cache服务又做应用服务
Squid+apache
IP:192.168.2.17
二.安装squid
1. #tar -jxvf squid-2.7.STABLE5.tar.bz2
2. cd squid-2.7.STABLE5
3. ./configure  --prefix=/usr/local/squid --enable-dlmalloc --with-pthreads --enable-poll --disable-internal-dns --enable-stacktrace --enable-removal-policies="heap,lru" --enable-delay-pools --enable-storeio="aufs,coss,diskd,ufs"
4. make
5. make install
6. vi /usr/local/squid/etc/squid.conf
内容如下:
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl Localhost src 127.0.0.1 192.168.2.17
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443
acl Safe_ports port 81
acl CONNECT method CONNECT
#acl SNMP snmp_community   public
acl myip dst 192.168.2.17
http_access deny !myip
http_access allow all
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
#snmp_access allow SNMP Localhost
#acl myip dst 192.168.30.93
#http_access deny !myip
#acl Manager proto cache_object
#acl Localhost src 127.0.0.1 192.168.30.93
#http_access allow Manager Localhost
#http_access deny Manager
#acl Safe_ports port  81
#http_access deny !Safe_ports
#http_access allow all
#acl OverConnLimit maxconn 16
#http_access deny OverConnLimit

http_access deny all
 
icp_access allow all
 
 
http_port 192.168.2.17:80 vhost vport
 
cache_peer 192.168.2.17 parent 81 0 no-query originserver
 
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe
cache deny QUERY
 
cache_mem 300 MB
maximum_object_size_in_memory 4096 KB
 
 
cache_dir ufs /tmp1 2048 16 512
 
ie_refresh on
cache_swap_low 90
cache_swap_high 95
#ipcache_size 4096
#ipcache_low 90
#ipcache_high 95 
fqdncache_size 1024
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
#LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
access_log none
#access_log /var/log/squid/access.log squid
cache_log /var/log/squid/cache.log squid
cache_store_log none

emulate_httpd_log on
request_header_max_size 100 KB
url_rewrite_host_header off
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern .               0       20%     4320
refresh_pattern -i .gif$   1440    50%     2880      ignore-reload
refresh_pattern -i .jpg$   1440    50%     2880      ignore-reload
refresh_pattern -i .png$   1440    50%     2880      ignore-reload
refresh_pattern -i .mp3$   1440    50%     2880      ignore-reload
refresh_pattern -i .wmv$   1440    50%     2880      ignore-reload
refresh_pattern -i .rm$   1440    50%     2880      ignore-reload
refresh_pattern -i .swf$   1440    50%     2880      ignore-reload
refresh_pattern -i .mpeg$   1440    50%     2880      ignore-reload
refresh_pattern -i .wma$   1440    50%     2880      ignore-reload
refresh_pattern -i .css$ 10 50% 60 reload-into-ims
refresh_pattern -i .js$ 10 50% 60 reload-into-ims
refresh_pattern -i .xml$ 10 50% 30 reload-into-ims
 
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
 
 
cache_effective_user squid
cache_effective_group squid

visible_hostname pic.mytophome.com
cache_mgr molecar@gmail.com
httpd_suppress_version_string on
cache_vary on

icp_port 0

error_directory /usr/local/squid/share/errors/English

via off
forwarded_for on
tcp_recv_bufsize 65535 bytes

coredump_dir /usr/local/squid/var/cache
max_filedesc 20480
7.# useradd squid
   #chown -R  squid:squid  /usr/local/squid/var/
   #mkdir /tmp1
   #chmod -R 777 /tmp1
8.进行测试一下squid是否正常
#/usr/local/squid/sbin/squid -z
# /usr/local/squid/sbin/squid -NCd1
9.正常的话就可以启动squid了
#/usr/local/squid/sbin/squid -f /usr/local/squid/etc/squid.conf
10.查看一下squid是否启动起来
# ps -ef | grep squid
# nestat -ln | grep 80
三.配置apache
1. 安装apache
2. 改apache的端口为81端口
3. 启动apache

四.测试是否全部正常
1. 访问 http://192.168.2.17,网页可以正常打开
2. 查看squid的cache的命中率:
squidclient -h 192.168.2.17 -p 80 mgr:info
内容如下:
Cache information for squid:
        Request Hit Ratios:     5min: 0.0%, 60min: 33.3%  (请求命中率)
        Byte Hit Ratios:        5min: -0.0%, 60min: 36.7%   (字节命中率)
        Request Memory Hit Ratios:      5min: 0.0%, 60min: 0.0%  (内存命中率)
        Request Disk Hit Ratios:        5min: 0.0%, 60min: 0.0%   (硬盘命中率)
        Storage Swap size:      40 KB
        Storage Mem size:       152 KB
        Mean Object Size:       8.00 KB
        Requests given to unlinkd:      3