Centos安装Squid 配置代理上网

Squid cache(简称为Squid)是一个流行的自由软件(GNU通用公共许可证)的代理服务器和Web缓存服务器。Squid有广泛的用途,从作为网页服务器的前置cache服务器缓存相关请求来提高Web服务器的速度,到为一组人共享网络资源而缓存万维网,域名系统和其他网络搜索,到通过过滤流量帮助网络安全,到局域网通过代理上网。Squid主要设计用于在Unix一类系统运行

安装:
yum install squid -y //yum安装squid
安装后,默认配置存放在 /etc/squid 目录下
主要是修改配置文件:/etc/squid/squid.conf

# Squid normally listens to port 3128
http_port 3128
##代理服务的端口
--------------------------------------------------------------------------
#Default:
cache_mem 8 MB
##要额外提供多少内存给squid使用,这里的额外是指squid会将最常用的一些缓存放到这块内存中
##squid是这样来计算使用多少内存的:squid本身的进程大概10M-20M
##那他放在内存里的hash索引大概需要20M左右,然后再加上这里设置的cache_mem的值
##官方文档建议你的实际内存大小应该是这个squid所需要总内存的2倍以上。自己量力而为吧
##cache_mem当然是越大越好了。
--------------------------------------------------------------------------
#Default:
cache_dir ufs /var/spool/squid 500 16 256
##其中ufs是存储机制,默认是ufs,如果是编译安装设置参数 --enable-storeio=LIST 中指定
##默认为ufs,其他有:aufs, diskd, coss, null
##后面的数字是设置squid存放cache目录的位置以及大小。第一个数字500是指目录的总大小为500M
##(默认为100M),第二个数字16是指第一级目录为16个
##第三个数字256是指第二级目录为256个我个人觉得如果网站访问量大
##并且内容很多的话,可以考虑将默认的100M改大一点,否则会报错
--------------------------------------------------------------------------
# TAG: log_access allow|deny acl acl...
# This options allows you to control which requests gets logged
# to access.log (see access_log directive). Requests denied for
# logging will also not be accounted for in performance counters.
#
#Default:
cache_access_log /var/log/squid/access.log

# TAG: cache_log
# Cache logging file. This is where general information about
# your cache’s behavior goes. You can increase the amount of data
# logged to this file with the “debug_options” tag below.
#
#Default:
cache_log /var/log/squid/cache.log

# TAG: cache_store_log
# Logs the activities of the storage manager. Shows which
# objects are ejected from the cache, and which objects are
# saved and for how long. To disable, enter “none”. There are
# not really utilities to analyze this data, so you can safely
# disable it.
#
#Default:
cache_store_log /var/log/squid/store.log

##以上参数是设置log的,cache_access_log 访问日志,cache_log 缓存日志
##cache_store_log 存储日志。可以根据自己情况设置
————————————————————————–
acl all src 0.0.0.0/0.0.0.0
##ACL的基本格式如下: acl 列表名称 控制方式 控制目标 比如acl all src 0.0.0.0/0
##其名称是all,控制方式是src源IP地址,控制目标是0.0.0.0/0的IP地址,即所有未定义的用户
##出于安全考虑,总是在最后禁止这个列表
##下面这个列表代表高级用户,包括IP地址从192.168.0.2到192.168.0.10的所有计算机
##acl advance 192.168.0.2-192.168.0.20/32
————————————————————————–
#Recommended minimum configuration:
#
# Only allow cachemgr access from localhost
http_access allow all
http_access allow manager localhost
http_access deny manager
##上面几行代码告诉Squid不允许manager组访问Internet,但manager localhost组允许
##(此时还没有指定详细的权限)。由于Squid是按照顺序读取规则,会首先允许manager localhost组
##然后禁止manager组。所以manager localhost都可以访问。
##如果将两条规则顺序颠倒,由于先禁止manager组, Squid先禁止了manager组,
##那么再允许manager localhost时,manager就不起作用。
##特别要注意的是,Squid将使用allow-deny-allow-deny……这样的顺序套用规则。
##例如,当一个用户访问代理服务器时, Squid会顺序测试Squid中定义的所有规则列表,
##当所有规则都不匹配时,Squid会使用与最后一条相反的规则。
##这里就设置所有都允许http_access allow all
##这里和前面设置的 acl all src 0.0.0.0/0.0.0.0 要一致。
————————————————————————–
# TAG: dns_nameservers
# Use this if you want to specify a list of DNS name servers
# (IP addresses) to use instead of those given in your
# /etc/resolv.conf file.
# On Windows platforms, if no value is specified here or in
# the /etc/resolv.conf file, the list of DNS name servers are
# taken from the Windows registry, both static and dynamic DHCP
# configurations are supported.
#
# Example: dns_nameservers 10.0.0.1 192.172.0.4
#
#Default:
dns_nameservers 8.8.8.8
dns_nameservers 8.8.4.4
##配置DNS解析服务器
————————————————————————–
# TAG: visible_hostname
# If you want to present a special hostname in error messages, etc,
# define this. Otherwise, the return value of gethostname()
# will be used. If you have multiple caches in a cluster and
# get errors about IP-forwarding you must set them to have individual
# names with this setting.
#
#Default:
visible_hostname testname
##设置squid它的主机名

客户端配置:
Linux
http_proxy="http://10.171.246.48:3128"
ftp_proxy="http://10.171.246.48:3128"
export http_proxy
export ftp_proxy

Windows 略