apache(81端口) squid(80端口)(apache和squid跑在同一个机器上面 要实现反向代理 )我将我的外网域名用zhlinux.com代替了

下载squid  apache

wget
wget

安装apache

tar zxvf httpd-2.2.14.tar.gz

cd httpd-2.2.14

./configure --prefix=/usr/local/apache2

make&&make install

配置参数可以根据自己的需求来

apache配置如下:
Listen 81
NameVirtualHost *


    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
    Satisfy all

  
    ServerName   
    ServerAdmin
    DocumentRoot "/usr/local/apache2/htdocs/"
    DirectoryIndex index.html
#    ErrorLog "/usr/local/apache/logs/abc-error_log"
#    SetEnvIf Remote_Addr "::1" dontlog
#    CustomLog "/usr/local/apache/logs/abc-access_log" combined env=!dontlog

启动apache 
查看监听端口

netstat -ntpl | grep 81

安装squid

useradd squid
tar zxvf squid-3.0.STABLE4.tar.gz

cd squid-3.0.STABLE4

./configure --prefix=/usr/local/squid --disable-carp --with-aufs-threads=32 --with-pthreads --enable-storeio='ufs,aufs,coss,null' --enable-disk-io='AIO,Blocking' --enable-removal-policies='heap,lru' --disable-wccp --enable-kill-parent-hack --disable-snmp --disable-poll --disable-select --enable-auth=basic --with-aio --disable-ident-lookup --with-filedescriptors=65536

make&&make install

cd /usr/local/squid/var/logs/
touch cache.log
chmod 755 cache.log
chown squid:squid cache.log
touch page_zs_access_log
chmod 755 page_zs_access_log
chown squid:squid page_zs_access_log

配置squid.conf文件

vi /usr/local/squid/etc/squid.conf

visible_hostname
http_port 80 vhost vport
cache_mem 512 MB
maximum_object_size_in_memory 2048 KB
memory_replacement_policy lru
cache_dir ufs /tmp 512 16 256
max_open_disk_fds 0
minimum_object_size 0 KB
maximum_object_size 32768 KB
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %h" "%{User-Agent}>h" %Ss:%Sh
access_log /usr/local/squid/var/logs/page_zs_access_log combined
pid_filename /usr/local/squid/var/logs/squid.pid
cache_store_log none
cache_peer 127.0.0.1 parent 81 0 no-query no-digest originserver name=www
cache_peer_domain www
cache_peer_access www allow all
http_access allow all
acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe
cache deny QUERY
cache_effective_user squid
cache_effective_group squid

验证squid.conf配置是否正确
/usr/local/squid/sbin/squid -k parse

如果没有问题会显示
/usr/local/squid/etc/squid.conf (depth 0)

/usr/local/squid/sbin/squid -z
用来Creating Swap Directories

创建squid启动脚本

vi squid.sh

#!/bin/sh
#
ulimit -HSn 15000
# this script starts and stops Squid
echo 15000 > /proc/sys/fs/file-max
case "$1" in
start)
          /usr/local/squid/sbin/squid -s
          echo -n ' Squid'
          ;;
stop)
          /usr/local/squid/sbin/squid -k shutdown
          ;;
esac
赋予执行权限

chmod x squid.sh

./squid.sh start

查看有没有启动
#ps fax|grep squid
13750 pts/3    S      0:00                      \_ grep squid
30474 ?        Ss     0:00 /usr/local/squid/sbin/squid -s
30476 ?        S      0:01 \_ (squid) -s
则证明OK

more /usr/local/squid/var/logs/page_zs_access_log |grep TCP_MEM_HIT
该指令可以看到在squid运行过程中,有那些文件被squid缓存到内存中,并返回给访问用户

more /usr/local/squid/var/logs/page_zs_access_log |grep TCP_HIT
该指令可以看到在squid运行过程中,有那些文件被squid缓存到cache目录中,并返回给访问用户

可以查看下命中率及其他相关信息
#/usr/local/squid/bin/squidclient -p 80 -h localhost mgr:info

 

说明:本文档是参照网络上一些文档而写。