项目笔记:4.引入CDN内容分发网络,实现网站静态元素加速 squid


1、在192.168.0.6和192.168.0.7上安装squid

开两台虚拟机ip为0.6,0.7 只需搭建本地系统的yum源

# yum -y install squid

一台 父squid和一台子squid多重缓存加速访问。如果访问子squid,子squid没有就会访问父squid,层层上去,父squid没有才去访问原始地址。

2、在父squid192.168.0.6上配置

<pre name="code" class="html"># vim /etc/squid/squid.conf
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 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 Safe_ports port 3130    #icp
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 deny all
http_port 3128 vhost vport
icp_port 3130
hierarchy_stoplist cgi-bin ?
cache_mem 100 MB
cache_dir ufs /var/spool/squid 100 16 256
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 .       0   20% 4320
cache_peer 192.168.0.2 parent 80 0 no-query originserver no-digest name=w1
cache_peer 192.168.0.2 parent 80 0 no-query originserver no-digest name=w2
cache_peer 192.168.0.3 parent 80 0 no-query originserver no-digest name=w3
cache_peer 192.168.0.3 parent 80 0 no-query originserver no-digest name=w4
cache_peer 192.168.0.6 sibling 3128 3130 name=cache0  --父squid
cache_peer 192.168.0.7 sibling 3128 3130 name=cache1  <span style="font-family: Arial, Helvetica, sans-serif;">-子squid</span>
cache_peer_domain w1    bbs1.kong.com
cache_peer_domain w2    bbs2.kong.com
cache_peer_domain w3    bbs1.kong.com
cache_peer_domain w4    bbs2.kong.com

3、在子squid192.168.0.7配置

# vim /etc/squid/squid.conf
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 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 Safe_ports port 3130    #icp
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 deny all
http_port 3128 vhost vport
icp_port 3130
hierarchy_stoplist cgi-bin ?
cache_mem 100 MB
cache_dir ufs /var/spool/squid 100 16 256
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 .       0   20% 4320
cache_peer 192.168.0.6 parent 3128 0 no-query originserver no-digest name=w1
cache_peer 192.168.0.6 parent 3128 0 no-query originserver no-digest name=w2
cache_peer 192.168.0.7 sibling 3128 3130 name=cache1 <span style="font-family: Arial, Helvetica, sans-serif;">--子squid</span>
cache_peer 192.168.0.6 sibling 3128 3130 name=cache0 <span style="font-family: Arial, Helvetica, sans-serif;">--父squid</span>
cache_peer_domain w1    bbs1.kong.com
cache_peer_domain w2    bbs2.kong.com

做测试一级squid

# vim /etc/hosts --记得修改访问端的hosts文件啊,不然什么都别谈了
192.168.0.6     bbs1.kong.com      bbs2.kong.com
先访问下http://bbs1.kong.com:3128 3128是squid的端口<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(240, 240, 240);"></span>
# curl -I http://bbs1.kong.com:3128/template/default/image/guest_bg.jpg
HTTP/1.0 200 OK
Server: nginx/1.4.7
Date: Fri, 06 Feb 2015 08:04:35 GMT
Content-Type: image/jpeg
Content-Length: 37373
Last-Modified: Wed, 23 Mar 2011 06:33:46 GMT
ETag: "4d89944a-91fd"
Accept-Ranges: bytes
X-Cache: MISS from vm06.kong.com                --第一次是miss
X-Cache-Lookup: MISS from vm06.kong.com:3128
Via: 1.0 vm06.kong.com (squid/3.1.10)
Connection: keep-alive# curl -I http://bbs1.kong.com:3128/template/default/image/guest_bg.jpg
HTTP/1.0 200 OK
Server: nginx/1.4.7
Date: Fri, 06 Feb 2015 08:04:35 GMT
Content-Type: image/jpeg
Content-Length: 37373
Last-Modified: Wed, 23 Mar 2011 06:33:46 GMT
ETag: "4d89944a-91fd"
Accept-Ranges: bytes
Age: 50
X-Cache: HIT from vm06.kong.com         --第二次以后都是hit
X-Cache-Lookup: HIT from vm06.kong.com:3128
Via: 1.0 vm06.kong.com (squid/3.1.10)
Connection: keep-alive

测试二级squid

# vim /etc/hosts --记得修改访问端的hosts文件啊,不然什么都别谈了
192.168.0.7     bbs1.kong.com      bbs2.kong.com
先访问下http://bbs1.kong.com:3128 3128是squid的端口
# curl -I http://bbs1.kong.com:3128/template/default/image/guest_bg.jpg
HTTP/1.0 200 OK
Server: nginx/1.4.7
Date: Fri, 06 Feb 2015 08:04:35 GMT
Content-Type: image/jpeg
Content-Length: 37373
Last-Modified: Wed, 23 Mar 2011 06:33:46 GMT
ETag: "4d89944a-91fd"
Accept-Ranges: bytes
Age: 230
X-Cache: HIT from vm06.kong.com --hit来时父squid
X-Cache-Lookup: HIT from vm06.kong.com:3128
X-Cache: MISS from vm07.kong.com
X-Cache-Lookup: MISS from vm07.kong.com:3128
Via: 1.0 vm06.kong.com (squid/3.1.10), 1.0 vm07.kong.com (squid/3.1.10)
Connection: keep-alive# curl -I http://bbs1.kong.com:3128/template/default/image/guest_bg.jpg
HTTP/1.0 200 OK
Server: nginx/1.4.7
Date: Fri, 06 Feb 2015 08:04:35 GMT
Content-Type: image/jpeg
Content-Length: 37373
Last-Modified: Wed, 23 Mar 2011 06:33:46 GMT
ETag: "4d89944a-91fd"
Accept-Ranges: bytes
X-Cache: HIT from vm06.kong.com --hit来时父squid
X-Cache-Lookup: HIT from vm06.kong.com:3128
Age: 265
X-Cache: HIT from vm07.kong.com
X-Cache-Lookup: HIT from vm07.kong.com:3128
Via: 1.0 vm06.kong.com (squid/3.1.10), 1.0 vm07.kong.com (squid/3.1.10)
Connection: keep-alive
</pre><p></p><pre>

4、在192.168.0.1上的nginx增加squid的分发

# vim /etc/nginx/nginx.conf
user  nobody nobody;
worker_processes  4;
error_log  /var/log/nginx/error.log  info;
pid        /var/run/nginx.pid;events {worker_connections  15000;
}http {include       mime.types;default_type  application/octet-stream;log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  /var/log/nginx/access.log  main;sendfile        on;tcp_nopush     on;keepalive_timeout  30;gzip  on;upstream squid_upstream {server 192.168.0.6:3128;server 192.168.0.7:3128;hash        $request_uri;hash_again  10;}upstream tomcat_upstream {server 192.168.0.2:8080 weight=10;server 192.168.0.3:8080 weight=10;}server {listen       80;server_name  localhost;charset utf8;location / {index  index.html index.htm index.jsp;proxy_pass http://squid_upstream;proxy_set_header Host $host;proxy_set_header X-Forward-For $remote_addr;}location ~ \.jsp$ {proxy_pass http://tomcat_upstream;proxy_set_header Host $host;proxy_set_header X-Forward-For $remote_addr;}location ~ ^/forum-[0-9]-[0-9]-[0-9]\.html$ {proxy_pass http://tomcat_upstream;proxy_set_header Host $host;proxy_set_header X-Forward-For $remote_addr;}}
}# service nginx reload

最后修改hosts 指向192.168.0.1

项目笔记:4.引入CDN内容分发网络,实现网站静态元素加速相关推荐

  1. EasyDSS高性能RTMP、HLS(m3u8)、HTTP-FLV、RTSP流媒体服务器解决方案之CDN内容分发网络

    背景分析 EasyDSS流媒体解决方案提供一站式的转码.点播.直播.录像.检索.时移回放服务,极大地简化了开发和集成的工作,并且EasyDSS支持多种特性,完全能够满足企业视频信息化建设方面的需求.其 ...

  2. 干货!CDN内容分发网络实战技巧

    干货!史上最全的CDN内容分发网络实战技巧 整理自[微学堂]第二十四期课程实录 嘉宾介绍 白金,ChinaUnix 资深版主,曾担任<iptables 高级使用研讨>讲师,精通iptabl ...

  3. 企业运维之 CDN 内容分发网络

    企业运维之 CDN 内容分发网络 1. CDN 是什么? 2. CDN 的工作原理 3. CDN 的组成 4. 部署 5. 负载均衡及健康检查 1. CDN 是什么? CDN 是 Content De ...

  4. 基础知识之CDN内容分发网络原理解析

    文章目录 0x00 前言简述 基础概念 工作原理 组成部分 应用场景 0x01 基础配置 CDN 入门配置 CDN 跨域设置 CDN 响应头参数 (扩充) 0x02 边缘脚本与程序 EdgeScrip ...

  5. 深度剖析:CDN内容分发网络技术原理--转载

    1.前言 Internet的高速发展,给人们的工作和生活带来了极大的便利,对Internet的服务品质和访问速度要求越来越高,虽然带宽不断增加,用户数量也在不断增加,受Web服务器的负荷和传输距离等因 ...

  6. 史上最全的CDN内容分发网络实战技巧

    今天来给大家分享下关于 CDN 的东西,以及我自己的一些发现.一些个人的拙见.总共分为 3 个部分:原理.详解.各种坑. 首先说一下 CDN 的基本原理部分,主要分 4 块来描述:CDN 的由来.调度 ...

  7. CDN内容分发网络(上)

    首先说一下 CDN 的基本原理部分,主要分 4 块来描述:CDN 的由来.调度是怎么做的.缓存是什么.关于安全. 最初刚有互联网的时候,带宽用量不多.用户少,并不存在什么问题,后来随着发展,逐渐出现了 ...

  8. 史上最全的CDN内容分发网络实战技巧(网络优化)

    今天来给大家分享下关于 CDN 的东西,以及我自己的一些发现.一些个人的拙见.总共分为 3 个部分:原理.详解.各种坑. 首先说一下 CDN 的基本原理部分,主要分 4 块来描述:CDN 的由来.调度 ...

  9. 运维小知识之CDN内容分发网络原理解析

    0x00 前言简述 基础概念 工作原理 组成部分 应用场景 0x01 基础配置 CDN 入门配置 CDN 跨域设置 CDN 响应头参数 (扩充) 0x02 边缘脚本与程序 EdgeScript - 边 ...

最新文章

  1. fedora12安装小企鹅输入法
  2. 使用了SDRAM,使用了分散加载文件,出现HardFault_Handler
  3. 设计模式-Observer模式
  4. mjpg-streamer在Ubuntu下编译,运行
  5. MyBatis中调用存储过程和函数
  6. Smartform 动态打印选择屏幕上传的图片
  7. Object Pascal 中类型
  8. JavaScript知识笔记(三)——内置对象、浏览器对象
  9. 基于多线程的TCP局域网通信,客户端向服务端上传 文件简单实现源码
  10. springboot配置多项目下统一切换不同环境变量profile办法
  11. 【视频】Vue作者分享:Vue 3.0 进展
  12. Video.js实现rtmp视频播放
  13. 【linux】linux 安装 redis
  14. 第 11 章 直接内存
  15. thinkphp实现动态下拉菜单(补充 设置默认值)
  16. Python学习笔记——python基础 3. 字符串
  17. 增长量计算n+1原则_资料分析几大常用公式,增速、A/B型公式.....
  18. 阿里秒挂,疯狂复习半个月,拿下美团offer(后台开发JAVA岗)
  19. android 常用框架整理
  20. 在 Kubernetes 上快速测试 Citus 分布式 PostgreSQL 集群(分布式表,共置,引用表,列存储)...

热门文章

  1. miui11 android,悉数MIUI11不容易注意到的细节新特性
  2. MTK Camera驱动移植
  3. 12天背诵楞严咒的技巧_楞严咒快速背诵方法,我试了n种,最后选择了这些土方法...
  4. 微信小程序开发入门教程(十一)
  5. 【随笔】从友商丢单看滤食生活
  6. Python 下载文件获取文件名request.get(...,stream=True)
  7. MSFSR: 一种通过增强人脸边界精确表示人脸的多级人脸超分辨率算法(读书笔记)
  8. 把照片变成字母符号软件下载 抖音上特别说的照片变成TXT文档软件
  9. 安装和使用WebStorm、idea (两者步骤是一样的)
  10. ADT和OOP自学,并撰写心得和收获。