2,开始安装和配置:
qUFLinux联盟qUFLinux联盟1) 查看和修改最大连接数:
qUFLinux联盟 #ulimit -a
qUFLinux联盟core file size (blocks, -c) unlimited
qUFLinux联盟data seg size (kbytes, -d) unlimited
qUFLinux联盟file size (blocks, -f) unlimited
qUFLinux联盟open files (-n) 65536
qUFLinux联盟pipe size (512 bytes, -p) 10
qUFLinux联盟stack size (kbytes, -s) 8480
qUFLinux联盟cpu time (seconds, -t) unlimited
qUFLinux联盟max user processes (-u) 8485
qUFLinux联盟virtual memory (kbytes, -v) unlimited
qUFLinux联盟qUFLinux联盟修改:vi /usr/include/sys/types.h
qUFLinux联盟qUFLinux联盟#define FD_SETSIZE 10240
qUFLinux联盟#ifndef _SYS_TYPES_H
qUFLinux联盟#define _SYS_TYPES_H
qUFLinux联盟qUFLinux联盟2)将squid软件解压和安装到制定目录:
qUFLinux联盟 ./configure --prefix=/usr/local/squid --disable-internal-dns --enable-useragent-log --enable-referer-log(可以看到连接数已经修改为10240)
qUFLinux联盟 make;make install;
qUFLinux联盟3)在squid.conf文件里修改配置:
qUFLinux联盟 vi /usr/local/squid/etc/squid.conf
qUFLinux联盟qUFLinux联盟 增加和修改的部分:
qUFLinux联盟 http_port 80 accel vhost
qUFLinux联盟 hierarchy_stoplist cgi-bin ?
qUFLinux联盟 acl QUERY urlpath_regex cgi-bin \?
qUFLinux联盟 cache deny QUERY
qUFLinux联盟 acl apache rep_header Server ^Apache
qUFLinux联盟 broken_vary_encoding allow apache
qUFLinux联盟 cache_mem 1024 MB
qUFLinux联盟 cache_dir ufs /export/home/squid/cache 4000 16 256
qUFLinux联盟 access_log /export/home/squid/logs/access.log squid
qUFLinux联盟 cache_log /export/home/squid/logs/cache.log
qUFLinux联盟 cache_store_log /export/home/squid/logs/store.log
qUFLinux联盟 pid_filename /export/home/squid/logs/squid.pid
qUFLinux联盟 cache_dns_program /usr/local/squid/libexec/dnsserver
qUFLinux联盟 dns_children 10
qUFLinux联盟 hosts_file /etc/hosts
qUFLinux联盟 refresh_pattern ^ftp: 1440 20% 10080
qUFLinux联盟 refresh_pattern ^gopher: 1440 0% 1440
qUFLinux联盟 refresh_pattern .jsp 0 20% 0
qUFLinux联盟 refresh_pattern . 0 20% 2
qUFLinux联盟 acl acceleratedHostSCUT dstdomain .abc.com
qUFLinux联盟qUFLinux联盟 acl acceleratedProtocol protocol HTTP
qUFLinux联盟 acl acceleratedPort port 80
qUFLinux联盟qUFLinux联盟 acl all src 0.0.0.0/0.0.0.0
qUFLinux联盟 acl manager proto cache_object
qUFLinux联盟 acl localhost src 127.0.0.1/255.255.255.255
qUFLinux联盟 acl to_localhost dst 127.0.0.0/8
qUFLinux联盟 acl SSL_ports port 443
qUFLinux联盟 acl Safe_ports port 80 # http
qUFLinux联盟 acl Safe_ports port 21 # ftp
qUFLinux联盟 acl Safe_ports port 443 # https
qUFLinux联盟 acl Safe_ports port 70 # gopher
qUFLinux联盟 acl Safe_ports port 210 # wais
qUFLinux联盟 acl Safe_ports port 1025-65535 # unregistered ports
qUFLinux联盟 acl Safe_ports port 280 # http-mgmt
qUFLinux联盟 acl Safe_ports port 488 # gss-http
qUFLinux联盟 acl Safe_ports port 591 # filemaker
qUFLinux联盟 acl Safe_ports port 777 # multiling http
qUFLinux联盟 acl CONNECT method CONNECT
qUFLinux联盟 http_access allow acceleratedProtocol acceleratedPort acceleratedHostABC
qUFLinux联盟qUFLinux联盟http_access allow manager localhost
qUFLinux联盟http_access deny manager
qUFLinux联盟http_access deny !Safe_ports
qUFLinux联盟http_access deny CONNECT !SSL_ports
qUFLinux联盟http_access deny all
qUFLinux联盟http_reply_access allow all
qUFLinux联盟icp_access allow all
qUFLinux联盟visible_hostname webcache3.abc.com
qUFLinux联盟logfile_rotate 10
qUFLinux联盟always_direct allow acceleratedHostABC
qUFLinux联盟qUFLinux联盟coredump_dir /export/home/squid/cache
qUFLinux联盟qUFLinux联盟4)配置hosts文件
qUFLinux联盟#vi /etc/hosts
qUFLinux联盟#
qUFLinux联盟127.0.0.1 localhost
qUFLinux联盟IP
www.abc.comqUFLinux联盟qUFLinux联盟5)配置/etc/init.d/squid
qUFLinux联盟#!/bin/bash
qUFLinux联盟# squid This shell script takes care of starting and stopping
qUFLinux联盟# Squid Internet Object Cache
qUFLinux联盟#
qUFLinux联盟# chkconfig: - 90 25
qUFLinux联盟# description: Squid - Internet Object Cache. Internet object caching is \
qUFLinux联盟# a way to store requested Internet objects (i.e., data available \
qUFLinux联盟# via the HTTP, FTP, and gopher protocols) on a system closer to the \
qUFLinux联盟# requesting site than to the source. Web browsers can then use the \
qUFLinux联盟# local Squid cache as a proxy HTTP server, reducing access time as \
qUFLinux联盟# well as bandwidth consumption.
qUFLinux联盟# pidfile: /home/squid/logs/squid.pid
qUFLinux联盟# config: /usr/local/squid/etc/squid.conf
qUFLinux联盟qUFLinux联盟PATH=/usr/bin:/sbin:/bin:/usr/sbin
qUFLinux联盟export PATH
qUFLinux联盟qUFLinux联盟qUFLinux联盟# check if the squid conf file is present
qUFLinux联盟[ -f /usr/local/squid/etc/squid.conf ] || exit 0
qUFLinux联盟qUFLinux联盟# don't raise an error if the config file is incomplete
qUFLinux联盟# set defaults instead:
qUFLinux联盟SQUID_OPTS=${SQUID_OPTS:-"-D"}
qUFLinux联盟SQUID_PIDFILE_TIMEOUT=${SQUID_PIDFILE_TIMEOUT:-20}
qUFLinux联盟SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}
qUFLinux联盟qUFLinux联盟# determine the name of the squid binary
qUFLinux联盟[ -f /usr/local/squid/sbin/squid ] && SQUID=/usr/local/squid/sbin/squid
qUFLinux联盟[ -z "$SQUID" ] && exit 0
qUFLinux联盟qUFLinux联盟prog="$SQUID"
qUFLinux联盟qUFLinux联盟# determine which one is the cache_swap directory
qUFLinux联盟CACHE_SWAP=`sed -e 's/#.*//g' /usr/local/squid/etc/squid.conf | \
qUFLinux联盟 grep cache_dir | awk '{ print $3 }'`
qUFLinux联盟[ -z "$CACHE_SWAP" ] && CACHE_SWAP=/export/home/squid/cache
qUFLinux联盟qUFLinux联盟RETVAL=0
qUFLinux联盟qUFLinux联盟start() {
qUFLinux联盟 for adir in $CACHE_SWAP; do
qUFLinux联盟 if [ ! -d $adir/00 ]; then
qUFLinux联盟 echo -n "init_cache_dir $adir... "
qUFLinux联盟 $SQUID -z -F -D 2>/dev/null
qUFLinux联盟 fi
qUFLinux联盟 done
qUFLinux联盟 echo -n $"Starting $prog: "
qUFLinux联盟 $SQUID $SQUID_OPTS 2> /dev/null
qUFLinux联盟 RETVAL=$?
qUFLinux联盟 if [ $RETVAL -eq 0 ]; then
qUFLinux联盟 timeout=0;
qUFLinux联盟 while : ; do
qUFLinux联盟 [ ! -f /export/home/squid/logs/squid.pid ] || break
qUFLinux联盟 if [ $timeout -ge $SQUID_PIDFILE_TIMEOUT ]; then
qUFLinux联盟 RETVAL=1
qUFLinux联盟 break
qUFLinux联盟 fi
qUFLinux联盟 sleep 1 && echo -n "."
qUFLinux联盟 timeout=$((timeout+1))
qUFLinux联盟 done
qUFLinux联盟 fi
qUFLinux联盟 [ $RETVAL -eq 0 ] && echo "OK"
qUFLinux联盟 [ $RETVAL -ne 0 ] && echo "Failed"
qUFLinux联盟 echo
qUFLinux联盟 return $RETVAL
qUFLinux联盟}
qUFLinux联盟qUFLinux联盟stop() {
qUFLinux联盟 echo -n $"Stopping $prog: "
qUFLinux联盟 $SQUID -k check >/dev/null 2>&1
qUFLinux联盟 RETVAL=$?
qUFLinux联盟 if [ $RETVAL -eq 0 ] ; then
qUFLinux联盟 $SQUID -k shutdown &
qUFLinux联盟 timeout=0
qUFLinux联盟 while : ; do
qUFLinux联盟 [ -f /export/home/squid/logs/squid.pid ] || break
qUFLinux联盟 if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then
qUFLinux联盟 echo
qUFLinux联盟 return 1
qUFLinux联盟 fi
qUFLinux联盟 sleep 2 && echo -n "."
qUFLinux联盟 timeout=$((timeout+2))
qUFLinux联盟 done
qUFLinux联盟 echo "OK"
qUFLinux联盟 echo
qUFLinux联盟 else
qUFLinux联盟 echo "Failed"
qUFLinux联盟 echo
qUFLinux联盟 fi
qUFLinux联盟 return $RETVAL
qUFLinux联盟}
qUFLinux联盟qUFLinux联盟reload() {
qUFLinux联盟 $SQUID $SQUID_OPTS -k reconfigure
qUFLinux联盟}
qUFLinux联盟qUFLinux联盟restart() {
qUFLinux联盟 stop
qUFLinux联盟 start
qUFLinux联盟}
qUFLinux联盟qUFLinux联盟qUFLinux联盟rhstatus() {
qUFLinux联盟 status $SQUID
qUFLinux联盟 $SQUID -k check
qUFLinux联盟}
qUFLinux联盟qUFLinux联盟probe() {
qUFLinux联盟 return 0
qUFLinux联盟}
qUFLinux联盟qUFLinux联盟case "$1" in
qUFLinux联盟start)
qUFLinux联盟 start
qUFLinux联盟 ;;
qUFLinux联盟qUFLinux联盟stop)
qUFLinux联盟 stop
qUFLinux联盟 ;;
qUFLinux联盟qUFLinux联盟reload)
qUFLinux联盟 reload
qUFLinux联盟 ;;
qUFLinux联盟qUFLinux联盟restart)
qUFLinux联盟 restart
qUFLinux联盟 ;;
qUFLinux联盟qUFLinux联盟status)
qUFLinux联盟 rhstatus
qUFLinux联盟 ;;
qUFLinux联盟qUFLinux联盟probe)
qUFLinux联盟 exit 0
qUFLinux联盟 ;;
qUFLinux联盟qUFLinux联盟*)
qUFLinux联盟 echo $"Usage: $0 {start|stop|status|reload|restart}"
qUFLinux联盟 exit 1
qUFLinux联盟esac
qUFLinux联盟qUFLinux联盟exit $?