一、概述

1.1安装squid软件

在新服务器上安装squid软件。

操作系统:centOS 5.5

软件信息:squid-2.6.STABLE24.tar.gz

目的:使域名bj.abc.com转跳到www.abc.com

作用:起到加速作用。

二、安装步骤

2.1获得程序

从已经安装过squid的机器(11.11.11.11)获取软件版本信息。Squid –v

下载软件安装包:

wget http:#www.squid-cache.org/Versions/v2/2.6/squid-2.6.STABLE24.tar.gz

 

2.2 安装squid程序

cd /usr/local/

wget http:#www.squid-cache.org/Versions/v2/2.6/squid-2.6.STABLE24.tar.gz

tar -zxvf squid-2.6.STABLE24.tar.gz

cd squid-2.6.STABLE24

./configure --prefix=/usr/local/squid --enable-gnuregex --enable-icmp --enable-linux-netfilter --enable-default-err-language="Simplify_Chinese"

 --enable-follow-x-forwarded-for --enable-storeio=aufs,ufs --enable-kill-parent-hack --enable-cache-digests --with-maxfd=65536 --with-pthreads --enabl

e-dlmalloc --enable-poll --enable-stacktraces --enable-removal-policies=heap,lru --enable-delay-pools

make

make install

useradd squid

groupadd squid

mkdir /var/log/squid                                           #建立日志目录

chown squid:squid /var/log/squid                              #用户squid用户和组来运行squid

mkdir /var/spool/squid                                         #建立squid缓存目录

chown squid:squid /var/spool/squid                            #同样,给权限

/usr/local/squid/sbin/squid -z                                   #建立缓存目录

echo "/usr/local/squid/sbin/squid -Ds" >>/etc/rc.d/rc.local     #添加开机启动

 

2.3 配置squid.conf配置文件

备份配置文件:

mv squid.conf squid.conf_bak

 

生成新的配置文件:

vi squid.conf

 

配置内容原文:

visible_hostname Cache_server

cache_mgr sysop@izptec.com

error_directory /usr/local/squid/share/errors/Simplify_Chinese

cache_dir aufs /usr/local/squid/var/cache 80000 16 256

 

maximum_object_size_in_memory 160 KB

store_avg_object_size 40 KB

cache_effective_user squid

cache_effective_group squid

negative_ttl 10 seconds

 

http_port 80 vhost vport

icp_port 0

 

redirect_children 128

redirect_rewrites_host_header off

redirector_bypass off

 

cache_peer www.abc.com parent 80 0 no-query round-robin originserver name=128

cache_peer_domain 128 bj.abc.com

 

acl all src 0.0.0.0/0.0.0.0

acl ControlCentre src 127.0.0.1 118.66.252.200

acl PURGE method PURGE

http_access allow PURGE ControlCentre

http_access deny PURGE

http_access allow all

 

emulate_httpd_log on

strip_query_terms off

 

refresh_pattern -i .*.(html|htm|js|css|swf|gif|GIF|JPG|jpg|jpeg|JPEG|flv|wmv|mp3|mp4|avi|rm) 2880 50% 5760 ignore-reload ignore-no-cache

logformat common %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st %Ss:%Sh

logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%ru" "%{User-Agent}>h"

logformat squid [%tl] %6tr %>a %Ss/%03Hs %<st %rm %ru %Sh/%<A %mt "%{Referer}>h" "%{User-Agent}>h"

access_log /usr/local/squid/var/logs/access.log  squid

cache_log none

cache_store_log none

 

 

配置内容注解:

 

visible_hostname Cache_server      # cache服务器的名称

cache_mgr sysop@izptec.com        # 缓存管理员

error_directory /usr/local/squid/share/errors/Simplify_Chinese   #定义错误日志语言为中文

cache_dir aufs /usr/local/squid/var/cache 80000 16 256          # cache目录和大小的设置

 

maximum_object_size_in_memory 160 KB

#squid内存最大存储对象为160 KB,超过这个值将不保存在内存,这个对squid加速效果影响比较大,有的人将这个设置为8KB而一般网站的图像都大于8KB,如果squid每次都从磁盘为外部请求提供文件,那么是很慢的。

 

store_avg_object_size 40 KB      #squid 第一次缓冲数据的大小

cache_effective_user squid        #squid用户

cache_effective_group squid       #squid

negative_ttl 10 seconds       #404错误,缓存时间设置为10

http_port 80 vhost vport      # 监听80端口,并配置为加速模式

icp_port 0                     # cache服务器之间通信的端口UDP

 

redirect_children 128

redirect_rewrites_host_header off  # 禁止squid在使用重定向器时,更新请求的Host头部

redirector_bypass off               #禁止重定向器在忙碌时跳出

 

cache_peer www.abc.com parent 80 0 no-query round-robin originserver name=128 

#定义www.adbfp.com 为该squid的父节点并定义一个名称为128

 

cache_peer_domain 128 bj.abc.com

#定义父节点允许接受该squid对其发出的bj.adbfp.com请求

 

acl all src 0.0.0.0/0.0.0.0

acl ControlCentre src 127.0.0.1 118.66.252.200

acl PURGE method PURGE

http_access allow PURGE ControlCentre

http_access deny PURGE

http_access allow all

 

emulate_httpd_log on

strip_query_terms off

 

refresh_pattern -i .*.(html|htm|js|css|swf|gif|GIF|JPG|jpg|jpeg|JPEG|flv|wmv|mp3|mp4|avi|rm) 2880 50% 5760 ignore-reload ignore-no-cache

 

# -i 为忽略大小写 

#ignore-reload: 忽略httpno-cache头,reload

#ignore-private: 忽略httpprivate

#ignore-no-cache:忽略Pragma: no-cacheCache-controlno-cache

 

logformat common %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st %Ss:%Sh

logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%ru" "%{User-Agent}>h"     #日志文件内容格式

logformat squid [%tl] %6tr %>a %Ss/%03Hs %<st %rm %ru %Sh/%<A %mt "%{Referer}>h" "%{User-Agent}>h"        #定义生成访问日志的格式

access_log /usr/local/squid/var/logs/access.log  squid   #定义访问日志的路径

cache_log none        #不生成缓存日志文件

cache_store_log none

 

2.4启动squid程序

 

启动squid程序:

/usr/local/squid/sbin/squid -Ds

 

更改配置文件后,重新加载:

/usr/local/squid/sbin/squid -k reconfigure

 

停止squid程序:

/usr/local/squid/sbin/squid -k shutdown