wget  http://www.squid-cache.org/Versions/v2/2.6/squid-2.6.STABLE6.tar.bz2

cd squid-2.6.STABLE6
./configure prefix=/usr/local/squid/ --with-maxfd=65536
make
make install

vi /usr/local/squid/etc/squid.conf
#########配置文件开始##########
http_port 192.168.1.50:80 vhost vport

#xx.xx.xx.xx为这台服务器的IP地址

icp_port 0

cache_mem 40 MB

#设置Squid所能使用的内存共400MB,这个值因人而异

cache_swap_low 80
cache_swap_high 95

maximum_object_size 2000 KB

#最大缓存文件大小,超过这个值则不缓存,这个值因人而异

maximum_object_size_in_memory 4096 KB

#装入内存缓存的文件大小,这个值对Squid的性能影响比较大,因为默认值是8K,超过8K的文件都不装入内存,而实际应用中很多网页和图片等都超过8KB, 个人认为如果缓存不装入内存而存在磁盘上,性能和apache直接读取磁盘文件没什么区别,甚至不如直接访问apache,现在设置成小于4兆的文件通通装入内存缓存.

cache_dir ufs /tmp1 1000 16 256

#磁盘缓存的类型和目录,大小,一二级目录的设置,这里磁盘缓存大小是1G

cache_store_log none

#这个设置是不记录store.log

emulate_httpd_log on

#打开emulate_httpd_log选项,将使Squid仿照Aapche的日志格式

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

#日志格式combined的设置

pid_filename /usr/local/squid/var/logs/squid.pid
cache_log /usr/local/squid/var/logs/cache.log
access_log /usr/local/squid/var/logs/access.log

#这里是设置pid和日志文件的位置,因人而异,同时日志格式是combined,awstats可以直接调用分析了

acl all src 0.0.0.0/0.0.0.0

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

#设置不想缓存的目录或者文件类型

http_access allow all  #####允许全部类型访问
#acl picurl url_regex -i \.bmp$ \.png$ \.jpg$ \.gif$ \.jpeg$
#acl mystie1 referer_regex -i aaa
#http_access allow mystie1 picurl
#acl mystie2 referer_regex -i bbb
#http_access allow mystie2 picurl

#设置防图片盗链的,其中aaa,和bbb分别是虚拟主机的域名,referer中必须包含有aaa或者bbb的域名才能访问图片

#acl nullref referer_regex -i ^$
#http_access allow nullref
#acl hasref referer_regex -i .+
#http_access allow hasref picurl

#设置允许直接访问图片和拒绝referer中没有包含aaa或着bbb的访问图片

cache_peer 192.168.1.10 parent 80 0 no-query originserver login=PASS

#xx.xx.xx.xx还是本机服务器的IP,81则是apache的端口,如果你的虚拟主机有用户名和密码保护起来的目录必须设置login=PASS,否则认证会失效

cache_effective_user squid
cache_effective_group squid

#squid使用的用户组和用户名


####配置文件结束######

####首次运行squid要先建立缓存###
useradd squid
groupadd squid
mkdir /tmp1
chown squid.squid /tmp1
/usr/local/squid/sbin/squid -z

###启动squid
#/usr/local/squid/sbin/squid


/usr/local/squid/sbin/squid -k shutdown   ###停止squid
/usr/local/squid/sbin/squid -k reconfigure  ###重新加载配置文件

tail -5 /usr/local/squid/var/logs/access.log  #####查看命中率