Squid 基本配置

1、编译安装:
     从squid 网站下载, http://www.squid-cache.org/Versions/
     解压缩:tar -zxvf squid-3.2.1.tar.gz 
     进入解压后目录:cd squid-3.2.1
*********************************************************
     参见网站: http://wiki.squid-cache.org/SquidFaq/InterceptionProxy
     For Linux configure Squid with the --enable-linux-netfilter option. 
     For *BSD-based systems with IP filter configure Squid with the --enable-ipf-transparent option. 
     If you're using OpenBSD's PF configure Squid with --enable-pf-transparent. 
*************************************************************
      a. configure
      ./configure '--enable-linux-netfilter' '--enable-ssl'   ----开启透明模式 和 https
      查看报错
      ./configure --enable-linux-netfilter | grep error
      ./configure --enable-linux-netfilter | grep WARNING 
      自行查看是否有报错,本例缺少libcap 库,可以从linux 安装光盘安装
       mount -t nfs x.x.x.x:/home/partimag/iso/RH6 /mnt      mount nfs server
       mount -t auto /dev/cdrom /mnt/cdrom       或者mount linux 本地光盘
       mount -o loop isofile.iso /mnt/iso                或者mount linux iso
       进入cd Packages/    目录下
       ls libcap*   list 出所有libcap 的包
        rpm -ivh libcap-2.16-5.2.el6.x86_64.rpm  逐一安装libcap 的包
      再次configure
      进入解压后目录:cd squid-3.2.1
      重复上面步骤,确定无错后 继续进行
    
       b. make 
      无错完成后使用:make all
      进入 cd src/ 目录下
      查看./squid -version 版本
      Squid Cache: Version 3.2.1
      configure options:  '--enable-linux-netfilter' '--enable-ssl' --enable-ltdl-convenience      表示已经开启transparent 模式
 
       c. make install
      make install   接着安装  没有错误的话 表示安装上了
   
       d. 建立bash link
    使用which squid   查看squid 是否被 shell link 上
     如果为link 上 使用  vi ~/.bash_profile   
     增加 PATH=$PATH:/usr/local/squid/bin:/usr/local/squid/sbin
     source ~/.bash_profile  看是否有报错
      再次使用which squid   查看squid 是否被 shell link 上
      /usr/local/squid/sbin/squid  看到这样表示正常
   
2、启动squid:
     进入到squid 目录下 
      cd /usr/local/squid/
     使用chown -R nobody var 将var目录权限调整(因为要写入log)
     使用 squid -N -dl   此命令检查 看配置是否还有错误
    [root@proxy01 etc]# squid -N -dl
    2012/09/28 18:02:16| Starting Squid Cache version 3.2.1 for x86_64-unknown-linux-gnu...
    表示已经成功启动
     [root@proxy01 etc]# netstat -an | grep 3128
     tcp        0      0 0.0.0.0:3128                0.0.0.0:*                   LISTEN     
    
     [root@Proxy squid]# ps -elf | grep squid    查看进程 是否启动 
     1 S root     17724     1  0  80   0 - 15597 wait   02:57 ?        00:00:00 squid
     4 S nobody   17726 17724  0  80   0 - 21482 epoll_ 02:57 ?        00:00:06 (squid)
     0 S root     19185 16209  0  80   0 - 25788 pipe_w 04:38 pts/2    00:00:00 grep squid     
   
    如果以上都正常表示安装成功,已经正常启动。
 
3、编辑squid配置:
     a.建立证书:
     进入到squid 的etc 目录下
      cd /usr/local/squid/etc/
     openssl req -new -keyout key.pem -nodes -x509 -days 365 -out cert.pem
     b.编辑squid 配置文件:
     vi squid.conf
    设定以下几个网址的https 要转发
    acl forwarded_https dstdomain  .facebook.com .youtube.com .ytimg.com
    never_direct allow forwarded_https
    
    开启https 和 http 端口及transparent 模式
    https_port 3129 cert=/usr/local/squid/etc/cert.pem key=/usr/local/squid/etc/key.pem transparent
    http_port 3128 transparent
    指定要转发的地址
   cache_peer x.x.x.x parent 3128 0
   cache_peer_domain x.x.x.x .facebook.com
   cache_peer_domain x.x.x.x .youtube.com
   cache_peer_domain x.x.x.x .ytimg.com
 
   以上全部为新增部分,配置文件 下方 有 http_port 3128   将此注销掉,在这句前面加上# 即可 
 
   保存退出,直接 按下ESC 然后 输入wq 就好了
   squid -k reconfigure  重启squid   
   到此squid 基本配置完成。

4、配置iptable:
    chkconfig --list | grep iptable   查看linux firewall 是否有安装
    [root@Proxy02 etc]# chkconfig --list | grep iptables
    iptables        0:off   1:off   2:on    3:on    4:on    5:on    6:off
    如果看到3是 off 的  使用命令   chkconfig iptables on 将其设定为开机启动
    iptable 设定:
    iptables -t nat -A PREROUTING -i eth0 -s ! x.x.x.x  -p tcp --dport 80 -j REDIRECT --to-port 3128   - ---将80 和 443 的包转发给自己。
    iptables -t nat -A PREROUTING -i eth0 -s ! x.x.x.x  -p tcp --dport 443 -j REDIRECT --to-port 3129
    查看iptable 设定
     iptables -t nat -L
    清空iptables 
     service iptables restart
    保存iptable 设定
     service iptables save
    查看iptables 保存文件:
     more /etc/sysconfig/iptables
     设定开机启动iptables
      chkconfig iptables on
     查看开机设定
     chkconfig --list |grep iptables
 
5、查看squid 的log :
     
     tail -f /usr/local/squid/var/logs/access.log    可以及时查看squid proxy 的情况
     1344889177.913   2379 x.x.x.x  TCP_MISS/200 2393 GET http://img.finance.qq.com/images/hq_parts_little3/hushen/indexs/000001.png - DIRECT/58.251.58.60 image/png
     表示直连访问
     1344886846.356    506 x.x.x.x  TCP_MISS/200 404 GET  http://hit.icbc.com.cn/image/hitcount.gif? - FIRST_UP_PARENT/172.21.83.242 image/gif
     表示forward to HQ proxy
 
6、squid 优化配置 :
     cache_dir ufs /usr/local/squid/var/cache/squid 61440 64 512      ------61440  是给cache 的空间大小,本身没有限制,看你的硬盘多大,64,512 是 L1 L2 的缓存目录数在/usr/local/squid/var/cache/squid下
     cache_swap_low 90                                                             ------当cache高于95%的时候开始删除cache,直到保持90%的cache容量
     cache_swap_high 95
     cache_mem 2048 MB                                                           ------设定squid 说消耗的 内存大小(一般建议为物理内存的3/1)
     maximum_object_size_in_memory 16 MB                                -------设定对象的最大尺寸,4KB 的倍数               
     memory_pools on                                                                -------预先分配一定的内存用于cache,以提高效率,默认on
     memory_pools_limit 2048 MB                                                --------分配内存值的大小
     保存退出后:
     必须使用 squid -z 初始化cache 目录,再次确定下 权限问题,如果权限有问题再使用chown -R nobody var 将var目录权限调整    
     然后再重新启动 squid -k reconfigure
 
7、squid 优化配置2 :
     完成以上配置后, squid 经常会占用CPU 100%
     WARNING! Your cache is running out of filedescriptors    CPU 持续100%
      解决办法:
      1. /etc/squid/squid.conf
      最後一行新增 max_filedesc 60000
      设定完后:
      /usr/local/squid/bin/squidclient -p 3128 mgr:info 
      查看squid 的设定
       File descriptor usage for squid:
        Maximum number of file descriptors:   60000
        Largest file desc currently in use:   1773
        Number of file desc currently in use: 1323
        Files queued for open:                   0
        Available number of file descriptors: 58677
        Reserved number of file descriptors:   100
        Store Disk files open:                   6
      2. 每次squid 执行前要先执行一下 ulimit -HSn 65536  (目前我还没找到有效的 永久更改方法)
      [root@Proxy02 bin]# ulimit -n
      65535
 
8、https forward :
     HTTP 和HTTPS 的 forward   从transparent 的这台 squid ,forward 到另一台 squid 的时候 另外一台 squid 不能用transparent 模式
     (forward 到bluecoat proxy 也是不行)
     另外一台squid 配置较为简单
     不用transparent 就好了
     https_port 3129 cert=/usr/local/squid/etc/cert.pem key=/usr/local/squid/etc/key.pem
     http_port 3128
 
9、serveriron 的TCS :
     server cache-name proxy02 x.x.x.x         ---------指定cache server IP
     port ssl                                                        ----------指定cache server 的port 443
     port http                                                     ----------指定cache server 的port 80
     port http url "HEAD /"
                                                          
    server cache-group 1                                      ----------指定cache server group
     acl-id 130                                                     ----------调用是否要bypass squid 的policy
     cache-name proxy02                                      ----------添加cache server 到group 中
    vlan 1 name DEFAULT-VLAN by port                                  
     no spanning-tree
    ip address x.x.x.x 255.255.255.0
    ip default-gateway x.x.x.x 
    ip policy 1 cache tcp http global                       ----------应用cache http  TCS 到所有端口
    ip policy 2 cache tcp ssl global                          ----------应用cache https  TCS 到所有端口
    interface e 3    
    no cache-group                                            ----------本端口不启用TCS
    access-list 130 permit tcp any 69.171.0.0 0.0.255.255 eq ssl   ----------设定facebook的https 经过TCS 导入到squid 
    access-list 130 permit tcp any 66.220.0.0 0.0.255.255 eq ssl   ----------设定facebook的https 经过TCS 导入到squid 
    access-list 130 permit tcp any 68.178.0.0 0.0.255.255 eq ssl   ----------设定facebook的https 经过TCS 导入到squid 
    access-list 130 deny tcp any any eq ssl   -------------------------------------设定非facebook的https全部bypass 不经过TCS 导入到squid 
    access-list 130 permit ip any any ----------------------------------------------设定其它经过TCS 导入到squid 的access-list
 
10、squid 常用命令 :
    squid -N -dl                       --------检查squid 启动是否有错误
    squid -k reconfigure           --------在更新完squid.conf后重新启动squid
    squid -k shutdown            ---------关闭squid
    tail -f /usr/local/squid/var/logs/access.log             ---------查看access.log
    tail -f /usr/local/squid/var/logs/cache.log             ----------查看cache.log
    /usr/local/squid/bin/squidclient -p 3128 mgr:info   ---------查看squid 的状态,可以看到hit 率是多少
   
11、redhat 6 linux 添加永久路由:
     touch /etc/sysconfig/network
     vi /etc/sysconfig/network  
     any net x.x.x.x gw x.x.x.x 
     保存退出
     service network restart
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值