Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3286803
  • 博文数量: 266
  • 博客积分: 3081
  • 博客等级: 中校
  • 技术积分: 2640
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-04 10:35
个人简介

没什么好介绍的!穷屌丝一个~

文章分类

全部博文(266)

文章存档

2021年(3)

2020年(1)

2019年(2)

2016年(5)

2015年(1)

2014年(1)

2011年(9)

2010年(16)

2009年(31)

2008年(58)

2007年(111)

2006年(2)

2005年(26)

我的朋友

分类: LINUX

2009-06-18 22:03:51

转自:http://iyubo.blogbus.com/logs/37254471.html

其实本人实在是更喜欢一 些,而线上用来跑css/js等静态文件cache的Varnish也确实运行的非常好,缓存的命中率也很高,性能也很好。但是因为是内存式的 Cache,Varnish在缓存图片时当达到一定量的时候会出现无法分配内存导致重启子进程缓存丢失的情况。所以当图片数量级较大且访问量较大时,还是 老老实实用Squid吧。

安装环境
操作系统: CentOS release 5.2 (Final)
Kernel: 2.6.18-92.el5PAE

软件列表


软件存放位置
/data/software

安装过程
#/usr/sbin/groupadd squid -g 610
#/usr/sbin/useradd -u 610 -g squid squid
#mkdir /srv/scache
#chmod +w /var/vcache
#chown -R squid.squid /srv/scache
#mkdir /var/log/squid
#chmod +w /var/log/squid
#chown -R squid.squid /var/log/squid
#cd /data/software/pkg
#tar zxvf ../squid-2.6.STABLE22.tar.gz
#cd squid-2.6.STABLE22
#./configure --prefix=/usr/local/squid
#make && make install

编辑Squid配置文件
#vi /usr/local/squid/etc/squid.conf

-------------------------华丽的分割线,以下都是配置文件内容----------------------------
#定义acl项名称
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443
acl Safe_ports port 80
acl safeprotocol protocol HTTP
acl test dstdomain .test.com
acl CONNECT method CONNECT

#定义acl规则
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access deny to_localhost

http_access allow safeprotocol Safe_ports test
http_access deny all
icp_access allow all

#squid监听端口
http_port 80 accel defaultsite=59.151.32.58 vhost

always_direct allow all

#后端服务器
cache_peer 10.10.10.8 parent 80 0 no-query originserver

hierarchy_stoplist cgi-bin ?

#内存cache大小
cache_mem 2048 MB

#内存cache中最大的object大小(超过这个值则不进入内存cache)
maximum_object_size_in_memory 8 KB

#内存cache的替换规则
memory_replacement_policy lru

#硬盘cache的替换规则
cache_replacement_policy lru

#磁盘cache目录(文件类型 cache目录路径 cache目录大小 二级目录个数 每个二级目录下的三级目录个数)
cache_dir ufs /srv/scache 40000 16 256

#磁盘cache中最小的object的大小(低于这个值则不缓存)
minimum_object_size 0 KB

#磁盘cache中最大的object的大小(超过这个值则不缓存)
maximum_object_size 2048 KB

cache_swap_low 90
cache_swap_high 95

#定义日志格式
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %h" "%{User-Agent}>h" %Ss:%Sh

#记录相关日志
access_log /var/log/squid/access.log squid
cache_log /var/log/squid/cache.log
cache_store_log /var/log/squid/store.log

#日志rotate(24则后缀从.0到.23)
logfile_rotate 24

emulate_httpd_log on

#如果你的URL里面带有?,这两行一定要注销掉
#acl QUERY urlpath_regex cgi-bin \?
#cache deny QUERY

#配置自动更新(关于后面的三个值请参考Squid配置手册)
refresh_pattern -i \.jpg$ 60 80% 1440
refresh_pattern -i \.png$ 60 80% 1440
refresh_pattern -i \.gif$ 60 80% 1440

quick_abort_min 16 KB
quick_abort_max 16 KB
quick_abort_pct 95

request_header_max_size 10 KB
reply_header_max_size 10 KB

acl apache rep_header Server ^Apache
broken_vary_encoding allow apache

#相关timeout设置
forward_timeout 4 minutes
connect_timeout 3 minutes
peer_connect_timeout 30 seconds
read_timeout 15 minutes
request_timeout 1 minute
persistent_request_timeout 3 minutes
half_closed_clients off
pconn_timeout 1 minute

#cache管理员邮箱
cache_mgr webmaster@test.com

cache_effective_user squid
cache_effective_group squid

#squid服务器的visible_hostname,此处指定的值显示在Squid响应的Header里面的X-Cache项中
visible_hostname squidserver

coredump_dir /var/log/squid/cache

------------------------华丽的分割线,以上都是配置文件内容-----------------------------


初始化squid缓存目录
#/usr/local/squid/sbin/squid -z

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

配置完成以后,最重要最重要的一点,修改Squid服务器的hosts文件,将需要Cache的域名指向到后端的服务器IP上

相关命令

停止squid
/usr/local/squid/sbin/squid -k shutdown

启用新配置
/usr/local/squid/sbin/squid -k reconfig

通过crontab每小时截断/轮循日志
59 * * * * /usr/local/squid/sbin/squid -k rotate

查看squid运行状况
/usr/local/squid/bin/squidclient -p 80 mgr:info
/usr/local/squid/bin/squidclient -p 80 mgr:5min

查看squid内存使用情况
/usr/local/squid/bin/squidclient -p 80 mgr:mem

查看squid磁盘使用情况
/usr/local/squid/bin/squidclient -p 80 mgr:diskd

查看squid已缓存列表(小心使用,可能会导致crash)
/usr/local/squid/bin/squidclient -p 80 mgrbjects

强制更新某个url
/usr/local/squid/bin/squidclient -p 80 -m PURGE

查看squid缓存到内存cache中并返回给访问用户的项
#cat /var/log/squid/access.log | grep TCP_MEM_HIT

查看squid缓存到磁盘cache中并返回给访问用户的项
#cat /usr/local/squid/var/logs/access.log | grep TCP_HIT

查看没被squid缓存住,直接从原始服务器获取并返回给访问用户的项
#cat /usr/local/squid/var/logs/access.log | grep TCP_MISS

关于 TCP_XXXX 等参数及代表的信息,请参考《squid中文权威指南》13.2.1 章节。

更多参数
/usr/local/squid/bin/squidclient -h
/usr/local/squid/bin/squidclient -p 80 mgr:menu

参考文档


找到一篇的文章,来自扶凯

阅读(1679) | 评论(0) | 转发(0) |
0

上一篇:PPPD指令意义

下一篇:linux网桥

给主人留下些什么吧!~~