基于Squid的反向加速多个WEB服务器[安装文档]

基于Squid的反向加速多个WEB服务器

Step I - Downloading and compiling Squid

Wget http://www.squid-cache.org/Versions/v2/2.5/squid-2.5.STABLE13.tar.gz

[root@redhatas4 squid-2.5.STABLE13]# tar zxvf squid-2.5.STABLE13.tar.gz

[root@redhatas4 squid-2.5.STABLE13]# cd squid-2.5.STABLE13

[root@redhatas4 squid-2.5.STABLE13]# vi config.sh

写入内容如下:

代码:



#!/bin/bash

SQUID_ROOT="/Data/apps/squid"

./configure --prefix=$SQUID_ROOT \

--enable-useragent-log \

--enable-referer-log \

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

--enable-err-languages="Simplify_Chinese English" \

--disable-internal-dns

[root@redhatas4 squid-2.5.STABLE13]# sh config.sh

[root@redhatas4 squid-2.5.STABLE13]# make

[root@redhatas4 squid-2.5.STABLE13]# make install

Step II - Basic Configuration

[root@redhatas4 squid]# cd /Data/apps/squid/

[root@redhatas4 squid]# mkdir cache

[root@redhatas4 squid]# chown squid.squid *

A、 /etc/hosts中:加入内部的DNS解析,比如:
61.135.132.176 www.sohu.com
202.108.33.32 www.sina.com
202.108.9.16 www.163.com

202.108.12.68 www.tom.com

Bvi /Data/apps/squid/etc/squid.conf

详见附件,重点都在这里了

Step III - Starting Squid

A、创建缓存目录

[root@redhatas4 sbin]# ./squid –z

B、测试Squid运行状况

[root@redhatas4 sbin]# ./ squid –NCd1

成功后将出现"Ready to serve requests".否则请检查配置文件

C、建立Squid启动脚本

# cd /etc/rc.local

#vi squid.sh

代码:

#!/bin/sh

# if ! PREFIX=$(expr $0 : "\(/.*\)/etc/rc\.d/$(basename $0)\$"); then

#   echo "$0: Cannot determine the PREFIX" >&2

#   exit 1

# fi

case "$1" in

start)

  if [ -x /Data/apps/squid/sbin/squid -a -f /Data/apps/squid/etc/squid.conf ]; then

  (cd /Data/apps/squid/var/logs; /Data/apps/squid/sbin/squid >/dev/null 2>&1 &) ; echo -n ' squid'

  fi

  ;;

stop)

    /Data/apps/squid/sbin/squid -k shutdown 2>&1

    # Uncomment this if you'd like the system to (attempt to

    # wait for) squid to shut down cleanly

    #echo "Sleeping for 45 seconds to allow squid to shutdown.."

    #sleep 45

  ;;

*)

  echo "Usage: `basename $0` {start|stop}" >&2

  ;;

esac

exit 0

启动squid
/etc/rc.local/squid.sh start 启动squid


/etc/rc.d/squid.sh stop 停止squid

启用新配置:
/Data/apps/squid/sbin/squid -k reconfig
通过crontab每天0点截断/轮循日志:
0 0 * * * (/Data/apps/squid/sbin/squid -k rotate)

停止 squid

你可能感兴趣的:(Web,cache,F#,脚本,bash)