Squid 3的多域名加速基本配置
<div style="font-size: 14px;">Squid是一种在Linux系统下使用的优秀的代理服务器软件,可以作为缓存加速服务和CDN服务使用。squid不仅可用在Linux系统上,还可以用在AIX、Digital Unix、FreeBSD、HP-UX、Irix、NetBSD、Nextstep、SCO和Solaris等系统上。
首先不用我说了 肯定是要在服务器安装Linux操作系统了,我们这里推荐使用CentOS.个人比较喜欢这个。
安装好CentOS后,我们利用SSH登陆进超级终端做一下必要的更新。
#yum install -y make gcc-gcc+ autoconf sudo wget libtool-ltdl-devel gd-devel freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel curl-devel patch libmcrypt-devel libmhash-devel ncurses-devel 更新完后我们开始安到http://www.squid-cache.org上下载最新的Squid3x稳定版本装Squid.
#groupadd squid
#useradd -s /sbin/nologin -d /dev/null -g squid squid
#wget http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE15.tar.gz
用tar命令把文件解压出来 进入squid目录进行编译安装
#./configure --prefix=/usr/local/squid --enable-follow-x-forwarded-for --enable-storeio=aufs,ufs --with-maxfd=65536 --with-pthreads --enable-dlmalloc --enable-poll --enable-stacktraces --enable-removal-policies=heap,lru --enable-delay-pools
#make(这里可能会编译很久 请耐心等待)
#make install(安装也是一样)
安装完成后,我们进入/usr/local/squid/etc目录编写squid.conf文件。可以把自带的删除 然后自己用vi命令重新写一份,这样比较快。
配置文件如下
# squid conf etc/squid.conf# Last Updated 2010.11.20
###cache_effective_user squidcache_effective_group squidtcp_recv_bufsize 65535 bytesicp_port 0visible_hostname cdncache(为squid缓存服务器名称,每台服务器建议取不同的名字,便于区别)http_port 80 vhost vport
#domains(以下为加速的站点)cache_peer www.linuxidc.com parent 80 0 no-query originserver name=site1cache_peer www.linuxidc.net parent 80 0 no-query originserver name=site2
#peer_domaincache_peer_domain site1 www.linuxidc.comcache_peer_domain site2 www.linuxidc.net
#aclacl local src 127.0.0.1acl Manager proto cache_objectacl purge method PURGEhttp_access allow Manager local purgehttp_access deny Manager purgeacl alls src allhttp_access allow alls
###cache,dircache_log /usr/local/squid/var/logs/cache.logaccess_log /usr/local/squid/var/logs/access.log squidcache_dir ufs /usr/local/squid/var/cache/ 10000 16 256maximum_object_size 1024 KBmaximum_object_size_in_memory 1024 KBcache_mem 512 MBcache_swap_low80cache_swap_high 90ipcache_size 512ipcache_low 90ipcache_high 95fqdncache_size 512
### timeoutconnect_timeout 1 minutepeer_connect_timeout 30 secondsrequest_timeout 2 minutespersistent_request_timeout 30 secondsdns_children 3hierarchy_stoplist cgi-bin ?
#refresh_patternrefresh_pattern ^ftp: 1440 20% 10080refresh_pattern ^gopher: 1440 0% 1440refresh_pattern -i (/cgi-bin/|\?) 0 0% 0refresh_pattern -i \.jpg$ 43200 50% 86400refresh_pattern -i \.png$ 43200 50% 86400refresh_pattern -i \.css$ 43200 50% 86400refresh_pattern -i \.js$ 43200 50% 86400refresh_pattern -i \.xml$ 43200 50% 86400refresh_pattern -i \.htm$ 43200 50% 86400refresh_pattern -i \.html$ 43200 50% 86400refresh_pattern . 0 20% 4320
#header offvia offreply_header_access Via deny allreply_header_access Server deny all
编辑好后保存退出。这里我们可以把Squid写成服务让他开机自动启动,具体设置方法可以见上遍文章。最后一步,加速站点配置好后,还需要关键的一步,就是修改linux服务器本地host让他解析加速域名到需要加速的服务器上面。linux下面的hosts表位于/etc/hosts,格式跟Windows大致相同,打开后我们把下面一行加到末尾
1.1.1.1 linuxidc.com www.linuxidc.com
然后保存退出。重启下服务器 试试效果吧。
页:
[1]