当前位置:网站首页>CDN principle

CDN principle

2022-06-24 22:33:00 Zhuge iron and steel cloud

cdn brief introduction

There is a performance bottleneck when users access the origin service , adopt cdn Technology caches the contents of the origin to multiple nodes . When the user sends a request to the origin domain name , The request will be dispatched to the service node closest to the user , The service node responds directly and quickly , Effectively reduce user access delay , Improve usability .

understand cdn You need to know some knowledge first :

  • dns Principle of analysis
  • CNAME effect

dns Analytical process

No matter how much you say, it is not as good as practical application , Let's learn from the example dns Analytical process

$ nslookup www.moehot.com  
Server:     10.0.0.1
Address:    10.0.0.1#53

Non-authoritative answer:
Name:   www.moehot.com
Address: 139.196.3.197

nslookup yes dns The command to parse ,server 10.0.0.1 It's internal dns Server's ip. 139.196.3.197 Is the domain name requested ip.

The detailed process uses dig Command view

$ dig +trace www.moehot.com 

; <<>> DiG 9.9.4-RedHat-9.9.4-72.el7 <<>> +trace www.moehot.com
;; global options: +cmd
.           518382  IN  NS  a.root-servers.net.
.           518382  IN  NS  b.root-servers.net.
.           518382  IN  NS  c.root-servers.net.
.           518382  IN  NS  d.root-servers.net.
.           518382  IN  NS  e.root-servers.net.
.           518382  IN  NS  g.root-servers.net.
.           518382  IN  NS  h.root-servers.net.
.           518382  IN  NS  i.root-servers.net.
.           518382  IN  NS  j.root-servers.net.
.           518382  IN  NS  k.root-servers.net.
.           518382  IN  NS  l.root-servers.net.
.           518382  IN  NS  m.root-servers.net.
.           518382  IN  NS  root1.sc163.net.
.           518382  IN  NS  root2.sc163.net.
.           518382  IN  NS  b.root-servers.net.
.           518382  IN  NS  c.root-servers.net.
.           518382  IN  NS  d.root-servers.net.
.           518382  IN  NS  e.root-servers.net.
.           518382  IN  NS  g.root-servers.net.
.           518382  IN  NS  h.root-servers.net.
.           518382  IN  NS  i.root-servers.net.
.           518382  IN  NS  j.root-servers.net.
.           518382  IN  NS  k.root-servers.net.
.           518382  IN  NS  l.root-servers.net.
.           518382  IN  NS  m.root-servers.net.
.           518382  IN  NS  root1.sc163.net.
.           518382  IN  NS  root2.sc163.net.
.           518382  IN  NS  a.root-servers.net.
;; Received 631 bytes from 10.0.0.1#53(10.0.0.1) in 54 ms

com.            172800  IN  NS  i.gtld-servers.net.
com.            172800  IN  NS  a.gtld-servers.net.
com.            172800  IN  NS  e.gtld-servers.net.
com.            172800  IN  NS  k.gtld-servers.net.
com.            172800  IN  NS  l.gtld-servers.net.
com.            172800  IN  NS  g.gtld-servers.net.
com.            172800  IN  NS  h.gtld-servers.net.
com.            172800  IN  NS  d.gtld-servers.net.
com.            172800  IN  NS  j.gtld-servers.net.
com.            172800  IN  NS  f.gtld-servers.net.
com.            172800  IN  NS  c.gtld-servers.net.
com.            172800  IN  NS  m.gtld-servers.net.
com.            172800  IN  NS  b.gtld-servers.net.
com.            86400   IN  DS  30909 8 2 E2D3C916F6DEEAC73294E8268FB5885044A833FC5459588F4A9184CF C41A5766
com.            86400   IN  RRSIG   DS 8 1 86400 20190224210000 20190211200000 16749 . owDDrAEA9JJUhzbHNnVNjPpqTqeJrWMScHU4Wskrp9gnkBKI8+1PeBfP 6uIUeVT+0w/Vcfh03p7mw0w5DS0ub8wQUfBTfY37s1MhE45fWueTyUGt l9aMEsma0UHZV1TL2njmDhgr7koN935hhjiSv26wymuBx5CpOvF2y7ql ih4JGsWPnHLrsfnqjq9njmP/3RQnpXrJDP/+reb5DTpdqLEf9TM/OHbt 1UpkG6rMUx4Jz53pIksji/CUfbYPiuH8FrUnVJ5thn0o+o2ZPpQqSisA 9C9dYDl1o75CDC3FShp56EjfeGmm6ncY8Kz5Irer1HUjOjiudN4cCjWU NnljsQ==
;; Received 1174 bytes from 202.12.27.33#53(m.root-servers.net) in 4386 ms

moehot.com.     172800  IN  NS  dns9.hichina.com.
moehot.com.     172800  IN  NS  dns10.hichina.com.
CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN NSEC3 1 1 0 - CK0Q1GIN43N1ARRC9OSM6QPQR81H5M9A NS SOA RRSIG DNSKEY NSEC3PARAM
CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN RRSIG NSEC3 8 2 86400 20190216054237 20190209043237 16883 com. ZpsxE9/jbJ0Ues0CJFIz9X5DvvsTgUlhLjpRIrQcXbo9z+avYuhL5O7J MxzY0KbxK2hGWK2q5zesaB+9ye1v7LuEVn8OzHtyjxGxjr7sXqWiU+0W 3lFK8q2EdNOulZJrmJ/nSZGNZ3aXRpeFWLD2LYs1Eipw5D6KmBAWAy/w xvE=
HMIQOH986C2QQFJRPQJH18GTCL9922SH.com. 86400 IN NSEC3 1 1 0 - HMISVQBER3LFS6UELQ3DN9VT6QI4LL28 NS DS RRSIG
HMIQOH986C2QQFJRPQJH18GTCL9922SH.com. 86400 IN RRSIG NSEC3 8 2 86400 20190218055540 20190211044540 16883 com. R3GJVt5SSPC7MQUJTs6h0OC9qQnj2WZU2Y/ec+xbj39/Wuo/TwunvKYz NIr20VkkhMOeX/s8cfA3XheNMBdwufxLZNYTt3ptBySZdmiRKYFi/9HG jUfEcBF2tVVE/ae5qzftgIm7O+AUYxkwWMKBL4+XC3A3sV8I0Fv2fd+Y iDk=
;; Received 887 bytes from 192.42.93.30#53(g.gtld-servers.net) in 152 ms

www.moehot.com.     600 IN  A   139.196.3.197
;; Received 59 bytes from 140.205.41.26#53(dns10.hichina.com) in 36 ms

Let's analyze the parsing process step by step :

  • First, check whether the local cache query has the corresponding domain name resolution ip
  • Without it , To the configured dns Server initiates request (10.0.0.1 Within the company dns The server ip)
  • Received 631 bytes from 10.0.0.1#53(10.0.0.1) in 54 ms -- 10.0.0.1 The address of the root domain name server will be returned ( There are multiple root domain servers , So many domain names are returned )
  • Received 1174 bytes from 202.12.27.33#53(m.root-servers.net) -- The local machine sends a resolution request to the root domain name , The root domain server returns .com Top level domain name server address
  • Received 887 bytes from 192.42.93.30#53(g.gtld-servers.net) -- This machine to com. Domain name server initiates request , return moehot.com. Domain name server address
  • Finally to moehot.com. The domain name sends a request to get www.moehot.com. Of ip Address

CNAME effect

CNAME namely : Alias record . This record allows you to map multiple names to another domain name . Usually used to provide at the same time WWW and MAIL Computer serving . for example , There is a computer called “host.mydomain.com”(A Record ). It also provides WWW and MAIL service , In order to facilitate user access to services . You can set up two aliases for this computer (CNAME):WWW and MAIL. The full names of these two aliases are Web Hosting, Domain Name Registration - MyDomain.com and “mail.mydomain.com”. In fact, they all point to “host.mydomain.com”.

stay cdn The implementation principle in is : Add... To the origin domain name CNMAE, The alias is the domain name of the acceleration node . When the user makes a request to the origin station ,dns When the server resolves the domain name of the origin site, it will find that CNMAE Record , At this time dns The server will send to CNAME Domain name request , The request will be dispatched to the domain name of the acceleration node .

Tencent cloud cdn example

Suppose your domain name is www.test.com , When the domain name is accessed CDN After you start using the accelerator , you
User initiated HTTP request , The actual processing flow is shown in the figure :

 

image.png

  • The user to www.test.com A picture resource under , Such as 1.jpg Initiate request , First, to Local DNS Hair
    Domain name resolution request ;
  • When Local DNS analysis www.test.com when , You will find that it has been configured CNAME
    www.test.com.cdn.dnsv1.com, The parsing request is sent to Tencent DNS(GSLB),GSLB Wei Teng
    Dispatch system independently developed by xunyun , The best node is assigned to the request IP;
  • Local DNS obtain Tencent DNS Parsing returned IP;
  • User test get resolution IP;
  • Users get from IP Initiate a response to resources 1.jpg Access requests for ;
  • If so IP The corresponding node cache has 1.jpg, The data will be returned directly to the user (10), At this time, the request is closed
    beam . If the node is not cached 1.jpg, Then, the node will send a request to the service source station 1.jpg Request (6、7、8),
    After obtaining resources , Combined with user-defined configuration of the cache strategy ( Please refer to the cache time setting chapter in the user guide
    Section content ), Store resources (9), And return to the user (10), The request ends .



author :ScienBeast
link :https://www.jianshu.com/p/14dede92b02f
source : Simple books
The copyright belongs to the author . Commercial reprint please contact the author for authorization , Non-commercial reprint please indicate the source .

Reference resources

CDN Principle and configuration
https://www.cnblogs.com/losbyday/p/5843960.html
https://blog.csdn.net/weixin_40555670/article/details/79344707
https://www.jianshu.com/p/14dede92b02f
https://www.xinruiyun.cn/zhishiku/3869.html

原网站

版权声明
本文为[Zhuge iron and steel cloud]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211233395115.html