1、  安装squid

#rpm –ivh squid-*.rpm

 

2、  备份squid配置文件squid.conf

#cp /etc/squid/squid.conf /home

 

3、  删除默认squid配置文件

#cd /etc/squid

#rm –f squid.conf

 

4、  新建squid配置文件

#cd /etc/squid

#touch /etc/squid/squid.conf

 

5、  编辑新建的squid配置文件

#cd /etc/squid

#vi squid.conf

 

在配置文件中写入下列内容:

http_port ip:端口     #设置squid监听的ip地址和端口号

cache_mem 128 MB         #设置内存缓存大小

cache_dir ufs /var/spool/squid 4096 16 256        #设置硬盘缓存大小 4096为硬盘空间 16为一级目录个数 256为二级目录个数

cache_effective_user squid      #设置使用缓存的有效账户

cache_effective_group squid   #设置使用缓存的有效组

dns_nameservers 202.106.0.20       #设置dns服务器

cache_access_log /var/log/squid/access.log            #设置访问日志

cache_log /var/log/squid/cache.log                   #设置缓存日志

cache_store_log /var/log/squid/store.log                 #设置网页存储日志

visible_hostname ip           #设置squid主机地址

cache_mgr webmaster@localhost.com           #设置管理员邮件

acl all src 0.0.0.0/0.0.0.0           #设置访问控制列表

http_access allow all                  #设置http访问权限

error_directory /usr/share/squid/errors/Simplify_chinese               #设置错误提示信息为中文

 

6、  初始化squid

#cd /usr/sbin

#squid -z

 

7、  启动squid 服务

#service squid start

 

8、  添加自动启动

#ntsysv

 

9、  查看命中率

#cd /usr/sbin

#./squidclient –p 监听端口 –h 主机地址 mgr:info

 

10、              配置反向代理

#cd /etc/squid

#vi squid.conf

 

在配置文件中添加一下内容:

cache_peer {目标服务器ip} parent {目标服务器端口} 0 no-query originserver weight=1 name={别名}              #为目标服务器创建别名

cache_peer_domain {别名} {目标服务器域名或ip}                 #将别名和服务器映射

cache_peer_access {别名} allow all                   #设置访问权限

 

iptables配置端口重定向,把目标服务器的服务端口重定向到squid的端口

注:squid反向代理需要dns支持,不能通过host文件解析。

    以上配置方法只适用于squid2.6或以上版本。