一. 介绍:
Squid cache(简称为Squid)是一个流行的自由软件(GNU通用公共许可证)的代理服务器和Web缓存服务器。Squid有广泛的用途,从作为网页服务器的前置cache服务器缓存相关请求来提高Web服务器的速度,到为一组人共享网络资源而缓存万维网,域名系统和其他网络搜索,到通过过滤流量帮助网络安全,到局域网通过代理上网。Squid主要设计用于在Unix一类系统运行。
二.下载安装:
# yum install -y squid
# squid -v //查看版本
# > /etc/squid/squid.conf 清空配置文件
并在配置文件中添加以下参数:
# vim /etc/squid/squid.conf
http_port 3128
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
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.0.0/16 # RFC1918 possible internal network
acl SSL_ports port 443
acl Safe_ports port 80 8080 # http的端口
acl Safe_ports port 21 # ftp的端口
acl Safe_ports port 443 # https的端口
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet
http_access allow localhost
http_access allow all
cache_dir aufs /data/cache 1024 16 256 #缓存空间1024M大小 16个一级目录,256个子目录
cache_mem 128 MB #缓存可以使用的内存大小;放在内存中访问数据速度快;
hierarchy_stoplist cgi-bin ?
coredump_dir /var/spool/squid
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern \.(jpg|png|gif|mp3|xml) 1440 50% 2880 ignore-reload
refresh_pattern . 0 20% 4320
######################################################### 到此结束
三.配置部分
1)创建缓存目录:
# mkdir /data/cache -pv
2)更新缓存目录的权限为squid:
# chown -R squid:squid /data/cache/
3)初始化缓存目录:
# squid -z
4)启动squid服务器并查看
# /etc/init.d/squid start
Starting squid: . [ OK ]
# ss -ntl | grep 3128
LISTEN 0 128 :::3128
5)检查配置文件
# squid -k check
6)重新加载配置文件
# squid -k rec
四.测试squid
在另外一台linux服务器上做测试,前提保证代理服务器能够正常访问网站。
指定代理服务器的作用是让局域网中的用户访问速度块,另一方面可以监控用户访问过哪些网站。
#curl -x192.168.1.210:3128 www.qq.com
[小扩展]
# curl -x118.193.142.173:3128 www.qq.com -I
HTTP/1.0 200 OK
Server: squid/3.4.3
Date: Tue, 16 Aug 2016 11:19:43 GMT
Content-Type: text/html; charset=GB2312
Vary: Accept-Encoding
Vary: Accept-Encoding
Expires: Tue, 16 Aug 2016 11:20:43 GMT
Cache-Control: max-age=60
Vary: Accept-Encoding
Vary: Accept-Encoding
X-Cache: HIT from shanghai.qq.com
X-Cache: MISS from i-13ho6vqi
X-Cache-Lookup: MISS from i-13ho6vqi:3128
Via: 1.0 i-13ho6vqi (squid/3.1.23)
Connection: keep-alive

 

发表评论

后才能评论