在新服務器上安裝squid軟件。
操做系統:centOS 5.5
軟件信息:squid-2.6.STABLE24.tar.gz
目的:使域名bj.abc.com轉跳到www.abc.com
做用:起到加速做用。
從已經安裝過squid的機器(11.11.11.11)獲取軟件版本信息。Squid –v
下載軟件安裝包:
wget http:#www.squid-cache.org/Versions/v2/2.6/squid-2.6.STABLE24.tar.gz
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 #添加開機啓動
備份配置文件:
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: 忽略http的no-cache頭,reload 頭
#ignore-private: 忽略http的private頭
#ignore-no-cache:忽略Pragma: no-cache和Cache-control: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
啓動squid程序:
/usr/local/squid/sbin/squid -Ds
更改配置文件後,從新加載:
/usr/local/squid/sbin/squid -k reconfigure
中止squid程序:
/usr/local/squid/sbin/squid -k shutdown