squid做web镜像

应用环境:一台智能DNS,一台web做原始服务器,三台squid做web镜像,三台squid分别在重庆,上海,天津,web在深圳,智能dns能分析客户访问接入的IP然后叫其访问本城市的服务器,比如说上海的客户访问的就是上海的web镜像,然后第二次访问的时候首先是向其他两台squid发起请求看有没有这个缓存,如果没有在向web发起请求

系统环境:CentOS 5.2,squid-3.1.0.13.tar.gz,其中web服务器是LAMP环境,域名为www.qubaoquan.com

IP和域名规划:智能DNS的ip为192.168.10.100,web服务器的IP为192.168.10.1,上海squid的IP为:192.168.10.2,重庆squid的IP为:192.168.10.3,天津squid的IP为:192.168.10.4,对外提供的域名为www.qubaoquan.com

如下的的配置是上海的squid的配置,其他两台squid只要做些响应更改就可以了

1. 安装

[root@squid srv]# tar zvxf squid-3.1.0.13.tar.gz

[root@squid srv]# cd squid-3.1.0.13

[root@squid srv]# ./configure --prefix=/usr/local/squid --enable-storrio=ufs,aufs,null --enable-linux-netfilter

[root@squid srv]# make

[root@squid srv]# make install

2. 创建运行squid的用户

[root@squid srv]# useradd squid

3. 创建运行所需的目录并且赋权

[root@squid srv]# mkdir -p /usr/local/squid/cache

[root@squid srv]# chown -R squid:squid /usr/local/squid/cache/

[root@squid srv]# mkdir -p /var/run/squid/

[root@squid srv]# chown -R squid:squid /var/run/squid/

[root@squid srv]# mkdir -p /var/log/squid

[root@squid srv]# chown -R squid:squid /var/log/squid

4. 编辑主配置文件

[root@squid srv]# cd /usr/local/squid/etc/

[root@squid etc]# mv squid.conf squid.conf.bak

[root@squid etc]# vi squid.conf(内容如下)

############# basic setting ###############

visible_hostname 192.168.10.2

pid_filename /var/run/squid/squid.pid

dns_nameservers 192.168.10.100

############# log config ###############

cache_access_log /var/log/squid/access.log

cache_log /var/log/squid/cache.log

cache_store_log none

#========&gt; log format <===============

logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st"%{Referer}>h" "%{User-Agent}&gt;h" %Ss:%Sh

#====================#

logfile_rotate 24

emulate_httpd_log on //使日志和Apache的格式相似

debug_options ALL,2 //debuge级别

############# acl setting ###############

acl all src 0.0.0.0/0.0.0.0

http_access allow all

############ timeout setting ############

connect_timeout 1 minute

peer_connect_timeout 30 seconds

request_timeout 2 minutes

persistent_request_timeout 1 minute

############# admin setting #############

cache_mgr [email protected]

############# cache setting #############

cache_dir ufs /usr/local/squid/cache 4096 16 256

cache_mem 125 MB

cache_swap_low 90

cache_swap_high 95

maximum_object_size 32768k

minimum_object_size 2k

maximum_object_size_in_memory 256 KB

cache_replacement_policy lru

memory_replacement_policy lru

cache_effective_user squid

cache_effective_group squid

#=========&gt; dns reslove cache <========

ipcache_size 1024

ipcache_low 90

ipcache_high 95

fqdncache_size 1024

#==========> no cached <==========

hierarchy_stoplist cgi-bin ?

hierarchy_stoplist -i ^https:\\ ?

acl QUERY urlpath_regex -i cgi-bin \? \.asp \.php \.jsp \.cgi

acl denyssl urlpath_regex -i ^https:\\

no_cache deny QUERY

no_cache deny denyssl

#==========> Expires setting <=============

refresh_pattern -i \.gif$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.jpg$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.png$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.bmp$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.jpeg$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.mp3$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.wmv$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.rm$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.swf$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.mpeg$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.wma$ 1440 50% 2880 ignore-reload

refresh_pattern -i \.css$ 10 50% 60 reload-into-ims

refresh_pattern -i \.js$ 10 50% 60 reload-into-ims

refresh_pattern -i \.xml$ 10 50% 30 reload-into-ims

############# porxy setting #############

http_port 80 accel vhost vport

icp_port 3130

cache_peer 192.168.10.1 parent 80 3310 no-query round-robin max-conn=32 originserver name=qubaoquan

cache_peer_domain qubaoquan www.qubaoquan.com

#==========> forword cyclic <=============

#acl fromneighbor src 192.168.168.5

#cache_peer_access 192.168.168.5 deny fromneighbor

#==========> neighbor setting <=============

cache_peer 192.168.10.3 sibling 80 3310

cache_peer 192.168.10.4 sibling 80 3310

#==========> ICP contorl &lt;=============

acl N1 src 192.168.10.3

acl N2 src 192.168.10.4

acl ALL src 0.0.0.0/0.0.0.0

icp_access allow N1

icp_access allow N2

icp_access deny ALL

############# old version setting ###########

#httpd_accel_single_host off

#httpd_accel_host 221.122.76.96

#httpd_accel_port 80

#httpd_accel_with_proxy on

#httpd_accel_user_host_header on

############### other setting ##########

forwarded_for off

coredump_dir /usr/local/squid/var/cache

quick_abort_min 16 KB

quick_abort_max 16 KB

quick_abort_pct 95

error_directory /usr/local/squid/share/errors/en-us/

5. 创建启动脚本并且注册为系统服务

[root@squid ~]# vi /etc/init.d/squid(内容如下)

#!/bin/bash

# chkconfig: - 90 25

# description: Squid

case "$1" in

start)

if [ -f /var/run/squid/squid.pid ]

then

echo " the squid serve is running now,please stop it fisrt!"

else

/usr/local/squid/sbin/squid -s

fi

;;

stop)

rm -rf /var/run/squid/squid.pid

killall -9 squid

;;

status)

if [ -f /var/run/squid/squid.pid ]

then

echo " the squid serve is running now"

else

echo " the squid serve not running now"

fi

;;

restart)

# rm -rf /var/run/squid/squid.pid

#killall -9 squid

#/usr/local/squid/sbin/squid -s

e a

echo b

echo c

;;

Esac

[root@squid ~]# chmod +x /etc/init.d/squid

[root@squid ~]# chkconfig --add squid

[root@squid ~]# chkconfig --levels 2345 squid on

6. 启动服务

[root@squid ~]# service squid start

7. 测试:在一台测试机上把域名www.qubaoquan.com绑定到192.168.10.2上,然后再浏览器访问:www.qubaoquan.com就会出现192.168.10.1上面的web页面

8. 查看缓存命中率的方法:[root@squid ~]# /usr/local/squid/bin/squidclient -p 80 mgr:info

你可能感兴趣的:(Web,镜像,职场,squid,休闲)