78144666 发表于 2018-12-26 10:38:06

squid集群,cdn

  cdn有两个重要的功能,一个icp将dns解析下放给cdn提供商,cdn通过dns将用户访问的地址解析出离用户最近的server的IP地址;第二个功能使利用squid做一个cache加速。


[*]cdn的dns:192.168.0.31

[*]squid1:192.168.0.171

[*]squid2:192.168.0.40

[*]squid3:192.168.0.52

[*]server1:192.168.0.31

[*]server2:192.168.0.63

  配置cdn的dns


[*]yum install bind-utils bind -y
[*]cd /etc/
[*]vim named.conf
[*]在option块中去掉listen-on port 53 { 127.0.0.1; };
[*]加入一下内容:
[*]allow-query   { localhost; localnets; };
[*]         sortlist {
[*]                { localhost;
[*]                        { 192.168.0.52;
[*]                              { 192.168.0.40; 192.168.0.171; };
[*]                        };
[*]                };   #意为从localhost网段发来的请求,首先解析道德IP是192.168.0.52,如果192.168.0.52不能用则
[*]发给下面两个IP
[*]
[*]                { 192.168.0.0/24;
[*]                        { 192.68.0.40;
[*]                              { 192.168.0.171; 192.168.0.52; };
[*]                        };
[*]                }; #意为从192.168.0.0/24网段发来的请求,首先解析道德IP是192.168.0.40,如果192.168.0.52不能用则 发给下面两个IP
[*]      };



[*]vim /etc/named.rfc1912.zones
[*]zone "westos.org" IN {
[*]      type master;
[*]      file "westos.org.zone";
[*]      allow-update { none; };
[*]};
[*]
[*]zone "cdn.com" IN {
[*]      type master;
[*]      file "cdn.com.zone";
[*]      allow-update { none; };
[*]};
[*]cd /var/named
[*]cp -p named.localhost cdn.com.zone
[*]cp -p named.localhost westos.org.zone #注意权限问题
[*]vim cdn.com.zone
[*]$TTL 1D
[*]@       IN SOA@ root@localhost. (
[*]                                        0       ; serial
[*]                                        1D      ; refresh
[*]                                        1H      ; retry
[*]                                        1W      ; expire
[*]                                        3H )    ; minimum
[*]      NS      @
[*]      A       127.0.0.1
[*]cache   A       192.168.0.171
[*]cache   A       192.168.0.40
[*]cache   A       192.168.0.52
[*]vim westos.org.zone
[*]$TTL 1D
[*]@       IN SOA@ root@localhost. (
[*]                                        0       ; serial
[*]                                        1D      ; refresh
[*]                                        1H      ; retry
[*]                                        1W      ; expire
[*]                                        3H )    ; minimum
[*]      NS      @
[*]      A       127.0.0.1
[*]www   IN CNAME      cache.cdn.com.
[*]/etc/init.d/named start
[*]vim /etc/resolv.conf
[*]nameserver 192.168.0.31

  配置squid1:


[*]vim /etc/squid/squid.conf
[*]visible_hostname desktop171.example.com # 设定 squid 的主机名
[*]http_port 80 accel vhost vport #配置 squid 为加速模式,vhost和vport分别指支持以域名的虚拟目录和以ip的虚拟目录
[*]icp_port 3130
[*]
[*]# 配置 squid2和squid3 为其邻居,当 squid1 在其缓存中没有找到请求的资源时,通过 ICP 查询去其邻居中取得缓存
[*]cache_peer 192.168.0.40 sibling 80 3130
[*]cache_peer 192.168.0.52 sibling 80 3130
[*]
[*]#squid1 的两个父节点,originserver 参数指明是源服务器,round-robin 参数指明 squid 通过轮询方式将请求分发到其中一台父节;squid 同时会对这些父节点的健康状态进行检查,如果父节点down 了,那么 squid 会从剩余的 origin 服务器中抓取数据
[*]cache_peer 192.168.0.63 parent 80 0 no-query originserver round-robin name=web1
[*]cache_peer 192.168.0.31 parent 80 0 no-query originserver round-robin name=web2
[*]cache_peer_domain web1 web2 www.westos.org #将www.westos.org 域的请求通过 RR 轮询方式转发到两个父节点中的一个
[*]
[*]cache_mem 64 MB #squid 用于缓存的内存量

  #对 squid 的一些优化 根据系统实际情况而定,默认都有设置


[*]maximum_object_size 10240 KB ### 能缓存的最大对象为 10M
[*]maximum_object_size_in_memory 512 KB ### 内存中缓存的最大对象 512K

squid2 和 squid3 服务器的配置方法和配置参数和 squid1 一样,只有邻居那块的配置稍有不同,配置完成后,分别启动squid 服务。接下来查看日志文件观察状态


[*]# tail -f /var/log/squid/cache.log
[*]2012/06/10 11:45:11| Accepting ICP messages at [::]:3130, FD 14.
[*]2012/06/10 11:45:11| HTCP Disabled.
[*]2012/06/10 11:45:11| Configuring Sibling 192.168.0.40/80/3130
[*]2012/06/10 11:45:11| Configuring Sibling 192.168.0.52/80/3130
[*]2012/06/10 11:45:11| Configuring Parent 192.168.0.63/80/0
[*]2012/06/10 11:45:11| Configuring Parent 192.168.0.31/80/0



测试

在客户端输入http://www.westos.org,则正确的显示该网页。服务器端的响应对客户端是透明的,客户端不知道请求是由哪台 WEB 服务器处理的;而且其中某台 Squid 服务器或 WEB 服务器发生故障,也不影响服务的正常运行。

利用squid的反向代理技术可以提高网站系统的访问速度, squid 反向代理服务器加速了网站的性能,同时结合 DNS 轮询技术实现了网站的负载均衡。







页: [1]
查看完整版本: squid集群,cdn