Squid 缓存服务

1、缓存服务器结束

缓存服务器(cache server),即用来存储(介质为内存及硬盘)用户访问的网页、图片、文件等等信息的专用服务器,这种服务器不仅可以使用户可以最快的得到他们想要的信息,而且可以大大减少服务端网络传输的数据量,缓存服务器往往也是代理服务器,对于网站的用户来说,缓存服务器和代理是不可见的,即在用户看来所有的网站信息都是来自其正在访问的网站,而实际上可能是缓存服务器在提供访问数据

目前国内互联网公司常用的缓存服务器有:squid、varnish、nginx、ats。

第一次用户访问网站,先到squiq,但是squid没有数据,所以sqquid代理用户去服务端访问,之后数据也会保留在squid,所以下次用户访问的时候,可以直接从squid中获得,而不必再到服务器中取得数据。

官网:http://www.squid-cache.org/

2、web缓存的相关概念

a、cache命中

cache命中是在cache server每次从它的缓存里满足客户端http请求发送。cache命中率,是所有客户端HTTP请求中的命中比例,web缓存典型的cache命中率在30%到60%之间,另一个相似的度量单位叫做字节命中率,描述了cache提供服务的数据容量。

提供cache命中率的方法:

1、nginx/apache expries,cache-control缓存头

2、动静分离,静态化,对静态走CDN

3、设置数据库的cache等,如设置mysql 的cache,让缓存靠前

4、4XX/5XX之类的错误页面,死链无法缓存。

5、动态不走缓存

b、cache丢失

cache丢失在cache server不能从它的缓存里面满足客户端HTTP请求时发生,cache丢失的原因有很多种:

1、当cache server第一次接受到对第一个新资源的请求时,就会产生一个cache丢失,如何解决第一次命中?

先预热或者预取

a、内部先请求访问,可以通过脚本实现(但是这个思想不太靠谱)。

b、后端生成数据之后,统一推到前端cache server,即预取、预热

2、存储空间慢,或者对象自身过期,cache server会清除这些缓存对象,以释放空间给新对象

如果解决问题2:

a、增大内存或者磁盘。

b、增大对象缓存时间

c、参数设置,缓存参数设置打一下,最大缓存对象2M(想办法多缓存热门的数据)

d、分资源缓存,如1M/10M/100M不同大小的分开缓存。(分拆服务器,acl正则匹配抛给不同的pools)

3、还有可能是客户访问的资源不可到达,原始服务器指示cache server怎样处理用户响应,如:他会提示数据不能被缓存,或在有限的时间内才被重复使用等等。

a、

c、cache确认

cache确认保证cache server不对访问的用户返回过期的数据,在重复使用缓存对象时,cache server需要经常从原始服务器确认它,假如服务器指示squid的拷贝仍旧有效,数据就发送出去,否则,squid更新它的存储拷贝,并且转发给客户

当用户更新了数据到数据库或者存储服务器的时候,可以从业务角度主动调用接口清楚该对象缓存的指令。

对应缓存来讲,数据的一致性是一个特别头疼的问题,特别是memcached。

CDN删除数据一般需要5-15分钟才能删除完成。

图片放到CDN一般是不要更新了,图片修改算更新,这种业务就要推送。

删除图片再上传,这种不算修改,而是一个新的资源。老是数据,CDN会有相应的算法,在一定的时间内自动删除。

网站改版:在CDN上推送js、css(改名推送)等程序。

3、squid服务介绍

squid是一个高性能的代理和缓存服务器,squid支持FTP/gopher和HTTP协议,和一般的代理缓存软件不同,squid用一个单独的,非模块化的、I/O驱动的进程来处理所有的客户端请求。(gopher是internet上一个非常有名的信息查询系统,它将Internet上的文件组织成某种索引,很方便地将用户从Internet的一处带到另外一处,在WWW出现之前,GopherSHI Internet上主要的信息检索工具)

Squid将数据元缓存到内存或硬盘中,同时也缓存DNS查询结果,Squid只是SSL,支持访问控制,由于使用ICP(轻量Internet缓存协议),Squid能够实现层叠的代理阵列,从而最大限度的节约带宽

Squid Cache简称Squid,是一个流行的代理服务器和WEB缓存服务器软件,Squid服务有相当多的用途。

1、用于放置在WEB服务器的前面,缓存网站WEB服务器的相关数据。这样用户请求缓存服务器就可以直接返回数据给用户了,从而提升了用户的访问网站体验,从另外一方面也减轻了web服务器、数据服务器、图片文件存储服务器等业务服务器的压力。这种应用被称之为反向代理服务

2、用于放置在企业内部关键的出网位置或者某些共享的网络前端,缓存内部上网用户的数据,域名系统和其他网络搜索数据等,这样用户上网请求的数据,就可以有缓存服务器放回给内部用户,而不需要上网了,从而使得内部用户上网更快,更安全,也会大大节约公司的带宽,这种应用被称之为正向代理服务(分为普通代理或者透明代理)。(现在很少用,5年前,带宽很小的时候用得挺多)

3、通过放在网络的关键位置过滤网络流量和访问数据,提升整个网络安全,例如:可以监控及限制内部企业员工的上网行为,可以和iptables配合作为办公网的网关。

4、用作局域网通过代理上网

只要说是一台就可以上网的机器就可以,位置随便,让所有的用户的浏览器设置这个服务器代理上网即可。

Squid代理服务器主要用于类UNIX系统中运行,其发展历史相对悠久,功能也相对完善,除了对HTTP支持很好外,对于FTP和HTTPS的支持也很好,在3.0测试版中也支持了IPV6,Squid的主页在http://www.squid-cache.org/。目前业界主流的CDN都基本是Squid进行二次开发作为cache缓存服务器的

4、三种代理服务器的原理

普通代理(传统代理)

传统的代理服务器就是通过浏览器设置代理的方法。

用户访问网站,先到squid代理服务器,如果squid代理服务器有数据,那么squid就直接从缓存中放回给用户,如果squid缓存中没有,那么squid就代替用户去访问网站,把数据返回的给用户的同时留一份到缓存中,一遍下次用户(或者其他用户)访问的时候,直接从缓存中返回给用户

透明代理:

所谓的透明代理,是相对于普通代理服务而言,客户端不需要做任何和代理服务器相关的设置,对用户而言,感觉不到代理服务器的存在,所以称之为透明代理,即把代理服务器部署在核心的上网出口,当用户上网浏览页面时,会交给代理服务器向外请求,如果结合iptables可以实现代理+网关+内容过滤+流量安全控制等完整的上网解决方案。

透明代理流程说明:

用户A发送一个访问请求到防火墙,由防火墙将该用户的访问请求转发给Squid,squid再先检查自身缓存中有无该用户请求的访问内容,如果没有,则请求远端目的的服务器,获取该用户的访问内容,再放回给用户的同时,在自身缓存保留一份记录以备下次调用,当用户B发送一个和用户A相同的请求到防火墙时,有防火墙转发该用户请求到squid,squid检查到自身缓存发现有相同的内容,直接将该内容放回给用户B。而无需再次去访问请求的服务器。

普通代理和透明代理的区别就是,普通代理需要在客户端浏览器设置指定代理服务器,而透明代理不需要。

反向代理服务原理:

普通代理方式是代理内部网络用户请求internet上服务器的连接请求,客户端必须指定代理服务器,并将本来要直接发送到internet上的服务器的连接请求发送给代理服务器处理,

反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从内部服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外表现为一个服务器。

反向代理流程说明:

squid做反向代理服务器,通常工作在一个服务器集群的前端,在用户看来,squid服务器就是他所要访问的服务器,而实际意义上,squid只是接受用户的请求,同时将用户请求转发给内部真正的WEB服务器,如果squid本身有用户要访问的内容,则squid直接将数据返回给用户,起到了缓存数据的作用,减少了后端服务器的压力

三种代理的区别:

5、什么时候需要用squid(CDN)

a、想节省带宽及服务器成本

b、想提高访问速度,提升用户体验

c、源站扛不住了

6、haproxy和squid代理的区别

有了haproxy,后面还需要squid代理吗?

squid缓存及代理功能,一般用squid是用来作为缓存服务器

haproxy做动态及静态的代理,及负载均衡

squid分拆动态和静态进行缓存。

常见架构:

动态数据======>静态化=====>CDN

很多CDN现在逐渐开始支持动态加速业务。

7、如何选择squid服务的版本

squid2.5:有点老,不支持epoll,内存管理也不完善,例如可能常常会引起重新

squid2.6-2.7:建议使用,性能不错,2.7很建议使用,以为基本有了3.0的所以特性

squid3.0:不建议使用,因为使用C++全部重写,现在性能不如2.6和2.7,以后观察

8、部署squid需要的硬件环境

a、第一重要资源:内存

squid对硬件的要求最主要就是内存资源,内存资源短缺会严重影响性能,因为所有的对象都会尽可能的被缓存到内存中,这样才能更快提升用户的响应及返回数据

b、第二资源:磁盘

磁盘空间也是另外一个squid能够高效运行的重要因素,更多的磁盘空间意外着更多的缓存目标和更高的命中率,快速的磁盘介质也是很有必要的,例如用ssd,sas替代sata磁盘,除了使用raid外,可以指定多个磁盘路径缓存

9、squid的编译和安装

部署前环境准备

环境 :

  squid server           IP:10.0.0.4
WEB server IP:10.0.0.3
 
1.更改yum源:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum install tree -y
grep keepcache /etc/yum.conf
sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf
grep keepcache /etc/yum.conf
2.关闭selinux:
setenforce 0 #临时生效
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config #永久生效
3.关闭防火墙
/etc/init.d/iptables stop
chkconfig iptables off
chkconfig --list iptables
4.时间同步
/usr/sbin/ntpdate pool.ntp.org
echo '#time sync by gao at 2010-2-1'>>/var/spool/cron/root
echo '*/10 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1'>>/var/spool/cron/root
crontab -l
5.修改主机名
=======================================
hostname Squid
cp /etc/hosts /etc/hosts.bak
cp /etc/sysconfig/network /etc/sysconfig/network.bak
sed -i '$a 10.0.0.4 WEB' /etc/hosts
sed -i '$a 10.0.0.3 Squid' /etc/hosts
sed -i -e '/HOSTNAME=/d' -e '1aHOSTNAME=WEB' /etc/sysconfig/network
logout
=======================================
hostname WEB
cp /etc/hosts /etc/hosts.bak
cp /etc/sysconfig/network /etc/sysconfig/network.bak
sed -i '$a 10.0.0.4 WEB' /etc/hosts
sed -i '$a 10.0.0.3 Squid' /etc/hosts
sed -i -e '/HOSTNAME=/d' -e '1aHOSTNAME=Squid' /etc/sysconfig/network
logout
=======================================
6.调整文件描述符
ulimit -Hn 20480
echo "ulimit -Hn 20480" >>/etc/rc.local
tail -1 /etc/rc.local
ulimit -n
echo "* - nofile 20480">>/etc/security/limits.conf
tail -2 /etc/security/limits.conf
7.调整临时端口
cat /proc/sys/net/ipv4/ip_local_port_range
echo "net.ipv4.ip_local_port_range = 4000 65000">>/etc/sysctl.conf
sysctl -p|grep port_range
 

###记得一定要做时间同步

##开始编译安装Squid

在10.0.0.3操作

创建放置软件的目录
mkdir -p /home/lvnian/tools
cd /home/lvnian/tools
下载并安装squid
#wget http://www.it.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE20.tar.gz
#wget http://down1.chinaunix.net/distfiles/squid-3.0.STABLE20.tar.gz
#http://www.it.squid-cache.org/Versions/v3/3.0
wget http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE20.tar.gz
tar xf squid-3.0.STABLE20.tar.gz
cd squid-3.0.STABLE20
./configure --prefix=/application/squid3.0 \
--enable-asyno-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-cachemgr-hostname=localhost \
--enable-arp-acl \
--enable-default-err-language=English \
--enable-err-language="Simplify_Chinese" \
--disable-poll \
--disable-wccp \
--disable-ident-lookups \
--disable-internal-dns \
--enable-basic-auth-helpers="NCSA" \
--enable-stacktrace \
--with-filedescriptors=64000 \
--enable-ssl \
--enable-x-accelerator-very \
--disable-snmp \
--with-aio \
--enable-linux-netfilter \
--enable-linux-tproxy
==========================================================
make && make install
##############################################
make 报错解决
structs.h:738: error: ISO C++ forbids declaration of ‘SSL_CTX’ with no type
structs.h:738: error: expected ‘;’ before ‘*’ token
structs.h:1160: error: ISO C++ forbids declaration of ‘SSL_CTX’ with no type
structs.h:1160: error: expected ‘;’ before ‘*’ token
structs.h:1161: error: ISO C++ forbids declaration of ‘SSL_SESSION’ with no type
structs.h:1161: error: expected ‘;’ before ‘*’ token
make[1]: *** [cf_gen.o] Error 1
make[1]: Leaving directory `/home/lvnian/tools/squid-3.0.STABLE20/src'
make: *** [all-recursive] Error 1
[root@Squid squid-3.0.STABLE20]#
安装openssl*
yum install openssl* -y
cd /home/lvnian/tools
rm -rf squid-3.0.STABLE20
tar xf squid-3.0.STABLE20.tar.gz
cd squid-3.0.STABLE20
##############################################
 

#制作软连接

ln -s /application/squid3.0 /application/squid
 

到这来安装squid完毕:

squid 目录结构介绍:

 文件名/目录名功能描述
sbin squid主从程序的目录,正常只能被root启动
sbin/squid squid的主程序
bin bin目录包含对所有用户可用的程序
bin/RunAccel RunAccel和RunCache几乎一致,唯一不同时他增加了一个命令行参数,告诉squid在哪里侦听HTTP请求
bin/RunCache RunCache是一个脚本,你能用它来启动squid,假如squid死掉,该脚本自动重启它,除非它检测到经常的重启
bin/squidclient squidclient是一个简单的HTTP客户端程序,你能用它来测试squid,他也有一些特点的功能,用以对运行的squid进程发起管理请求
libexec libexec目录包含了辅助程序,有一些命令你不能正常启动,然而,这程序通常被其他程序启动
libexec/unlinkd unlinkd是一个辅助程序,它从cache目录里删除文件
libexec/cachemgr.cgi cachemgr.cgi是squid管理功能的CGI接口,为了使用它,你需要拷贝该程序到你的web服务的cgi-bin目录下
libexec/diskd diskd假如你知道了 --enable-storeio=diskd,你才能看到它
libexec/pinger pinger假如你知道了 --enable-icmp,你才能看到它
etc etc包含squid的主配置文件
etc/squid.conf 这是squid的主配置文件
var var目录包含了不是很重要的和经常变化的文件,这些文件不必正常备份他们
var/logs var/logs目录是squid不同日志文件的默认位置,当你第一次安装squid时,他是空的,一旦squid开始运行,你能在这里看到名字为access.log。cache.log和store.log这样的文件
var/cache 假如你不在squid.conf文件里指定,这是默认的cache缓存目录(cache_dir)
 

squid.conf 语法介绍

[root@Squid etc]# pwd
/application/squid/etc
[root@Squid etc]# ls
cachemgr.conf cachemgr.conf.default mime.conf mime.conf.default squid.conf squid.conf.default
[root@Squid etc]#
 

上面中以default为后缀的都是对于配置文件的备份

#看去掉注销和空行之后的配置文件

[root@Squid etc]# cat squid.conf.default|egrep -v '^#|^$'
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
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 # 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
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 deny all
icp_access allow localnet
icp_access deny all
htcp_access allow localnet
htcp_access deny all
http_port 3128
hierarchy_stoplist cgi-bin ?
access_log /application/squid3.0/var/logs/access.log squid
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern (cgi-bin|\?) 0 0% 0
refresh_pattern . 0 20% 4320
icp_port 3130
coredump_dir /application/squid3.0/var/cache
[root@Squid etc]#
 

#创建加用户

useradd squid -s /sbin/nologin -M
id squid
 

#调整配置文件

  vi /etc/squid.conf
#############################################
修改下面的用户为squid,注意不能是root,root无法执行
2941 # cache_effective_user nobody
2941 cache_effective_user squid
或者用sed修改
grep "cache_effective_user " squid.conf
sed -i "s/# cache_effective_user nobody/cache_effective_user squid/g" squid.conf
grep "cache_effective_user " squid.conf
============================================
 

#添加组

sed -i "/cache_effective_user squid/a cache_effective_group squid" squid.conf
grep "cache_effective" squid.conf
============================================
[root@Squid etc]# grep "cache_effective" squid.conf
# TAG: cache_effective_user
# see also; cache_effective_group
cache_effective_user squid
cache_effective_group squid
# TAG: cache_effective_group
[root@Squid etc]#
============================================
 

Squid日志文件

squid默认的日志你是是squid安装位置下的logs目录,例如,假如你在./configure中没有使用--prefix=选项,那么默认的日志文件路径是/usr/local/squid/var/logs,必须确认日志文件所存在的磁盘位置空间足够多,在squid写日志如果接受到错误,它会退出和重启。该行为的主要理由应引起你的注意,squid想确认你不会丢失任何重要的日志信息,特别你的系统被滥用或者被攻击时。

squid有三个主要的日志文件:cache.log access.log store.log

cache.log日志文件

cache.log 包含多种消息,例如Squid的配置信息,性能警告,以及严重错误,如下是cache.log的输出样本,主要的错误和异常条件最可能报告在cache.log里。

刚开始运行squid时,需要密切关注该文件,加入squid拒绝运行,原因也行会出现在cache.log文件的结尾处,在正常条件下,该文件不会变化很大,加入你以-s选型来运行squid,重要的cache.log消息也会被发送到你的syslog进程,通过使用cache_log指令,你可以修改配置文件squid.conf来改变该日志文件路径。

转发cache.log消息到系统日志

为了让squid发送到cache.log消息的拷贝到系统日志,请使用-s命令选型,仅仅在debug级别0和1的消息被转发,级别0的消息以syslog级别LOG_WARGING记录,级别为1的消息以syslog级别为LOG_NOTICE记录,所有消息使用LOCAL4的syslog设备,如下配置syslogd的一个方法,以便这些消息能保存下来

local4.warning/var/log/squid.log
 

在维护多个squid主机时,使用syslog来记录cache.log特别方便,可以配置每个本机syslog进程,转发这些消息到中央日志主机,这样就可以在一个地方统一浏览所有cache日志,例如。可以在/etc/sysconfigd.conf 里使用如下接口

   local4.notice@192.168.1.123
 

access.log日志文件

Squid把关于HTTP事务的关键信息存在access.log里,该文件是基于行,也就说每行对应一个客户端请求,squid记录客户端IP(或主机名)、请求URL、响应size、和其他信息

Squid 在access.log 里记录所有HTTP访问,除了那些在还没有发送数据前就断开的连接,squid也记录所有ICP事务,除非你使用log_icp_querise指令关闭了这个功能,

store.log日志文件

store.log记录Squid关于存储或删除cache目标的决定,对每个存在cache里的目标,每个不可cache的目标,已经每个被轮换策略删除的目标,Squid都会创建相关的日志条目,该日志文件内容包含了内存cache,又包含了磁盘cache。

squid的日志文件增加没有限制,为了保证日志文件大小合理,应创建计划规律的重命名和打包日志,squid有内建的日志回滚功能,也可以避免单个日志过滤。

squid的访问控制

理解squid如何搜索ACL元素去匹配是很重要的,当ACL元素有多个值时,任何单个值都能导致匹配,换句话说,squid在检查ACL元素值时使用OR逻辑,当squid找到第一个值匹配时,他停止搜索,这意味着把最可能匹配的值放在列表的开头出,能减少延时。

重点强调:

a、squid在搜索ACL元素时使用或逻辑,在acl里的任何单值都可以导致匹配。

b、而应用访问规则恰好相反,对http_access和其他规则设置,squid使用与逻辑。

squid默认的配置文件拒绝每一个客户请求,在任何人能使用代理之前,你必须在squid.conf文件里加入附加的访问控制规则,最简单的一个方式,就是定义一个针对客户IP地址的ACL和一个访问规则,告诉Squid运行来自这些地址的HTTP请求,squid有许多不同的ACL类型,src类型匹配客户端IP,squid会针对客户HTTP请求检查http_access规则。

如:

   acl mynet src 10.0.0.0/24
htcp_access allow mynet
 

这两行需要放在正确的位置,http_access的顺序非常重要,但是ACL行的顺序不必介意,squid默认的配置文件包含了一些重要的访问控制,最好不要改变她或者删除它们,除非你完全理解它们的意思。

##访问日志,保存默认,修改为如下

access_log /application/squid3.0/var/logs/access.log squid
##修改存储日志打开
============================================
sed -i 's/# cache_store_log/cache_store_log/g' squid.conf
grep "cache_store" squid.conf
============================================
[root@Squid etc]# grep "cache_store" squid.conf
# TAG: cache_store_log
cache_store_log /application/squid3.0/var/logs/store.log
============================================
 

#打开缓存log

============================================
grep cache_log squid.conf
sed -i 's/# cache_log/cache_log/g' squid.conf
grep cache_log squid.conf
============================================
[root@Squid etc]# grep cache_log squid.conf
# TAG: cache_log
cache_log /application/squid3.0/var/logs/cache.log
============================================
 

#####修改缓存目录,也可以配置多个

grep cache_dir squid.conf
sed -i 's%# cache_dir ufs /application/squid3.0/var/cach%cache_dir ufs /application/squid3.0/var/cach%g' squid.conf
grep cache_dir squid.conf
============================================
[root@Squid etc]# grep cache_dir squid.conf
# Applies to any cache_dir lines listed below this.
# TAG: cache_dir
# cache_dir Type Directory-Name Fs-specific-data [options]
# You can specify multiple cache_dir lines to spread the
# cache_dir ufs Directory-Name Mbytes L1 L2 [options]
# cache_dir aufs Directory-Name Mbytes L1 L2 [options]
# cache_dir diskd Directory-Name Mbytes L1 L2 [options] [Q1=n] [Q2=n]
# block-size=n defines the "block size" for COSS cache_dir's.
# leads to a maximum cache_dir size of 512<<24, or 8 GB. Note
# has written some objects to the cache_dir.
# no-store, no new objects should be stored to this cache_dir
# the cache_dir lines with the smallest max-size value first and the
cache_dir ufs /application/squid3.0/var/cache 100 16 256
# 'cache_dir' directory, but you may specify an alternate
# a representation of the cache_dir name where each / is replaced
# with '.'. This is needed to allow adding/removing cache_dir
# If have more than one 'cache_dir', and %s is not used in the name
# corresponds to the order of the 'cache_dir' lines in this
# configuration file. If you change the order of the 'cache_dir'
# the correct 'cache_dir' entry (unless you manually rename
# better to keep these index files in each 'cache_dir' directory.
[root@Squid etc]#
============================================
 

##编辑可见主机名,如果不配置,可能无法启动squid

sed -n '/visible_hostname/p' squid.conf
sed -i '/# TAG: visible_hostname/avisible_hostname img01.etiantian.org ' squid.conf
sed -n '/visible_hostname/p' squid.conf
============================================
[root@Squid etc]# sed -n '/visible_hostname/p' squid.conf
# TAG: visible_hostname
visible_hostname img01.etiantian.org
# 'visible_hostname' you must give each machine a different
[root@Squid etc]#
============================================
 

##配置配置管理员联系信息cache_mgr配置这个,在网站出问题的时候,客户可以找到我

sed -n '/cache_mgr /p' squid.conf
sed -i 's/# cache_mgr webmaster/cache_mgr 75685538@qq.com/g' squid.conf
sed -n '/cache_mgr /p' squid.conf
============================================
[root@Squid etc]# sed -n '/cache_mgr /p' squid.conf
cache_mgr 75685538@qq.com
[root@Squid etc]#
============================================
 

对比修改哪些内容:

##############################################################################
##############################################################################
[root@Squid etc]# diff squid.conf squid.conf.default
1710c1710
< cache_dir ufs /application/squid3.0/var/cache 100 16 256
---
> # cache_dir ufs /application/squid3.0/var/cache 100 16 256
1889c1889
< cache_log /application/squid3.0/var/logs/cache.log
---
> # cache_log /application/squid3.0/var/logs/cache.log
1899c1899
< cache_store_log /application/squid3.0/var/logs/store.log
---
> # cache_store_log /application/squid3.0/var/logs/store.log
2912c2912
< cache_mgr 75685538@qq.com
---
> # cache_mgr webmaster
2941,2942c2941
< cache_effective_user squid
< cache_effective_group squid
---
> # cache_effective_user nobody
2971d2969
< visible_hostname img01.etiantian.org
[root@Squid etc]#
##############################################################################
 

修改后的配置文件

[root@Squid etc]# egrep -v '^#|^$' squid.conf
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
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 # 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
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 deny all
icp_access allow localnet
icp_access deny all
htcp_access allow localnet
htcp_access deny all
http_port 3128
hierarchy_stoplist cgi-bin ?
cache_dir ufs /application/squid3.0/var/cache 100 16 256
access_log /application/squid3.0/var/logs/access.log squid
cache_log /application/squid3.0/var/logs/cache.log
cache_store_log /application/squid3.0/var/logs/store.log
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern (cgi-bin|\?) 0 0% 0
refresh_pattern . 0 20% 4320
cache_mgr 75685538@qq.com
cache_effective_user squid
cache_effective_group squid
visible_hostname img01.etiantian.org
icp_port 3130
coredump_dir /application/squid3.0/var/cache
[root@Squid etc]#
##############################################################################
 

##启动squid

[root@Squid etc]# /application/squid/sbin/squid -h
Usage: squid [-cdhvzCDFNRVYX] [-s | -l facility] [-f config-file] [-[au] port] [-k signal]
-a port Specify HTTP port number (default: 3128).
-d level Write debugging to stderr also.
-f file Use given config-file instead of
/application/squid3.0/etc/squid.conf
-h Print help message.
-k reconfigure|rotate|shutdown|interrupt|kill|debug|check|parse
Parse configuration file, then send signal to
running copy (except -k parse) and exit.
-s | -l facility
Enable logging to syslog.
-u port Specify ICP port number (default: 3130), disable with 0.
-v Print version.
-z Create swap directories
-C Do not catch fatal signals.
-D Disable initial DNS tests.
-F Don't serve any requests until store is rebuilt.
-N No daemon mode.
-R Do not set REUSEADDR on port.
-S Double-check swap during rebuild.
-X Force full debugging.
-Y Only return UDP_HIT or UDP_MISS_NOFETCH during fast reload.
 

简单命令说明:

/application/squid/sbin/squid -z 初始化缓存空间
/application/squid/sbin/squid 启动
/application/squid/sbin/squid -k shutdown 停止
/application/squid/sbin/squid -k reconfigure 重新载入配置文件
/application/squid/sbin/squid -k rotate 轮循日志
/application/squid/sbin/squid -k parse检查语法
 

#检查配置文件语法

/application/squid/sbin/squid -k parse
chown -R squid.squid /application/squid3.0/var/logs/
/application/squid/sbin/squid -k parse
=====================================================================
[root@Squid etc]# /application/squid/sbin/squid -k parse
2015/09/08 11:23:45| Processing Configuration File: /application/squid3.0/etc/squid.conf (depth 0)
2015/09/08 11:23:45| Initializing https proxy context
WARNING: Cannot write log file: /application/squid3.0/var/logs/cache.log
/application/squid3.0/var/logs/cache.log: Permission denied 《=============语法问题。这个文件没有出现
messages will be sent to 'stderr'.
[root@Squid etc]# chown -R squid.squid /application/squid3.0/var/logs/
[root@Squid etc]# /application/squid/sbin/squid -k parse
2015/09/08 11:24:49| Processing Configuration File: /application/squid3.0/etc/squid.conf (depth 0)
2015/09/08 11:24:49| Initializing https proxy context
[root@Squid etc]#
=====================================================================
 

###设置环境变量

  echo 'export PATH=$PATH:/application/squid/sbin:=/application/squid/bin '>>/etc/profile
. /etc/profile
echo $PATH
 

###初始化squid

grep cache_dir squid.conf
ll /application/squid3.0/var/cache
ll /application/squid3.0/var/
squid -z /application/squid3.0/var/
chown -R squid.squid /application/squid3.0/var
squid -z /application/squid3.0/var/
tree /application/squid3.0/var/ |wc -l =====================================================================
[root@Squid etc]# grep cache_dir squid.conf
# Applies to any cache_dir lines listed below this.
# TAG: cache_dir
# cache_dir Type Directory-Name Fs-specific-data [options]
# You can specify multiple cache_dir lines to spread the
# cache_dir ufs Directory-Name Mbytes L1 L2 [options]
# cache_dir aufs Directory-Name Mbytes L1 L2 [options]
# cache_dir diskd Directory-Name Mbytes L1 L2 [options] [Q1=n] [Q2=n]
# block-size=n defines the "block size" for COSS cache_dir's.
# leads to a maximum cache_dir size of 512<<24, or 8 GB. Note
# has written some objects to the cache_dir.
# no-store, no new objects should be stored to this cache_dir
# the cache_dir lines with the smallest max-size value first and the
cache_dir ufs /application/squid3.0/var/cache 100 16 256
# 'cache_dir' directory, but you may specify an alternate
# a representation of the cache_dir name where each / is replaced
# with '.'. This is needed to allow adding/removing cache_dir
# If have more than one 'cache_dir', and %s is not used in the name
# corresponds to the order of the 'cache_dir' lines in this
# configuration file. If you change the order of the 'cache_dir'
# the correct 'cache_dir' entry (unless you manually rename
# better to keep these index files in each 'cache_dir' directory.
[root@Squid etc]# ll /application/squid3.0/var/cache
ls: cannot access /application/squid3.0/var/cache: No such file or directory
[root@Squid etc]#
[root@Squid etc]#
[root@Squid etc]# ll /application/squid3.0/var/
total 4
drwxr-xr-x. 2 squid squid 4096 Nov 10 00:15 logs
[root@Squid etc]# squid -z /application/squid3.0/var/
2015/11/10 10:09:45| Creating Swap Directories
FATAL: Failed to make swap directory /application/squid3.0/var/cache: (13) Permission denied
[root@Squid etc]# chown -R squid.squid /application/squid3.0/var
[root@Squid etc]# squid -z /application/squid3.0/var/
2015/11/10 10:10:09| Creating Swap Directories
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/00
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/01
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/02
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/03
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/04
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/05
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/06
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/07
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/08
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/09
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/0A
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/0B
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/0C
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/0D
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/0E
2015/11/10 10:10:09| Making directories in /application/squid3.0/var/cache/0F
[root@Squid etc]# tree /application/squid3.0/var/ |wc -l
4118
[root@Squid etc]#
=====================================================================
 

###启动squid

squid  -N -d1
初始化cache目录后,就可以在终端窗口里运行squid,将日志记录到标准输出,这样就可以轻易的定位任何错误或者问题,并且确认squid是否成功启动,使用-N参数,会持续squid在前台运行。-d1选项在标准错误里显示1级错误的调试信息,假如你看到错误信息,你该首先修正它,一旦你见到“Ready to serve requests. ”消息,就可用一些http请来测试squid。
=====================================================================
[root@Squid etc]# squid -N -d1
2015/09/08 11:37:46| Starting Squid Cache version 3.0.STABLE20 for x86_64-unknown-linux-gnu...
2015/09/08 11:37:46| Process ID 51053
2015/09/08 11:37:46| With 20480 file descriptors available
2015/09/08 11:37:46| Performing DNS Tests...
2015/09/08 11:37:46| Successful DNS name lookup tests...
2015/09/08 11:37:46| helperOpenServers: Starting 5/5 'dnsserver' processes
2015/09/08 11:37:46| User-Agent logging is disabled.
2015/09/08 11:37:46| Referer logging is disabled.
2015/09/08 11:37:47| Unlinkd pipe opened on FD 14
2015/09/08 11:37:47| Swap maxSize 102400 + 8192 KB, estimated 8507 objects
2015/09/08 11:37:47| Target number of buckets: 425
2015/09/08 11:37:47| Using 8192 Store buckets
2015/09/08 11:37:47| Max Mem size: 8192 KB
2015/09/08 11:37:47| Max Swap size: 102400 KB
2015/09/08 11:37:47| Version 1 of swap file without LFS support detected...
2015/09/08 11:37:47| Rebuilding storage in /application/squid3.0/var/cache (CLEAN)
2015/09/08 11:37:47| Using Least Load store dir selection
2015/09/08 11:37:47| Set Current Directory to /application/squid3.0/var/cache
2015/09/08 11:37:47| Loaded Icons.
2015/09/08 11:37:47| Accepting HTTP connections at 0.0.0.0, port 3128, FD 16.
2015/09/08 11:37:47| Accepting ICP messages at 0.0.0.0, port 3130, FD 17.
2015/09/08 11:37:47| HTCP Disabled.
2015/09/08 11:37:47| Pinger socket opened on FD 19
2015/09/08 11:37:47| Ready to serve requests. <=================表示成功
2015/09/08 11:37:47| Done reading /application/squid3.0/var/cache swaplog (0 entries)
2015/09/08 11:37:47| Finished rebuilding storage from disk.
2015/09/08 11:37:47| 0 Entries scanned
2015/09/08 11:37:47| 0 Invalid entries.
2015/09/08 11:37:47| 0 With invalid flags.
2015/09/08 11:37:47| 0 Objects loaded.
2015/09/08 11:37:47| 0 Objects expired.
2015/09/08 11:37:47| 0 Objects cancelled.
2015/09/08 11:37:47| 0 Duplicate URLs purged.
2015/09/08 11:37:47| 0 Swapfile clashes avoided.
2015/09/08 11:37:47| Took 0.02 seconds ( 0.00 objects/sec).
2015/09/08 11:37:47| Beginning Validation Procedure
2015/09/08 11:37:47| Completed Validation Procedure
2015/09/08 11:37:47| Validated 25 Entries
2015/09/08 11:37:47| store_swap_size = 0
2015/09/08 11:37:48| storeLateRelease: released 0 objects
=====================================================================
 

###不能停止另外一个窗口,查看是否启动

 netstat -lntup|grep 31
=====================================================================
[root@Squid ~]# netstat -lntup|grep 31
tcp 0 0 0.0.0.0:3128 0.0.0.0:* LISTEN 6993/squid
udp 0 0 0.0.0.0:3130 0.0.0.0:* 6993/squid
[root@Squid ~]#
=================================================================
 

====

#上面的是普通代理

用法:

打开IE浏览器>工具>连接>局域网设置>为LAN使用代理服务器

把squid服务器ip和3128端口填上去即可

之后重新打开IE,浏览网页。

一边看日志,一般通过IE浏览,会看到访问日志不停滚动

tailf /application/squid/var/logs/access.log

看服务器日志

=================
[root@Squid ~]# tailf /application/squid/var/logs/access.log
1447122191.894 23 10.0.0.1 TCP_MISS/200 7428 GET http://img.firefoxchina.cn/2015/11/8/201511090953240.jpg - DIRECT/222.186.20.109 image/jpeg
1447122191.895 24 10.0.0.1 TCP_MISS/200 5339 GET http://img.firefoxchina.cn/2015/11/8/201511090954000.jpg - DIRECT/58.220.2.124 image/jpeg
1447122191.900 29 10.0.0.1 TCP_MISS/200 20789 GET http://img.firefoxchina.cn/2015/11/4/201511100926100.jpg - DIRECT/58.220.2.10 image/jpeg
1447122191.901 27 10.0.0.1 TCP_MISS/200 25635 GET http://img.firefoxchina.cn/2015/11/8/201511091118200.jpg - DIRECT/58.217.195.246 image/jpeg
1447122191.916 41 10.0.0.1 TCP_MISS/200 6183 GET http://img.firefoxchina.cn/2015/11/8/201511091539590.jpg - DIRECT/222.186.20.123 image/jpeg
1447122193.337 30012 10.0.0.1 TCP_MISS/200 2878 CONNECT g.alicdn.com:443 - DIRECT/222.73.134.40 -
1447122193.493 30011 10.0.0.1 TCP_MISS/200 2878 CONNECT img.alicdn.com:443 - DIRECT/101.226.178.140 -
[root@Squid ~]# tree /application/squid3.0/var/cache/|wc -l
4714
[root@Squid ~]#
[root@Squid ~]# tree /application/squid3.0/var/cache/|wc -l
4847
[root@Squid ~]#
##################################前面的就是普通代理模式
#######设置开机自启动
/application/squid/sbin/squid -D ##-D 参数指后台运行
echo "start squid">>/etc/rc.local
echo "/application/squid/sbin/squid -D">>/etc/rc.local
tail -2 /etc/rc.local
######################################################
 

设置启动脚本

 #!/bin/sh
################################################
#this scripts is created by gao at 20150908
#gao lvnian
################################################
#!/bin/bash #
# chkconfig: 345 89 24
# description: squid is a web cache server
# processname: squid
. /etc/rc.d/init.d/functions
function_start_squid()
{
/application/squid/sbin/squid -D
if [ $? == "0" ];then
action " $1 squid..." /bin/true
sleep 3
echo "-----------------------check ing-----------------------------"
netstat -lntup|egrep '31|squid'
echo "-----------------------check over-----------------------------"
else
action " $1 squid..." /bin/failed
echo "please check the log"
fi
}
#stop function
function_stop_squid()
{
/application/squid/sbin/squid -k shutdown
if [ $? == "0" ];then
action "$1 squid..." /bin/true
else
action "$1 squid..." /bin/failed
echo "please check the log"
fi
}
#restart function
function_restart_squid()
{
printf "Restarting squid...\n"
function_stop_squid
sleep 2
function_start_squid
}
case $1 in
start)
function_start_squid
;;
stop)
function_stop_squid
;;
restart)
function_restart_squid
;;
*)
printf "Usage: $0 {start|stop|restart}\n"
esac
========================================================
把这个文件放到/etc/init.d/目录下并命名为squid
chmod +x /etc/init.d/squid
chkconfig --add squid
========================================================
[root@Squid ~]# chmod +x /etc/init.d/squid
[root@Squid ~]# chkconfig --add squid
[root@Squid ~]# chkconfig --list squid
squid 0:off 1:off 2:off 3:on 4:on 5:on 6:off
[root@Squid ~]#
 

##设置日志轮询

 /application/squid/sbin/squid -k rotate
查看日志
[root@Squid ~]# ll /application/squid/var/logs/
total 276
-rw-r----- 1 squid squid 99547 Sep 8 13:05 access.log
-rw-r----- 1 squid squid 28301 Sep 8 13:05 cache.log
-rw-r--r-- 1 root squid 6 Sep 8 13:03 squid.pid
-rw-r----- 1 squid squid 134582 Sep 8 13:05 store.log
[root@Squid ~]# /application/squid/sbin/squid -k rotate
[root@Squid ~]# ll /application/squid/var/logs/
total 284
-rw-r----- 1 squid squid 0 Sep 8 13:08 access.log
-rw-r----- 1 squid squid 100020 Sep 8 13:08 access.log.0
-rw-r----- 1 squid squid 458 Sep 8 13:08 cache.log
-rw-r----- 1 squid squid 28301 Sep 8 13:05 cache.log.0
-rw-r--r-- 1 root squid 6 Sep 8 13:03 squid.pid
-rw-r----- 1 squid squid 0 Sep 8 13:08 store.log
-rw-r----- 1 squid squid 135372 Sep 8 13:08 store.log.0
[root@Squid ~]#
#######设置切换时名称改为时间类型
脚本
echo "0 0 * * * /bin/sh /server/script/rotate_squid.sh" >>/var/spool/cron/root
crontab -l
####################
mkdir -p /server/script/
cat > /server/script/rotate_squid.sh <EOF
#!/bin/sh
cd /application/squid/var/logs/
[ -f access.log ] && mv access.log access_`data +%F`.log
/application/squid/sbin/squid -k rotate
EOF
===================================================================
[root@Squid script]# cat rotate_squid.sh
#!/bin/sh
cd /application/squid/var/logs/
[ -f access.log ] && access.log access_`data +%F`.log
/application/squid/sbin/squid -k rotate
[root@Squid script]#
[root@Squid script]# cat rotate_squid.sh
#!/bin/sh
cd /application/squid/var/logs/
[ -f access.log ] && {
for n in `ls *.log`
do
mv $n $n.`date +%F.%N`
done
}
/application/squid/sbin/squid -k rotate
[root@Squid script]#
================================================================
 

到这来一个完整的squid代理服务器就安装完成了

###配置管理页面

1.squid有一个cachemgr.cgi 的程序,可以用web来显示内容,这个对调整squid的参数很方便,平时我们安装完squid后,其实就有这个程序了,只有我们在apache下做相应的配置即可

========================================
ScriptAlias "/squid" "/application/squid3.0/libexec/cachemgr.cgi"
<Location "/squid">
Orderdeny,allow
Denyfrom all
Allowfrom all
</Location>
#cachemgr_passwd lvnian config ##这个如果启动。第一个lvnian是密码,第二个config是行为
##修改一个端口为8080(可选)
Listen 8080
========================================
2.直接打开测试接可以了,默认好像是不用密码和用户的,记住端口即可
http://ip/squid
http://10.0.0.4:8080/squid
 

实战

配置ACL

##############################
acl lvnian url_regex -i ^http://.*baidu.* ##禁止访问http开头,且保护oldboy字符串的网站
acl lvnian1 url_regex -i ^http://.*51.*| .*taobao.* ##禁止访问http开头,且保护oldboy字符串的网站,或者包含aobao字符串的网站网站
http_access deny lvnian
http_access deny lvnian1
 

提示:注意放置的位置:

[root@Squid etc]# vim squid.conf
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
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 # 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
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
###########################
acl lvnian url_regex -i ^http://.*baidu.*
acl lvnian1 url_regex -i ^http://.*51.*| .*taobao.*
http_access deny lvnian
http_access deny lvnian1
############################
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 deny all
icp_access allow localnet
icp_access deny all
htcp_access allow localnet
htcp_access deny all
http_port 3128
hierarchy_stoplist cgi-bin ?
"squid.conf" 50L, 1932C written
[root@Squid etc]# /etc/init.d/squid restart
Restarting squid...
squid... [ OK ]
squid... [ OK ]
-----------------------check ing-----------------------------
udp 0 0 0.0.0.0:3130 0.0.0.0:* 7112/(squid)
-----------------------check over-----------------------------
[root@Squid etc]#
 

这个时候你就无法访问51cto的网站,百度网站,以及淘宝的网站了。

部署完成

普通代理分为两种:

一种是普通代理服务器:

作为代理服务器,这是Squid的最基本的功能;通过在squid.conf配置文件添加一系列的访问及控制规则,用户在客户端设置服务器地址和端口,即可通过squid访问internet,在下面的规则里,squid实现局域网用户和高速缓存功能:

即通过浏览器设置代理服务器地址共享上网,这种方式不需要代理服务器在网络的出入口的位置,只需要代理服务器能够上网即可,其他的客户端就可以通过IE等客户端设置代理服务器的地址及端口进行上网。上一篇文件就是这样的一个例子。这个技术以及落后了。

另外一种就是透明代理,所谓的透明代理,是相对于代理服务器而已,客户端不需要做任何和代理服务器相关的设置和操作,对用户而言,感觉不到代理服务器的存在,所以称之为透明代理。即把代理服务器部署在核心的上网出口,当用户上网浏览页面时,会交给代理服务器向外请求,如果结合iptables可以实现代理+网关+内容过滤+浏览安全控制等完整的上网解决方案

透明代理流程说明:

用户A发送一个访问请求到防火墙,有防火墙将该用户的访问请求转发给SQUID,SQUID在先检查自身缓存中有无该用户请求的访问的内容,如果没有,则请求远端目的服务器,获取该用户的访问内容,在返回给用户的同事,自身也缓存保留一份记录,以备下次调用,当用户B发送一个和用户A刚才访问的相同请求时,由防火墙将转发该用户请求到SQUID,squid检查自身缓存,发现有同样的内容后,直接将该内容返回给用户,而无需再去向源站点请求。

注意:在实际使用中,通常将squid和防火墙放在同一台服务器上。

透明代理的好处:

上网行为控制

节约网站带宽成本

提升员工上网速度

squid可以为局域网中的客户端做代理,用来加速用户的网页访问,第一次访问的时候,squid会把数据缓存到服务器上,当客户端第二次访问的时候,squid会对比文件的新旧,如果文件没有发送变化,则squid直接返回给用户数据,不需要在互联网上重新下载一份。

squid有没代理物理拓扑说明

作为透明代理服务器,一般和公司的上网网关放在一起,即所以的客户机的网关都设置为代理服务器的IP,具体需求如下

a、至少有两块网卡,一块连接路由器,一块连接内部网络

b、所以的上网请求都不行经过代理服务器(即把代理服务器设置为网关)

下面我部署的透明代理如下:

需要两块网卡

eth0 10.0.0.4
eth1 172.16.1.1
 

如果要实现透明代理,在编译安装squid的时候需要添加下面编译参数

./configure \
--enable-linux-entfilter
--enable-linux-tproxy
 

##部署方法

#在squid.conf 中的http——port 3128 后面加transparent参数。这个是核心参数,有这个参数就可以了。

grep "http_port 3128" squid.conf
sed -i 's/http_port 3128/http_port 3128 transparent/g' squid.conf
grep "http_port 3128" squid.conf
 

#增加几个参数,这些是调优参数,不是必须的

#cache_mem 128 MB#这是一个优化选项,增加该内存值有利于缓存。应该注意的是:  一般来说如果系统有内存,设置该值为(n/)3M。现在是3G 所以这里1G
#cache_swap_low 90#最小允许使用swap 90%
#cache_swap_high 95#最多允许使用swap 95%
#maximum_object_size 8192 KB#允午最大文件请求体大小
#minimum_object_size 0 KB#允午最小文件请求体大小
#maximum_object_size_in_memory 4096 KB#允许最大的文件载入内存
#emulate_httpd_log on#将使Squid仿照Web服务器的格式创建访问记录。如果希望使用
#memory_replacement_policy lru ##缓存算法,保持最近使用的
##sed名称操作如下:
sed -i '/http_port 3128/acache_mem 128 MB\ncache_swap_low 90\ncache_swap_high 95' squid.conf
sed -i '/cache_swap_high/a \nmaximum_object_size 8192 KB\nminimum_object_size 0 KB\nmaximum_object_size_in_memory 4096 KB\nemulate_httpd_log on\nmemory_replacement_policy lru' squid.conf
sed -n '/http_port 3128/,+9p' squid.conf
=========================================================
[root@Squid etc]# sed -n '/http_port 3128/,+9p' squid.conf
http_port 3128 transparent
cache_mem 64 MB
cache_swap_low 90
cache_swap_high 95
nmaximum_object_size 8192 KB
minimum_object_size 0 KB
maximum_object_size_in_memory 4096 KB
emulate_httpd_log on
memory_replacement_policy lru
hierarchy_stoplist cgi-bin ?
[root@Squid etc]#
=========================================================
 

##防火墙设置

iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-ports 3128
iptables -t nat -A POSTROUTING -o eth0 -s 172.16.1.0/24 -j MASQUERADE
iptables -t nat -L -nv
===========================================================
[root@Squid etc]# iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-ports 3128
[root@Squid etc]# iptables -t nat -A POSTROUTING -o eth0 -s 172.16.1.0/24 -j MASQUERADE
[root@Squid etc]# iptables -t nat -L -nv
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 REDIRECT tcp -- eth1 * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 redir ports 3128
Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 MASQUERADE all -- * eth0 172.16.1.0/24 0.0.0.0/0
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
[root@Squid etc]#
===========================================================
 

#开启转发功能

sed -i 's#net.ipv4.ip_forward = 0#net.ipv4.ip_forward = 1#g' /etc/sysctl.conf
sysctl -p
 

####这样就设置成功了

我们在用一台服务器,设置只有内网网卡,网段在172.16.1.0/24 网段。把网关设置为172.16.1.1.用它访问外网。这样就可以了,

一边访问web,一般查看squid的日志

[root@Squid ~]# tailf /application/squid/var/logs/access.log
1441695622.825 52 172.16.1.100 TCP_MISS/200 97207 GET http://www.baidu.com/ - DIRECT/115.239.211.112 text/html
1441695625.005 52 172.16.1.100 TCP_MISS/200 97406 GET http://www.baidu.com/ - DIRECT/115.239.210.27 text/html
1441695709.770 208 172.16.1.100 TCP_MISS/200 727503 GET http://www.163.com/ - DIRECT/114.80.143.158 text/html
 

##TCP_MISS  代表没有缓冲

普通代理方式是代理内部网络用户访问Internet上服务器的连接请求,客户端必须指定代理服务器,并将本来要直接发送到internet上服务器的连接请求发送给代理服务器处理。

反向代理方式是指以代理服务器来接受Internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外表现问一台服务器。

1、反向代理流程说明:

squid做为反向代理服务器,通常工作在一个服务器集群的前端,在用户端看来,squid服务器就是他所要访问的服务器,而实际意义上squid只是接受用户的请求,同时将用户请求转发给内网真正的web服务器,如果squid本身有用户要访问的内容,则squid直接将内容返回给用户,而无需再去后端的服务器中请求

2、squid反向代理生产案例

很多大型门户网站,经常使用squid作为服务器的反向cache,提高了服务器的访问性能,这些cache服务器组有效减轻了后端web服务器的负载,并且提高了访问速度,在某种程度上保护了后端的web服务器。

3、squid反向代理的优点:

1.节约带宽(对CDN),自己在机房部署squid反向代理,不能节约带宽

2.提升用户体验

3.减轻服务器压力,减少WEB,存储,数据库的压力

公司购买CDN了,企业还需要在机房搭建squid反向代理

答:需求不大,有CDN了,静态业务命中到百分之90左右了,所以需求不大

在穿透CDN请求比较多的时候,超过web服务及其他存储,数据库的压力时候,需要部署squid

4、squid 反向代理如何获取数据更新

squid反向代理一般只缓存可缓存的数据(比如html页面,js,css和图片等静态数据),而一些CGI脚本程序或ASP、JSP、PHP之类的动态程序默认不缓存,它根据从WEB服务器返回的HTTP头标记来缓冲静态页面,有四个重要的HTTP头标记。

Last-Modified:告诉反向代理页面什么时间被修改;

Expries:告诉反向代理页面什么时间应该从缓冲区中删除

Cache-Control:告诉方向代理页面是否应该被缓存;

Pragma:用来包含实现特定的指令,最常见的是Pragma:no-Cache

优先级对比(no-cache,expries,max-age)参考

经验:在squid中Cache-Control:no-cache>expries>refresh_pattern>Last-Modified.考前面的最重要,前面的失效了,后面的基本也就失效了。

另外安装一台web服务器,作为源站。也就是RS

web 服务器ip是 10.0.0.4 端口为80

yum install httpd*
/etc/init.d/iptables stop
/etc/init.d/httpd start
netstat -lnt|grep 80
lsof -i :80
echo 111>/var/www/html/index.html
====================================================================
[root@WEB html]# ps -ef |grep http
root 1798 1 0 14:47 ? 00:00:00 /usr/sbin/httpd
apache 1800 1798 0 14:47 ? 00:00:00 /usr/sbin/httpd
apache 1801 1798 0 14:47 ? 00:00:00 /usr/sbin/httpd
apache 1802 1798 0 14:47 ? 00:00:00 /usr/sbin/httpd
apache 1803 1798 0 14:47 ? 00:00:00 /usr/sbin/httpd
apache 1804 1798 0 14:47 ? 00:00:00 /usr/sbin/httpd
apache 1805 1798 0 14:47 ? 00:00:00 /usr/sbin/httpd
apache 1806 1798 0 14:47 ? 00:00:00 /usr/sbin/httpd
apache 1807 1798 0 14:47 ? 00:00:00 /usr/sbin/httpd
root 1811 1743 0 14:49 pts/0 00:00:00 grep http
[root@WEB html]# netstat -lntup|grep 80
tcp 0 0 :::80 :::* LISTEN 1798/httpd
[root@WEB html]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 1798 root 4u IPv6 19044 0t0 TCP *:http (LISTEN)
httpd 1800 apache 4u IPv6 19044 0t0 TCP *:http (LISTEN)
httpd 1801 apache 4u IPv6 19044 0t0 TCP *:http (LISTEN)
httpd 1802 apache 4u IPv6 19044 0t0 TCP *:http (LISTEN)
httpd 1803 apache 4u IPv6 19044 0t0 TCP *:http (LISTEN)
httpd 1804 apache 4u IPv6 19044 0t0 TCP *:http (LISTEN)
httpd 1805 apache 4u IPv6 19044 0t0 TCP *:http (LISTEN)
httpd 1806 apache 4u IPv6 19044 0t0 TCP *:http (LISTEN)
httpd 1807 apache 4u IPv6 19044 0t0 TCP *:http (LISTEN)
[root@WEB html]#
[root@WEB html]# curl 10.0.0.4
111
[root@WEB html]#
====================================================================
 

在客户端打开检查看看是否正确

上传3张图片到web站点,后缀为jpg的图片

 [root@WEB html]# ls
1.jpg 1.png 2.jpg 3.jpg index.html K2.png keep1.png na1.png na2.png
[root@WEB html]#
http://10.0.0.4/1.jpg
http://10.0.0.4/2.jpg
http://10.0.0.4/3.jpg
 

在squid服务器(IP:10.0.0.3),设置squid.conf

#首先设置squid支持虚拟主机模式
host_port 8000 accel vhost vport ##加速模式 #设置squid运行的用户
cache_effective_user squid
cache_effective_group squid
#设置对哪里web做方向代理
cache_peer imag1.lvnian.org parent 80 0 no-query no-digest max-conn=32 originserver
#cache_peer vi.gis.cttic.cn parent 80 0 no-query no-digest max-conn 32 originserve
#设置缓存目录(squid吃没吃文件系统类型、缓存目录、目录大小Mbyte、第一层目录的文件数,第二层文件夹的数目)
cache_dir ufs /app/squid/cache 10000 16 256 cache_mem 128 MB
#这是一个优化选项,增加该内存值有利于缓存。应该注意的是: 一般来说如果系统有内存,设置该值为(n/)3M。现在是3G 所以这里1G
cache_swap_low 90 #最小允许使用swap 90%
cache_swap_high 95 #最多允许使用swap 95%
maximum_object_size 8192 KB #设置缓存在硬盘上的文件的最大大小
minimum_object_size 0 KB #设置缓存在硬盘上的文件的最小大小
maximum_object_size_in_memory 4096 KB#设置缓存在内存上的文件的大小
emulate_httpd_log on
#将使Squid仿照Web服务器的格式创建访问记录。如果希望使用
memory_replacement_policy lru #缓存算法,保持最近使用的 #设置这些方向代理的ACL,避免squid被恶意用户作为代理
acl my_allow_domain_list dstdomain imag1.lvnian.org
#acl my_allow_domain_list dstdomain vi.gis.cttic.cn
#只允许我们定义的域名my_allow_domain_list
cache_peer_access imag1.lvnian.org vi.gis.cttic.cn #设置缓存过期时间
refresh_pattern -i \.jpg$ 30 50% 4320 reload-into-ims
refresh_pattern -i \.png$ 30 50% 4320 reload-into-ims
refresh_pattern -i \.gif$ 30 50% 4320 reload-into-ims
上面的意思是:如果某个响应驻留在cache里的时间没有超过这个30分钟最低的限制,那么他不会过期,类似最高限制4320分钟是存活响应的最高时间限制,如果某个响应驻留在你cache里的实际高于这个最高限制,那么它必须被刷新,在最低和最高时间限制之间的响应,会面对squid的最后修改系数(LM-factor)算法,对这样的响应,squid计算响应的年龄和最后修改的系数,然后将他作为百分比值进行比较,如果这个系数超过50%,那么这个响应必须被刷新
 

###################

squid缓存设置--控制页面的缓存时间

refresh_pattern的作用: 用于确定一个页面进入cache后,它在cache中停留的时间。

refresh_pattern 只对后端没设置Expires过期时间的页面起作用,比如论坛页面;而对类似apache mod_expires 设置过的页面不起作用。

语法:

refresh_pattern [-i] regexp min percent max [options
refresh_pattern -i \.css$ 1440 50% 129600 reload-into-ims
refresh_pattern -i \.xml$ 1440 50% 129600 reload-into-ims
refresh_pattern -i \.html$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.shtml$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.hml$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.jpg$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.png$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.gif$ 1440 90% 129600 ignore-reload
refresh_pattern -i \.bmp$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.js$ 1440 90% 129600 reload-into-ims
 

#指定hosts 文件

hosts_file /etc/hosts
request_header_max_size 128 KB
ipcache_size 1024
ipcache_low 90
ipcache_high 95
 

###在hosts中添加相应的解析

cp /etc/hosts /etc/hosts
echo -e "10.0.0.4 imag1.lvnian.org" >>/etc/hosts
 

##只有缓存完了,不管你在不在线,都会有。哪怕你把客户端端IE删除缓存,把后端的http服务关闭,也一样可以看到数据

offline_mode on
 

##定义日志格式

logformat squid %{X-Forwarded-For}>h %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st %tr "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
##应用日志格式
access_log /application/squid3.0/var/logs/access.log squid
 

###可以配置多个缓存目录

cache_dir aufs /data1/cache 94000 64 256
cache_dir aufs /data2/cache 94000 64 256
cache_dir aufs /data3/cache 94000 64 256
 

完整的配置文件如下:

[root@Squid etc]# cat squid.conf
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
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 # 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
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 deny all
icp_access allow localnet
icp_access deny all
htcp_access allow localnet
htcp_access deny all
###################################
http_port 80 accel vhost vport
#设置对哪里web做方向代理
cache_peer imag1.lvnian.org parent 80 0 no-query no-digest max-conn=32 originserver
cache_mem 64 MB
cache_swap_low 90
cache_swap_high 95
maximum_object_size 8192 KB
minimum_object_size 0 KB
maximum_object_size_in_memory 4096 KB
emulate_httpd_log on
memory_replacement_policy lru
###################################
hierarchy_stoplist cgi-bin ?
cache_dir ufs /application/squid3.0/var/cache 100 16 256
access_log /application/squid3.0/var/logs/access.log squid
cache_log /application/squid3.0/var/logs/cache.log
cache_store_log /application/squid3.0/var/logs/store.log
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern (cgi-bin|\?) 0 0% 0
refresh_pattern . 0 20% 4320
cache_mgr 75685538@qq.com
cache_effective_user squid
cache_effective_group squid
visible_hostname img01.etiantian.org
icp_port 3130
coredump_dir /application/squid3.0/var/cache
#######################################
refresh_pattern -i \.css$ 1440 50% 129600 reload-into-ims
refresh_pattern -i \.xml$ 1440 50% 129600 reload-into-ims
refresh_pattern -i \.html$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.shtml$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.htm$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.jpg$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.png$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.gif$ 1440 90% 129600 ignore-reload
refresh_pattern -i \.bmp$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.js$ 1440 90% 129600 reload-into-ims
#指定hosts 文件
hosts_file /etc/hosts
request_header_max_size 128 KB
ipcache_size 1024
ipcache_low 90
ipcache_high 95
cache_dir ufs /app/squid/cache 10000 16 256
offline_mode on
[root@Squid etc]#
 

###检查语法

[root@Squid etc]# squid -k parse
2015/09/08 16:54:32| Processing Configuration File: /application/squid3.0/etc/squid.conf (depth 0)
2015/09/08 16:54:32| WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP
2015/09/08 16:54:32| Initializing https proxy context
[root@Squid etc]#
上面是没错误的
#启动
[root@Squid etc]# /etc/init.d/squid restart
squid restart... [ OK ]
---------- -------------check ing-----------------------------
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 55119/(squid)
udp 0 0 0.0.0.0:3130 0.0.0.0:* 55119/(squid)
-----------------------check over-----------------------------
[root@Squid etc]#
 

#检查命中转态

curl -I -s 10.0.0.3/1.jpg|grep -i x-cache
[root@Squid ~]# curl -I -s 10.0.0.4/1.jpg|grep -i x-cache
X-Cache: HIT from img01.lvnian.org
[root@Squid ~]# curl -I -s 10.0.0.4/2.jpg|grep -i x-cache
X-Cache: HIT from img01.lvnian.org
[root@Squid ~]# curl -I -s 10.0.0.4/3.jpg|grep -i x-cache
X-Cache: HIT from img01.lvnian.org
[root@Squid ~]#
 

一边用windows浏览器访问下面地址,看能不能正确访问到10.0.0.4后端RS的内容。一边看10.0.0.3squid的日志文件。观察squid的代理情况

 http://10.0.0.3/1.jpg
http://10.0.0.3/2.jpg
http://10.0.0.3/3.jpg
 

学习Squid(三)的更多相关文章

  1. squid 三种代理实验

    squid 软件既可以做代理,也可以做实现缓存加速,大大降低服务器的I/O.. 1.其中squid代理分为三种,正向代理.透明代理.反向代理. (1)squid正向代理和squid透明代理都位客户端: ...

  2. Oracle学习笔记三 SQL命令

    SQL简介 SQL 支持下列类别的命令: 1.数据定义语言(DDL) 2.数据操纵语言(DML) 3.事务控制语言(TCL) 4.数据控制语言(DCL)  

  3. 从零开始学习jQuery (三) 管理jQuery包装集

    本系列文章导航 从零开始学习jQuery (三) 管理jQuery包装集 一.摘要 在使用jQuery选择器获取到jQuery包装集后, 我们需要对其进行操作. 本章首先讲解如何动态的创建元素, 接着 ...

  4. 前端学习 第三弹: JavaScript语言的特性与发展

    前端学习 第三弹: JavaScript语言的特性与发展 javascript的缺点 1.没有命名空间,没有多文件的规范,同名函数相互覆盖 导致js的模块化很差 2.标准库很小 3.null和unde ...

  5. Android Animation学习(三) ApiDemos解析:XML动画文件的使用

    Android Animation学习(三) ApiDemos解析:XML动画文件的使用 可以用XML文件来定义Animation. 文件必须有一个唯一的根节点: <set>, <o ...

  6. 三、Android学习第三天——Activity的布局初步介绍(转)

    (转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 三.Android学习第三天——Activity的布局初步介绍 今天总结下 ...

  7. JavaWeb学习总结(三)——Tomcat服务器学习和使用(二) 包含https 非对称秘钥 NB

    JavaWeb学习总结(三)--Tomcat服务器学习和使用(二) 一.打包JavaWeb应用 在Java中,使用"jar"命令来对将JavaWeb应用打包成一个War包,jar命 ...

  8. MyEclipse Spring 学习总结三 SpringMVC

    MyEclipse Spring 学习总结三 SpringMVC 一.SpringMVC原理 1.Springmvc 框架介绍 1)Spring 框架停工了构建Web应用程序的全功能MVC模块.Spr ...

  9. Quartz定时任务学习(二)web应用/Quartz定时任务学习(三)属性文件和jar

    web中使用Quartz 1.首先在web.xml文件中加入 如下内容(根据自己情况设定) 在web.xml中添加QuartzInitializerServlet,Quartz为能够在web应用中使用 ...

  10. MyBatis学习系列三——结合Spring

    目录 MyBatis学习系列一之环境搭建 MyBatis学习系列二——增删改查 MyBatis学习系列三——结合Spring MyBatis在项目中应用一般都要结合Spring,这一章主要把MyBat ...

随机推荐

  1. centos网络配置、虚拟机克隆

    查看网卡命令: ifconfig 查看网络配置 ifconfig -a 查看隐藏网卡 window下使用ipconfig 网络配置 设置静态IP,修改/etc/sysconfig/network-sc ...

  2. 我遇到移动端ios系统遇到的一些坑和解决办法

    我是作为一个H5移动端开发.主要是做跨平台兼容ios系统和Android系统. 在移动端中,最让我头疼的不是功能,不是业务逻辑.而是适配.俗话说:移动端适配是最头疼的事情,也是头发掉得最快的时候. 我 ...

  3. qt日常积累

    http://blog.sina.com.cn/s/blog_b8bcba160102yyi3.html

  4. JZ-059-按之字形顺序打印二叉树

    按之字形顺序打印二叉树 题目描述 请实现一个函数按照之字形打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印,其他行以此类推. 题目链接: 按之字形 ...

  5. 一台电脑设置多个网段的IP地址

                    

  6. Mysql引擎、隔离机制、存储结构、索引

    目录 数据库常用的两种引擎 两种引擎差异对比 如何选择引擎 两个引擎索引结构 查找mysql数据存储位置方式 MyISAM InnoDB 1. 非独立表空间 2. 独立表空间 3. idb文件存的哪些 ...

  7. 前端—我的第一篇博客 梦开始的地方(面向对象版tab栏)

    这是我的第一篇博客 博客生涯才开始 但是人生已经过去了二十个年头了 才开始弄这个 也没搞得太懂 我原本的想法是想搞个源代码上来 但是看了半天好像就只能传html源代码 那我还有css js的部分呢 我 ...

  8. python算法 前缀和

    这里有 n 个航班,它们分别从 1 到 n 进行编号.有一份航班预订表 bookings ,表中第 i 条预订记录 bookings[i] = [firsti, lasti, seatsi] 意味着在 ...

  9. CVE-2015-3337(任意文件读取)

    vulhub漏洞环境搭建: https://blog.csdn.net/qq_36374896/article/details/84102101 启动docker环境 cd vulhub-master ...

  10. async-validator 源码学习笔记(四):validator

    系列文章: 1.async-validator 源码学习(一):文档翻译 2.async-validator 源码学习笔记(二):目录结构 3.async-validator 源码学习笔记(三):ru ...