由於環境有限就在一臺機器上既做cache服務又做應用服務
Squid+apache
IP:192.168.2.17
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 Localhost src 127.0.0.1 192.168.30.93
#http_access allow Manager Localhost
#http_access deny Manager
#http_access deny !Safe_ports
#http_access allow all
#http_access deny OverConnLimit
http_access deny all
cache deny QUERY
cache_swap_high 95
#ipcache_low 90
#ipcache_high 95
#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
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
refresh_pattern -i .jpg$ 1440 50% 2880 ignore-reload
refresh_pattern -i .png$ 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 .js$ 10 50% 60 reload-into-ims
refresh_pattern -i .xml$ 10 50% 30 reload-into-ims
broken_vary_encoding allow apache
cache_effective_group squid
visible_hostname pic.mytophome.com
icp_port 0
error_directory /usr/local/squid/share/errors/English
via off
coredump_dir /usr/local/squid/var/cache
max_filedesc 20480
#chown -R squid:squid /usr/local/squid/var/
#mkdir /tmp1
#chmod -R 777 /tmp1
#/usr/local/squid/sbin/squid -z
# /usr/local/squid/sbin/squid -NCd1
#/usr/local/squid/sbin/squid -f /usr/local/squid/etc/squid.conf
# ps -ef | grep squid
# nestat -ln | grep 80
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