现在的位置: 首页 > 综合 > 正文

Squid编译安装及基本配置

2013年07月11日 ⁄ 综合 ⁄ 共 4185字 ⁄ 字号 评论关闭

1、Squid编译安装参数说明

–prefix=/usr/local/squid :指定软件的安装路径
–enable-gnuregex :支持GNU正则表达式。
–disable-carp: Cache数组路由协议(CARP)用来转发丢失的cache到父cache的数组或cluste
–enable-async-io=240等同于同时打开./configure如下三个选项
--with-aufs-threads=N_THREADS
--with-pthreads
--enable-storeio=ufs,aufs
这个主要是设置async模式来运行squid,我的理解是设置用线程来运行squid,如果服务器配置很不错,有1G以上内存,cpu使用SMP的方式的话可以考虑设成160或者更高。如果服务器比较糟糕就根据实际情况设了。另外此项还另cache文件支持aufs
--disable-wccp用于阻止或分发HTTP请求到一个或多个caches
–enable-icmp :加入icmp支持
–enable-kill-parent-hack :关掉suqid的时候,要不要连同父进程一起关掉
--enable-cachemgr-hostname=localhost:指定cachemgr-hostname值为localhost
-- enable-snmp :此选项可以让MRTG使用SNMP协议对服务器的流量状态进行监测,因此必须选择此项,使Squid支持SNMP接口。
–disable-ident-lookups :防止系统使用RFC931规定的身份识别方法。
--enable-delay-pools 开启squid延时池功能
–enable-cahce-digests :加快请求时,检索缓存内容的速度。
–enable-err-language=”Simplify_Chinese” 和
–enable-default-err-languages=”Simplify_Chinese” :指定出错是显示的错误页面为简体中文
--with-maxfd=65535指定最大文件描述
–enable-poll :指定使用Poll()函数,提升性能就是啦。
--disable-ident-lookups允许服务器利用客户端的特殊TCP连接来发现用户名
–enable-linux-netfilter :可以支持透明代理
--enable-large-cache-files开启大文件支持,支持2GB以上的文件
--disable-internal-dns使用自己的内部DNS查询
–enable-underscore :允许解析的URL中出现下划线,因为默认squid会认为带下划线的URL地址是非法的,并拒绝访问该地址

–enable-arp-acl :可以在规则设置中直接通过客户端的MAC地址进行管理,防止客户使用IP欺骗。


安装实例:

#configure --prefix=/usr/local/squid \ 

--enable-gnuregex \ 

--disable-carp \ 

--enable-async-io=240 \ 

--with-pthreads \ 

--enable-storeio=ufs,aufs,diskd \ 

--disable-wccp \

–enable-icmp \

--enable-kill-parent-hack \ 

--enable-cachemgr-hostname=localhost \ 

--enable-default-err-language=Simplify_Chinese \ 

--with-maxfd=65535 \ 

--enable-poll \ 

--enable-linux-netfilter \ 

--enable-large-cache-files \ 

--disable-ident-lookups \ 

--enable-default-hostsfile=/etc/hosts \ 

--with-dl \ 

--with-large-files \ 

--enable-delay-pools \ 

--enable-snmp \ 

--disable-internal-dns \

–enable-underscore\

–enable-arp-acl

#make && make install

2、配置文件

# cat /etc/squid/squid.conf

配置文件相关说明

#定义acl访问控制元素:ip地址、端口
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1
acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7       # RFC 4193 local private network range
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines
acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
acl CONNECT method CONNECT
acl worktime time 8:00-23:59  //定义工作时间
acl worktime time 00:00-5:59
http_access allow mynetwork !worktime  //只允许非工作时间上网
访问控制设置
http_access allow manager localhost
http_access deny manager
# Deny requests to certain unsafe ports
http_access deny !Safe_ports  禁止非安全端口的访问
# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports
http_access allow localnet
http_access allow localhost
# And finally deny all other access to this proxy
http_access allow all   最好一条http_access设置默认访问规则
# Squid normally listens to port 3128
http_port 192.168.1.254:3128 transparent  代理服务器监听的地址及端口,transparent 为透明代理模式
# We recommend you to use at least the following line.
hierarchy_stoplist cgi-bin ?
# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /var/spool/squid 1000 8 128  配置缓存文件的文件格式,缓存大小,缓存目录数
# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid
# Add any of your own refresh_pattern entries above these.
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320
visible_hostname 192.168.1.254
cache_mem 128 MB  //squid服务器占用内存大小
forwarded_for off  //不传递被代理地址
via off //不传递代理服务器信息

三、初始化squid代理服务器

#squid -z
 开启路由功能,并将下面的命令写入/etc/rc.d/rc.local 文件,使其开机自动开启路由功能
#echo '1' >/proc/sys/net/ipv4/ip_forward

四、配置iptables防火墙

自动将http请求转发到代理服务器上
#iptables -t nat -A PREROUTING -i eth1 -p tcp  --dport 80 -j REDIRECT --to-ports 3128
设置源地址映射
#iptables -t nat -A POSTROUTING -j SNAT --to-source 192.168.1.254 (外网地址)
#iptables -P INPUT ACCEPT
启动squid代理服务
# service squid restart
查看squid代理服务器缓存日志
# tail -f /var/log/squid/access.log
个人感觉使用缓存服务器之后网页访问速度有大幅度的加快。

本文参考:http://www.liusuping.com/ubuntu-linux/squid-transparent-setting.html

抱歉!评论已关闭.