推荐阅读:http://blog.s135.com/book/squid/chap06.html    squid中文权威指南

 http://fengzhilinux.blog.51cto.com/1343279/348486
 
squid笔记:
 
[root@zhaochj ~]# uname -r
2.6.32-220.el6.x86_64
[root@zhaochj ~]# tar -xf squid-3.2.0.19.tar.bz2 
[root@zhaochj ~]# cd squid-3.2.0.19
[root@zhaochj squid-3.2.0.19]# ./configure --prefix=/usr/local/squid --enable-gnuregex --enable-snmp --enable-delay-pools --enable-icmp --enable-cahce-digests --enable-poll --enable-linux-netfilter --enable-large-cache-files --enable-underscore --enable-arp-acl --enable-kill-parent-hack --enable-cachemgr-hostname=localhost --disable-ident-lookups
 
--enable-gnuregex :由于Squid大量使用字符串处理做各种判断,加入此项能更好的处理,激活使用GNU正则表达式。 
--enable-snmp :此选项可以让MRTG使用SNMP协议对服务器的流量状态进行监测,因此必须选择此项,使Squid支持SNMP接口。 
--enable-delay-pools 开启squid延时池功能
--enable-icmp :加入icmp支持 
--enable-cahce-digests :加快请求时,检索缓存内容的速度。
--enable-err-language=”Simplify_Chinese” 和 
--enable-default-err-languages=”Simplify_Chinese” :指定出错是显示的错误页面为简体中文 
--enable-poll :指定使用Poll()函数,提升性能就是啦。
--enable-linux-netfilter :可以支持透明代理 
--enable-large-cache-files开启大文件支持,支持2GB以上的文件
--enable-underscore :允许解析的URL中出现下划线,因为默认squid会认为带下划线的URL地址是非法的,并拒绝访问该地址
--enable-arp-acl :可以在规则设置中直接通过客户端的MAC地址进行管理,防止客户使用IP欺骗。
--enable-async-io=80 :等同于同时打开./configure如下三个选项
--with-aufs-threads=N_THREADS
--with-pthreads
--enable-storeio=ufs,aufs
这个主要是设置async模式来运行squid,我的理解是设置用线程来运行squid,如果服务器配置很不错,有1G以上内存,cpu使用SMP的方式的话可以考虑设成160或者更高。如果服务器比较糟糕就根据实际情况设了。另外此项还另cache文件支持aufs
--enable-kill-parent-hack :关掉suqid的时候,要不要连同父进程一起关掉
--enable-cachemgr-hostname=localhost:指定cachemgr-hostname值为localhost
--disable-ident-lookups允许服务器利用客户端的特殊TCP连接来发现用户名 
 
[root@zhaochj squid-3.2.0.19]# make && make install
[root@zhaochj squid-3.2.0.19]# useradd -s /sbin/nologin squid -M
[root@zhaochj squid-3.2.0.19]# chown -R squid.squid /usr/local/squid/var/logs/
[root@zhaochj squid-3.2.0.19]# chown -R squid.squid /usr/local/squid/var/cache/
[root@zhaochj squid-3.2.0.19]# cat /usr/local/squid/etc/squid.conf | grep -v '^#' | grep -v '^$' 查看配置文件(去除注释行与空白行)
[root@zhaochj squid-3.2.0.19]# echo "" > /usr/local/squid/etc/squid.conf
 
 
以下此配置为实现透明代理!
模型  client(192.168.1.100,gate:192.168.1.1)----->eth0(192.168.1.1):[   squid   ]:eth1:(192.168.133.130)<--------lamp服务器(192.168.133.140)
 
[root@zhaochj squid-3.2.0.19]# vi /usr/local/squid/etc/squid.conf   
#model
http_port 192.168.1.1:3128 transparent
#avisible_hostname zhaochj
cache_mgr root@localhost.localdomain
cache_effective_user squid
cache_effective_group squid
 
#cache limit
cache_dir ufs /usr/local/squid/var/cache 100 16 256
cache_mem 100 MB
cache_swap_low 90
cache_swap_high 95
cache_access_log /usr/local/squid/var/logs/access.log
cache_log /usr/local/squid/var/logs/cache.log
cache_store_log /usr/local/squid/var/logs/store.log
coredump_dir /usr/local/squid/var/cache
minimum_object_size 0 KB
maximum_object_size 10240 KB
pid_filename /usr/local/squid/var/logs/squid.pid
 
#acl limit
acl myclients src 192.168.1.0/24
acl query urlpath_regex .php .jsp .asp .pl .cgi
http_access deny query
http_access allow myclients
http_access deny all
保存退出!!
#avisible_hostname zhaochj       在以往版本中一定要加这一项,不然启动时会报错,但在3.2的版本中,加了反而还会报错,可能就像是“acc all src 0.0.0./0.0.0”一样,这些必须的参数默认已加上了。
 
[root@zhaochj squid-3.2.0.19]# /usr/local/squid/sbin/squid -k parse   测试配置文件语法
[root@zhaochj squid-3.2.0.19]# /usr/local/squid/sbin/squid -zX        初始化,生成cache目录!
[root@zhaochj squid-3.2.0.19]# /usr/local/squid/sbin/squid -s       启动
[root@zhaochj squid-3.2.0.19]# /usr/local/squid/sbin/squid -k shutdown  关闭
[root@zhaochj squid-3.2.0.19]# /usr/local/squid/sbin/squid -k reconfigure   重新读取配置文件
 
透明代理要配合iptables来实现
[root@zhaochj ~]# vi /etc/sysconfig/iptables.sh
#!/bin/bash
  /sbin/iptables -F
  /sbin/iptables -X
  /sbin/iptables -Z
  /sbin/iptables -F -t nat
  /sbin/iptables -X -t nat
  /sbin/iptables -Z -t nat
  /sbin/iptables -P INPUT   DROP
  /sbin/iptables -P OUTPUT  ACCEPT
  /sbin/iptables -P FORWARD ACCEPT
  /sbin/iptables -t nat -P PREROUTING  ACCEPT
  /sbin/iptables -t nat -P POSTROUTING ACCEPT
  /sbin/iptables -t nat -P OUTPUT      ACCEPT
#
   echo "1" > /proc/sys/net/ipv4/ip_forward 
  /sbin/iptables -A INPUT -i lo -j ACCEPT
  /sbin/iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  /sbin/iptables -A INPUT -i eth+ -p icmp --icmp-type 8 -j ACCEPT
#deny DDOS
  /sbin/iptables -A INPUT -p icmp -m icmp --icmp-type 8 -m limit --limit 6/min --limit-burst 2 -j ACCEPT
  /sbin/iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j REJECT --reject-with icmp-port-unreachable
#
  /sbin/iptables -A INPUT -p TCP -i eth0 --dport  22 -j ACCEPT
  /sbin/iptables -A INPUT -p TCP -i eth1 -s 192.168.1.0/24 -j ACCEPT
  /sbin/iptables -t nat -A PREROUTING -i eth1 -s 192.168.1.0/24 -p tcp --dport 80 --j REDIRECT --to 3128
[root@zhaochj ~]# chmod +x /etc/sysconfig/iptables.sh
[root@zhaochj ~]# echo "/etc/sysconfig/iptables.sh" >> /etc/rc.local
 
为了预防日志过于庞大,所以借助cron排程来定期滚动日志
[root@zhaochj ~]# crontab -e
40 15 * * * /usr/local/squid/sbin/squid -k rotate
[root@zhaochj ~]# service crond restart
 
 
 
反向代理实验
[client](192.168.133.1)--------->eth0:192.168.133.130[squid server]eth1:172.16.0.1--------->172.16.0.2[web server]
 
[root@zhaochj ~]# vi /usr/local/squid/etc/squid.conf
#model
http_port 192.168.133.130:80 vhost
cache_mgr root@localhost.localdomain
cache_effective_user squid
cache_effective_group squid
#cache limit
cache_dir ufs /usr/local/squid/var/cache 100 16 256
cache_mem 100 MB
cache_swap_low 90
cache_swap_high 95
cache_access_log /usr/local/squid/var/logs/access.log
cache_log /usr/local/squid/var/logs/cache.log
cache_store_log /usr/local/squid/var/logs/store.log
coredump_dir /usr/local/squid/var/cache
minimum_object_size 0 KB
maximum_object_size 10240 KB
pid_filename /usr/local/squid/var/logs/squid.pid
###
cache_peer 172.16.0.2 parent 80 0 originserver weight=1 max-conn=100
#acl limit
#acl query urlpath_regex .php .jsp .asp .pl .cgi
#http_access deny query
http_access allow all
保存退出!
 
 
在做反向代理时在启动squid时有警告:
2012/08/24 12:52:37| WARNING: http(s)_port: vhost option is deprecated. Use 'accel' mode flag instead.
 
 
暂时没找到原因,