squid-3.1.19缓存服务器的安装与配置

发布时间:2020-09-13编辑:脚本学堂
使用Squid3.1配置一台缓存服务器。Squid:192.168.1.1 主机:192.168.1.254

使用Squid3.1配置一台缓存服务器
Squid:192.168.1.1
主机:192.168.1.254

一、安装squid3.1
 

复制代码 代码如下:

wget http://www.squid-cache.org/Versions/v3/3.1/squid-3.1.19-20120507-r10446.tar.gz
tar zxvf squid-3.1.19-20120507-r10446.tar.gz
cd squid-3.1.19-20120507-r10446
 
./configure --prefix=/usr/local/squid3
--enable-async-io=100
--with-pthreads
--enable-storeio="aufs,diskd,ufs"
--enable-removal-policies="heap,lru"
--enable-icmp
--enable-delay-pools
--enable-useragent-log
--enable-referer-log
--enable-kill-parent-hack
--enable-arp-acl
--enable-default-err-language=Simplify_Chinese
--enable-err-languages="Simplify_Chinese English"
--disable-poll
--disable-wccp
--disable-wccpv2
--disable-ident-lookups
--disable-internal-dns
--enable-basic-auth-helpers="NCSA"
--enable-stacktrace
--with-large-files
--disable-mempools
--with-filedescriptors=65536
--enable-ssl
--enable-x-accelerator-var

make
make install

二、编辑配置文件
# vim /usr/local/squid3/etc/squid.conf
 

复制代码 代码如下:

::::::::::::::
squid.conf
::::::::::::::
#
# Recommended minimum configuration:
#
acl manager proto cache_object
acl localhost src 127.0.0.1/32 ::1
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
acl localnet src 192.168.1.0/24 # RFC1918 possible internal network
acl localnet src fc00::/7       # RFC 4193 local private network range
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
acl CONNECT method CONNECT

#
# Recommended minimum Access Permission configuration:
#
# Only allow cachemgr access from localhost
http_access allow manager localhost
http_access deny manager

# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
#http_port 192.168.1.1:3128
http_port 192.168.1.1:3128 transparent

# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /usr/local/squid3/var/cache 100 16 256
cache_dir ufs /mnt/squid01 68000 16 256
cache_dir ufs /mnt/squid02 68000 16 256
cache_dir ufs /mnt/squid03 68000 16 256
cache_dir ufs /mnt/squid04 68000 16 256
cache_swap_low 80
cache_swap_high 96
cache_mem 8192 MB
cache_mgr test@jb200.com
# dns_nameservers 8.8.8.8
cache_effective_user squid
cache_effective_group squid
visible_hostname 192.168.1.1

httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on

# Leave coredumps in the first cache dir
coredump_dir /usr/local/squid3/var/cache

# Add any of your own refresh_pattern entries above these.
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|?) 0     0%      0
refresh_pattern .               0       20%     4320

三、设定目录权限

复制代码 代码如下:
/usr/sbin/groupadd squid
/usr/sbin/useradd -g squid squid
mkdir -p /data/logs
chown squid:squid /data/logs
mkdir -p /data/cache1
chown squid:squid /data/cache1
mkdir -p /data/cache2
chown squid:squid /data/cache2

四、启动squid测试
 

复制代码 代码如下:
cd /usr/local/squid3/sbin
./squid -z
./squid

五、配置开机自动启动squid
vi /etc/rc.local
在末尾增加以下内容:
/usr/local/squid3/sbin/squid

新增:
不重启squid服务,重载配置文件:
 

复制代码 代码如下:
cd /usr/local/squid3/sbin
./squid -k reconfigure