现在的位置: 首页随笔>正文
Squid+Purge安装配置
发表于8年前 随笔 暂无评论 ⁄ 被围观 1,940 次+

Squid+Purge安装配置
安装环境:Centos5..4

一,安装Squid
wget http://www.squid-cache.org/Versions/v3/3.1/squid-3.1.9.tar.gz /root/tools/
cd /root/tools
tar zxvf squid-3.1.9.tar.gz
cd squid-3.1.9
mkdir /usr/local/squid
./configure --prefix=/usr/local/squid
make
make install

二,安装Purge
wget http://www.wa.apana.org.au/~dean/sources/purge-20040201-src.tar.gz /root/tools/
tar zxf purge-20040201-src.tar.gz
mv purge /usr/local/purge
cd /usr/local/purge && make
purge安装位置:/usr/local/purge/ 做了个链接: ln -s /usr/local/purge/purge /usr/bin/purge

三,配置squid
groupadd squid
useradd --gid 23 -d /usr/local/squid/var -s /sbin/nologin --uid 23 squid
chown squid.squid -R /var/local/squid/var
将主机名写到/etc/hosts文件中去
squid的配置文档
cat /etc/squid/squid.conf |egrep -v '(^$|#)'

acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
acl SSL_ports port 443
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet
http_access allow localhost

acl purge method PURGE
acl src_local src 127.0.0.0/8
http_access allow purge src_local
http_access deny purge
http_access allow all

http_port 3128
hierarchy_stoplist cgi-bin ?
cache_dir ufs /usr/local/squid/var/cache 10240 16 256
coredump_dir /usr/local/squid/var/cache
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320
cache_effective_user squid
cache_effective_group squid

四,启动squid
首次启动前,先创建cache目录
/usr/local/squid/sbin/squid -z
启动squid
查看squid 配置文件路径
/usr/local/squid/sbin/squid -k parse
启动Squid
/usr/local/squid/sbin/squid
重新加载squid
/usr/local/squid/sbin/squid -k reconfigure

五,测试
purge 的用法
-c 指定quid配置文件路径
-p 指定squid端口
-P 如果接2 则是列出cache,如果接1 则是清除cache
-se 关键词
1.
列出cache中包含sohu.com的缓存: purge -c /usr/local/squid/etc/squid.conf -p localhost:3128 -P 2 -se 'sohu.com'
清除cache中包含sohu.com的缓存: purge -c /usr/local/squid/etc/squid.conf -p localhost:3128 -P 1 -se 'sohu.com'

2.
列出cache中以.txt结尾的缓存: purge -c /usr/local/squid/etc/squid.conf -p localhost:3128 -P 2 -se '\.txt$'
清除cache中以.txt结尾的缓存: purge -c /usr/local/squid/etc/squid.conf -p localhost:3128 -P 1 -se '\.txt$'

purge -c /etc/squid/squid.conf -p localhost:3128 -P 2 -se 'baidu'
### Use at your own risk! No guarantees whatsoever. You were warned. ###
#
# Currently active values for purge:
# $Id: purge.cc,v 1.17 2000/09/21 10:59:53 cached Exp $
# Debug level       : production level + parallel mode
# Copy-out directory: copy-out mode disabled
# Squid config file : /etc/squid/squid.conf
# Cacheserveraddress: 127.0.0.1:3128
# purge mode        : 0x01
# Regular expression: 1 "baidu"
#
/usr/local/squid/var/cache/00/00/000000A0 404      940 http://baike.baidu.com/template/baikeDynamicData.js?random=0.18836161426392095
/usr/local/squid/var/cache/00/00/0000009D 404     3454 http://baike.baidu.com/js/sug.js
/usr/local/squid/var/cache/00/00/000000A3 404     1610 http://baike.baidu.com/favicon.ico
/usr/local/squid/var/cache/00/00/00000081 404    18838 http://img.baidu.com/js/tangram-1.3.0.js
 

给我留言

留言无头像?