本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
31


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7594288
建立时间:2006年5月29日




[网站架构]安装Squid
软件技术

lhwork 发表于 2007/1/18 12:47:34

 安装Squid[root@localhost]#./configure --prefix=/usr/local/server/squid --enable-async-io=100 --disable-delay-pools \ --disable-mem-gen-trace --disable-useragent-log --enable-kill-parent-hack --disable-arp-acl \ --enable-epoll --disable-ident-lookups --enable-snmp --enable-large-cache-files --with-large-files [root@localhost]#make && make install 如果是2.6的内核,才能支持epoll的IO模式,旧版本的内核则只能选择poll或其他模式了;另外,记得带上支持大文件的选项,否则在access log等文件达到2G的时候就会报错。设定 squid 的配置大概如下内容:#设定缓存目录为 /var/cache1 和 /var/lib/squid,每次处理缓存大小为128MB,当缓存空间使用达到95%时 #新的内容将取代旧的而不直接添加到目录中,直到空间又下降到90%才停止这一活动 #/var/cache1 最大1024MB,/var/lib/squid 最大 5000MB,都是 16*256 级子目录 cache_dir aufs /var/cache1 1024 16 256 cache_dir aufs /var/lib/squid 5000 16 256 cache_mem 128 MB cache_swap_low 90 cache_swap_high 95 #设置存储策略等 maximum_object_size 4096 KB minimum_object_size 0 KB maximum_object_size_in_memory 80 KB ipcache_size 1024 ipcache_low 90 ipcache_high 95 cache_replacement_policy lru memory_replacement_policy lru #设置超时策略 forward_timeout 20 seconds connect_timeout 15 seconds read_timeout 3 minutes request_timeout 1 minutes persistent_request_timeout 15 seconds client_lifetime 15 minutes shutdown_lifetime 5 seconds negative_ttl 10 seconds #限制一个ip最大只能有16个连接 acl OverConnLimit maxconn 16 http_access deny OverConnLimit #限制baidu spider访问 #acl AntiBaidu req_header User-Agent Baiduspider #http_access deny AntiBaidu #常规设置 visible_hostname cache.yejr.com cache_mgr webmaster@yejr.com client_persistent_connections off server_persistent_connections on cache_effective_user nobody cache_effective_group nobody tcp_recv_bufsize 65535 bytes half_closed_clients off #设定不缓存的规则 hierarchy_stoplist cgi-bin acl QUERY urlpath_regex cgi-bin cache deny QUERY #不要相信ETag 因为有gzip acl apache rep_header Server ^Apache broken_vary_encoding allow apache #设置access log,并且令其格式和apache的格式一样,方便awstats分析 emulate_httpd_log on logformat apache %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs % 初始化和启动squid [root@localhost]#/usr/local/server/squid/sbin/squid -z [root@localhost]#/usr/local/server/squid/sbin/squid 第一条命令是先初始化squid缓存哈希子目录,只需执行一次即可。 一、)想要启用squid所需的改变想要更好的利用squid的cache功能,不是把它启用了就可以的,我们需要做以下几个调整:1、启用apache的 mod_expires 模块,修改 httpd.conf,加入以下内容:#expiresdefault "modification plus 2 weeks"expiresactive onexpiresbytype text/html "access plus 10 minutes"expiresbytype image/gif "modification plus 1 month"expiresbytype image/jpeg "modification plus 1 month"expiresbytype image/png "modification plus 1 month"expiresbytype text/css "access plus 1 day"expiresbytype application/x-shockwave-flash "access plus 3 day"以上配置的作用是规定各种类型文件的cache规则,对那些图片/flash等静态文件总是cache起来,可根据各自的需要做适当调整。2、修改 php.ini 配置,如下:session.cache_limiter = nocache以上配置的作用是默认取消php中的cache功能,避免不正常的cache产生。3、修改应用程序例如,有一个php程序页面static.php,它存放着某些查询数据库后的结果,并且数据更新并不频繁,于是,我们就可以考虑对其cache。只需在static.php中加入类似如下代码:header('Cache-Control: max-age=86400 ,must-revalidate');header('Pragma:');header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT' );header("Expires: " .gmdate ('D, d M Y H:i:s', time() + '86400' ). ' GMT');以上代码的意思是,输出一个http头部信息,让squid知道本页面默认缓存时长为一天。二、)squidclient简要介绍*取得squid运行状态信息: squidclient -p 80 mgr:info*取得squid内存使用情况: squidclient -p 80 mgr:mem*取得squid已经缓存的列表: squidclient -p 80 mgr:objects. use it carefully, it may crash*取得squid的磁盘使用情况: squidclient -p 80 mgr:diskd*强制更新某个url: squidclient -p 80 -m PURGE http://www.yejr.com/static.php*更多的请查看:squidclient -h 或者 squidclient -p 80 mgr:最后祝大家的服务器越跑越欢 :)


阅读全文(1854) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.313 second(s), page refreshed 144765457 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号