• RSS订阅
  • 交换链接
  • 首页

Jeffrey’s Blog

Web&P2P系统架构及优化


squid安装配置笔记(反向代理)

February 5th, 2007

作者: Jeffrey
出处: http://blog.zhangjianfeng.com/article/531
=====安装部分=====
下载最新版
wget http://www.squid-cache.org/Versions/v2/2.6/squid-2.6.STABLE9.tar.bz2 -P /tmp
cd /tmp
tar jxf squid-2.6.STABLE9.tar.bz2
cd squid-2.6.STABLE9
./configure –prefix=/app/squid2.6.9 –enable-snmp –with-maxfd=65536  –with-large-files && make && make install

=====配置文件=====
cache_swap_low 90
cache_swap_high 95
cache_mem 1024 MB
maximum_object_size 20000 KB
maximum_object_size_in_memory 4096 KB     #装入内存缓存的文件大小,默认值是8K,超过8K的文件都不装入内存,可以在这里设成4M.
cache_dir ufs /tmp1 10000 16 256      #磁盘缓存的类型和目录,大小,一二级目录的设置,这里磁盘缓存大小是10G

acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe
cache deny QUERY  #设置不想缓存的目录或者文件类型

###相关日志记录,可以设为none成不记录日志####
logfile_rotate 5 #表示保存5个轮循日志
cache_mgr admin@zhangjianfeng.com
emulate_httpd_log on
logformat combined %>a %ui %un [%tl] “%rm %ru HTTP/%rv” %Hs %<st “%{Referer}>h” “%{User-Agent}>h” %Ss:%Sh
pid_filename /jeffrey/app/squid/var/logs/squid.pid
cache_store_log /var/log/squid/store.log
cache_log /var/log/squid/cache.log
access_log /var/log/squid/access.log combined

###设置防图片盗链,其中aaa.com和bbb.com分别是虚拟主机的域名,referer中必须包含有aaa.com或bbb.com的域名才能访问图片####
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

#考虑有些referer为空的情况
acl nullref referer_regex -i ^$
http_access allow nullref
#其它referer,直接拒绝访问
acl hasref referer_regex -i .+
http_access deny hasref picurl

###反向代理###
http_port xxx.xxx.xxx.:81 vhost vport
cache_peer xx.xx.xx.xx parent 81 0 no-query originserver

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

#### 各种文件控制,注意位置 ####
refresh_pattern -i .html 10 90% 2160 reload-into-ims
refresh_pattern -i .shtml 10 90% 2160 reload-into-ims
refresh_pattern -i .htm 10 90% 2160 reload-into-ims
refresh_pattern -i .gif 60 90% 2160 reload-into-ims
refresh_pattern -i .swf 60 90% 2160 reload-into-ims
refresh_pattern -i .jpg 60 90% 2160 reload-into-ims
refresh_pattern -i .png 60 90% 2160 reload-into-ims
refresh_pattern -i .bmp 60 90% 2160 reload-into-ims
refresh_pattern -i .js 10 90% 2160 reload-into-ims

#限制同一IP客户端的最大连接数
acl OverConnLimit maxconn 16
http_access deny OverConnLimit

#防止被人利用为HTTP代理,设置允许访问的IP地址
acl myip dst 192.168.1.1
http_access deny !myip

#Squid信息设置
visible_hostname http://www.zhangjianfeng.com/
cache_mgr webmaster@zhangjianfeng.com

#错误文档
#error_directory ../squid/share/errors/Simplify_Chinese

#虚拟主机反向代理
#cache_peer w1.aa.com parent 80 0 no-query originserver
cache_peer 192.168.0.10 parent 80 0 no-query originserver name=testserver80
cache_peer_domain testserver80 http://www.testserver81.com/
cache_peer 192.168.0.11 parent 81 0 no-query originserver name=testserver81
cache_peer_domain testserver81 www.testserver82.com
cache_peer_domain testserver81 www.test182.com

####squid.conf 结束####

++启动
squid -z
echo “65535″ > /proc/sys/fs/file-max
ulimit -HSn 65535
squid -NCd1 #来以debug模式启动,加-D选项来可不检查DNS启动squid

=====其它=====
++遇到故障,runcache发现频繁重启后停止服务:
:./bin/RunCache  Running: squid -sY  >> /usr/local/squid//var/squid.out 2>&1
./bin/RunCache: line 35: 20000 File size limit exceededsquid -NsY $conf >>$logdir/squid.out 2>&1
..中间省去几行….
./bin/RunCache: line 35: 20177 File size limit exceededsquid -NsY $conf >>$logdir/squid.out 2>&1
RunCache: EXITING DUE TO REPEATED, FREQUENT FAILURES
故障原因: log超过了ext3文件系统最大支持容量2G导致,解决办法:
1)每天轮循一次日志0 0 * * * /usr/local/squid/sbin/squid -k rotate
2)直接在配置文件中禁用日志
access_log none
cache_store_log none

++查看信息
1)squidclient -h 218.85.132.65 -p 80 mgr:info #也可看到描述符
2)看cache.log,如果能看到很多的TCP_MEM_HIT,这说明该文件是从内存缓存读取的,其它如TCP_HIT等等,这些是从磁盘读取的,这个只不过能缓解apache的压力而已.

++apache的log显示ip来源都是127.0.0.1,修改配置文件使其可以正常记录来访IP
将CustomLog的%h改为%{X-Forwarded-For}i,其它不变.

++ 限制外网电脑使用代理,只允许IP为192.168.0.2~192.168.0.255的机器访问。
acl our_clients src 192.168.0.0/255.255.255.0
acl other_clients src 0.0.0.0/0.0.0.0
http_access allow our_clines
http_access deny other_clients   (禁止其他用户通过本机上网)

++快速清空cache
echo ” ” > $CachePath/caches/swap.state

ps:用squid做代理网关的学习笔记 http://blog.zhangjianfeng.com/?p=630

Last modified at: Thursday, July 24th, 2008 09:48:42 am
Trackback URL: http://blog.zhangjianfeng.com/article/531/trackback

给本文打分: 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Tags: squid, 下载, 使用, 学习, 安装, 笔记, 配置, 配置文件
2007/02/5 | 阅读全文 | 应用服务, 电脑网络 | Email This Post | Print This Post | 2,146 views |
收藏到网摘: Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网

Related Post

  • Sunday, March 11th, 2007 -- Cygwin安装配置笔记
  • Friday, March 31st, 2006 -- MySQL学习笔记
  • Monday, September 3rd, 2007 -- squid代理网关笔记
  • Thursday, June 28th, 2007 -- freebsd 6.2 安装配置笔记
  • Friday, March 30th, 2007 -- linux下ntpd安装配置笔记
  • Saturday, October 7th, 2006 -- “中文垃圾邮件过滤规则集”安装配置笔记
  • Sunday, April 30th, 2006 -- [转]samba3.0实战演练
  • Friday, June 6th, 2008 -- xen安装及配置笔记
  • Wednesday, December 26th, 2007 -- mysql主从服务器的配置笔记
  • Saturday, December 22nd, 2007 -- suse 学习笔记

0 Responses to “squid安装配置笔记(反向代理)”


  1. No Comments

Leave a Reply

  • :em04:
  • :em18:
  • :em17:
  • :em10:
  • :em01:
  • :em05:
  • :em15:
  • :em07:
  • :em03:
  • :em13:
  • :em09:
  • :em12:
  • :em11:
  • :em06:
  • :em16:
  • :em14:
  • :em02:
  • :em08:

« 系统报错ip_conntrack满的解决方法
sed学习笔记 »

    最新文章

    • Subversion的用户自助修改口令实现(linux测试通过)
    • SLES10-SP1+Apache-2.0.63+SVN-1.4.6安装配置笔记
    • [音乐欣赏]A place nearby
    • 不错的firefox插件---鼠标手势mouse gestures
    • 一些相克食品
    • oracle一次数据迁移笔记
    • 不错的vi-vim键盘图(中英文双版)
    • xen安装及配置笔记
    • Multiple network cards and bridges in Xen[zz]
    • 从LiveJournal后台发展看大规模网站性能优化方法[zz]

    评分最高文章

      • 今天下载的一个CHM文件,打开时右边的内容看不到,提示“该页无法显示”。
      • linux日志服务器配置笔记
      • Legato networker学习笔记(杂)
      • linux tips 技巧笔记
      • [BT下载]2006韩剧-葡萄园的那小伙儿
      • 我家的金吉拉
      • 卡巴斯基病毒库离线更新方法
      • 忽悠姐妹花主题曲下载
      • 轻轻松松把 Apache 配置安全
      • 北京IDC机房介绍

    随机文章:

    • 在 Oracle 数据库 10g中轻松进行响应时间分析[zz]
    • smoothwall发布VPN
    • FC5硬盘安装笔记
    • 12星座在2006年的运势
    • 使用Windows 系统性能监控来报警磁盘空间不足
    • 职场生存七大勇气不可少~
    • ICP备案通过纪念
    • 你的左脑活跃还是右脑更活跃?
    • 给准备买第一部车的筒子们,补
    • 从运行 Microsoft Windows Server 2003 的服务器上迁移 DHCP 数据库

    最新评论

    • very good :em02: ,I like very much !!...
    • :em03: :em13: :em15: :em07...
    • 北京电信通有四个机房1惠普机房 2中...
    • :em04: :em18: :em17...
    • 结婚的好日子啊8月10...
    • c2950-1-1(config)# snmp-server trap-source FastEt...
    • :em16: :em16: :em16: :em16: :em16: :em16: :...
    • :em01: :em07: :em04: :em17: :em10: :em18: :...
    • 我是天称座 :em14: :em15: :em03: :em02: :...
    • [...] 前面一段:1.3.6.1.4.1. 可以查看这...


    邮件订阅  
  • Categories

    • 个人日志 (15)
    • 休闲娱乐 (79)
    • 应用服务 (86)
    • 影音娱乐 (10)
    • 电脑网络 (78)
    • 站点日志 (19)
    • 系统管理 (242)
    • 英语学习 (15)
    • 衣食住行 (41)
    • 资料共享 (28)
  • 工具网址

    • 天气预报
    • 常用电话
    • 疾病查询
    • 在线翻译
    • Alexa排名查询
    • IP信息查询
    • 邮箱图标生成
    • 我的Firefox插件
  • 友情链接

    • linuxの飘扬
    • winter的平凡生活
    • 伤感星星的天空
    • 回忆未来[张宴]
    • 存储部落
    • 扶凯Blog
    • 沐宇春风
    • 爱MySQL中文网
    • 狗.车.志
    • 非礼勿视
  • Tags

    • 下载 优化 使用 免费 北京 升级 学习 学习笔记 安装 工具 技巧 日志 最新 服务器 笔记 英语学习 菜谱 视频 解决 调优 软件 运程 配置 配置文件 食物 2007 apache blog dreamhost freebsd Legato linux mysql networker oracle php RAID5 RedHat sendmail shell squid suse Ubuntu windows wordpress

Jeffrey's Blog is powered by WordPress 2.3.1 and Unnamed 1.22
Entries (RSS) and Comments (RSS) Admin 京ICP备06038449号

Podcast Powered by podPress (v8.8)