CDNãåä¸é害ç¹ã«ãªããªãããã«ããããã«
ãã¼ã©ãã§ã¯ 2010 å¹´Â Cacoo ã®åç¨ãµã¼ãã¹ã®éå§ã«åãã㦠AWS ã«ãããéç¨ãéå§ãã¾ãããå½æãéç¨ç°å¢ã¨ã㦠AWS ãæ¡æãã決ãæã®ä¸ã¤ã«ãªã£ãã®ã CloudFront ã§ããããã®å¾ãçã ã¨ã¨ãã¸ãã±ã¼ã·ã§ã³ã¯å¢ããç¬èªãã¡ã¤ã³ã®ãµãã¼ããªã©é åçãªæ©è½ãæä¾ãããä»ã§ã¯ãã¼ã©ãã®å ¨ãµã¼ãã¹ã®éçãã¡ã¤ã«ã®é ä¿¡ã§å©ç¨ãã¦ãããç¡ãã¦ã¯ãªããªããµã¼ãã¹ã¨ãªã£ã¦ãã¾ãã
ãã®é åã®åé¢ãCloudFront ã®é害ã¯ãã¢ããªã±ã¼ã·ã§ã³ãã®ãã®ã«åé¡ããªãã¦ãã以ä¸ã®ãããªè¡¨ç¤ºãå´©ããç»é¢ã表示ããã¦ãã¦ã¼ã¶ãå ¨ããµã¼ãã¹ã使ããªããªãã¨ããããã®å½±é¿ãé常ã«å¤§ãããã®ã§ããã¾ãé害ã®åå ã DNS ããããã¯ã¼ã¯ã®çµè·¯ã«ãããåé¡ã¨ãã£ããç§ãã¡ãç´æ¥è§£æ±ºãã«ããé åã«ãããã¨ããã°ãã°ã§ãã
ãã ãã©ããªäºæ ã§ãããé害ãèµ·ããã¨ãã«ã¯ã¦ã¼ã¶ã®çæ§ããã¿ã¦ãµã¼ãã¹ãå©ç¨åºæ¥ãªããã¨ã«å¤ããã¯ããã¾ããããµã¼ããåé·åããã®ã¨åæ§ãCloudFront ããµã¼ãã¹ã®åä¸é害ç¹ã¨ããªãããã«ããã¼ã©ãã§ã¯åãµã¼ãã¹ã«ãããã対çãã¨ã£ã¦ãã¾ããããããã§ã2014å¹´11æ27æ¥ã® 9:00 éããã 2 æéè¿ãã«åãã CloudFront ã®é害ã§ããå¹¾ã¤ãã®ãµã¼ãã¹ã§å¾©æ§ä½æ¥ãè¦ãããã®ã®å¤§ããªå½±é¿ãããããã¨ãªããµã¼ãã¹ãç¶ç¶ã§ãã¾ããã
CloudFront ã®é害ã¯éå» 5 å¹´ã®éç¨ã®ä¸ã§ãå¹´ã« 1,2 åã¯èµ·ãã£ã¦ãããã¨ãé害ã®å½±é¿ç¯å²ã®å¤§ãããªã©ããã対çãã¨ã£ãã»ããè¯ã課é¡ã ã¨èãã¦ãã¾ãããããã£ã対çã®æ¤è¨ãããéã«ãæ¬ã¨ã³ããªã®å 容ãåèã«ãªãã°å¬ããæãã¾ãã
ãªããæ¬ã¨ã³ããªã® CloudFront ã®éç¨ã«ã¤ãã¦ã®åææ¡ä»¶ã¯ä»¥ä¸ã§ãã
- CSSãJavaScriptãFlashãç»åãªã©ã®éçãªã½ã¼ã¹ãé ä¿¡
- CloudFront ã®ãªãªã¸ã³ã¯ S3
- å ¨ã¦ SSL
- ä¸åº¦é åããããã¡ã¤ã«ã¯å¤æ´ããªã
対çæ¹éãåºæ¬ã¯ãã©ã¼ã«ããã¯ã
ãã¦ã対çæ¹éãã®ãã®ã¯ã·ã³ãã«ã§ãä¸æçã« CloudFront ã®å©ç¨ããããå¥ã®ã¨ããããéçãã¡ã¤ã«ãé ä¿¡ããããã«åãæ¿ããè¡ããã¨ãããã®ã«ãªãã¾ããé ä¿¡å ã®åãæ¿ãå ã¨ãã¦ã¯ãä»£æ¿ CDN (å¥ã®ãµã¼ãã¹) ããS3 ãEC2ããã®ä»ã¨å¹¾ã¤ãã®ã¢ããã¼ããããã¾ãããã¡ãã¯ä¸æçãªåãæ¿ãå ã§ãã®ã§ãããã©ã¼ãã³ã¹ãªã©ã©ãã¾ã§è¨±å®¹ã§ãããã¯ãµã¼ãã¹ã®ç¹æ§ãªã©ã«ãããã¦èæ ®ããã°ãããã¨æãã¾ãã
代æ¿CDNã®é¸ã³æ¹
ãã¼ã©ãã®å¹¾ã¤ãã®ãµã¼ãã¹ã§ã¯ä»£æ¿ CDN ã¨ã㦠KeyCDN ãå©ç¨ãã¦ãã¾ãã KeyCDN ãæ¡æããçç±ã¨ãã¦ã¯ä¸»ã«ä»¥ä¸ã®éãã§ãã
- S3 ãããã¯ã¨ã³ãã«åºæ¥ã (éçã¦ã§ããµã¤ããã¹ãã£ã³ã°ãå©ç¨ããåæ)
- æ¥æ¬ã«ã¨ãã¸ããã
- å¾é課éã§æä½éé¡ãå®ãã£ã ($25 ã®ã¯ã¬ã¸ããã§æé¡ã®æä½éé¡ã¯ãªã)
- Cross-Origin Resource Sharing (CORS) ããµãã¼ããã¦ãã  (çç±ã«ã¤ãã¦ã¯å¾è¿°)
 ã¾ããS3 ãããã¯ã¨ã³ãã«ã§ããã¨ãCloudFront åãã«é åãããã®ããã®ã¾ã¾ä»£æ¿ CDN å´ã§å©ç¨åºæ¥ã¾ããã¤ã¾ãã
- é常æ : https://xxx.cloudfront.net/R20141127_1/css/all.css
- åæ¿æ:Â https://xxx.alternativecdn.net/R20141127_1/css/all.css
ã®ããã«ãé ä¿¡å ã®ãã¡ã¤ã³ã®é¨åã ããã¢ããªã±ã¼ã·ã§ã³å´ã§åãæ¿ãã¦è¿ãããããã°ããªã½ã¼ã¹ãé åãç´ãå¿ è¦ãããã¾ãããã¾ãæ¥æ¬ã®ã¦ã¼ã¶ãå¤ããå ãããµã¼ãã¹ãããããæ¥æ¬ã«ã¨ãã¸ããããã¨ã大äºãªæ¡ä»¶ã§ããããããã®æ¡ä»¶ãæºãããã®ã§ä»ã«æ¤è¨ããã®ããFastly ã CDN77 ã§ãããã調æ»æç¹ã§ã¯ã©ã¡ããæé¡ã§ã®æä½å©ç¨æéããã£ããããä»£æ¿ CDN ã¨ãã¦ã¯å°ãã³ã¹ãããããæãå¦ãããæçµçã« KeyCDN ã¨ãªãã¾ããã
ãµã¼ãã¹ã«ãã£ã¦éè¦ãããæ¡ä»¶ã¯å¤ããã¨æãã¾ãã®ã§ããããã£ãæ¯è¼ãµã¤ã ãåèã«ãã¦ããã ããã°ã¨æãã¾ãã
åãæ¿ãæ¹æ³
次ã«é ä¿¡å ã®åãæ¿ãæ¹æ³ã§ããããã¼ã©ãã§ã¯å¤§ããåãã¦ä»¥ä¸ã®ï¼ã¤ã®æ¹å¼ãæ¡ç¨ãã¦ãã¾ãã
- DNS ã«ããåãæ¿ãæ¹å¼
- ã¢ããªã±ã¼ã·ã§ã³ã«ããåãæ¿ãæ¹å¼
åè ã¯é ä¿¡å ã DNS ã«ãã£ã¦ã¢ããªã±ã¼ã·ã§ã³ã¯å ¨ãå¤æ´ããã«åãæ¿ããã¢ããã¼ãã§ãå¾è ã¯ã¢ããªã±ã¼ã·ã§ã³ã§é ä¿¡å ã®ãªã½ã¼ã¹ã® URL ãåãæ¿ããæ¹å¼ã§ããå ·ä½çãªæ¹æ³ã¨ããã®ç¹å¾´ãªã©ã詳細ã«ã¿ã¦ããã¾ãããã
1.DNS ã«ããåãæ¿ãæ¹å¼
Backlog ã§æ¡æãã¦ããã®ããã®æ¹å¼ã§ããã¾ã CloudFront ã®Â ç¬èª SSL  ãªãã·ã§ã³ã使ããã¢ããªã±ã¼ã·ã§ã³ããã¯éçãªã½ã¼ã¹ã¨ãã¦ç¬èªãã¡ã¤ã³ã® URL  ( ä¾: https://assets.backlog.jp/R20141119_1/script/common-libs.js ) ãè¿ãã¾ãããã㦠Route53 ã«ã¦  assets.backlog.jp ã®è§£æ±ºå ã¨ã㦠CloudFront ã®ãã£ã¹ããªãã¥ã¼ã·ã§ã³ã®Â Alias ãè¨å®ãã¦ããã¾ããCNAME ã§æå®ãã¦ãè¯ãã®ã§ãããåå解決ã®ã³ã¹ããçºçãããããRoute53 ãå©ç¨ããå ´å㯠Alias ã§è¨å®ãã¦ããã¨ããã§ãããã
ã¾ãé害çºçæã®åãæ¿ãã®ããã«ãã¢ããªã±ã¼ã·ã§ã³ã®é åæã«éçãªã½ã¼ã¹ã EC2 ãããé ä¿¡ã§ããããã«ãã¦ããå¿ è¦ãããã¾ããBacklog ã§ã¯ãªãã¼ã¹ãããã·ã¨ãã¦å©ç¨ãã¦ãã nginx ããéçãªã½ã¼ã¹ãè¿ããããã«ãã¦ããããã®å段㫠ELB ãããã¾ããBacklog ã§ã¯ SSL ãå¿ è¦ãªãã¨ããããS3 ã§ã¯ãªã ELB ãå©ç¨ãã¦ãã¾ãã
ãã㦠CloudFront ã«åé¡ãçºçããå ´åã«ã¯ããã® assets.backlog.jp ã®è§£æ±ºå ã ELB ã«åãæ¿ã㦠EC2 ã¤ã³ã¹ã¿ã³ã¹ããã®é ä¿¡ã«åãæ¿ãã¾ããå ¨ä½åã¯ä»¥ä¸ã®å³ã®ããã«ãªãã¾ãã
ãã¡ãã§ç´¹ä»ããã¦ããããã«ãRoute53 ãå©ç¨ãã¦ããã°ããã«ã¹ãã§ãã¯ãå©ç¨ãã¦èªåçã«åãæ¿ãããã¨ãå¯è½ã§ãã
ãã®æ¹å¼ã®ã¡ãªããã¯ä½ããã¢ããªã±ã¼ã·ã§ã³ã«å ¨ãå¤æ´ãå ããã«åãæ¿ããè¡ããã¨ãåºæ¥ãç¹ã§ããæè¿ã§ã¯ã¦ã§ãã ãã§ãªããã¢ãã¤ã«ã¢ããªãæä¾ãã¦ãããµã¼ãã¹ãå¤ããã¨æãã¾ããããã®ã©ã¡ãããã CloudFront ã®ãªã½ã¼ã¹ãå©ç¨ãã¦ããå ´åã«ã¯ç¹ã«ãã®ã¡ãªããã享åã§ããã§ãããããã¡ãªããã¯ãã¯ã©ã¤ã¢ã³ãå´ã§åå解決ã®çµæããã£ãã·ã¥ãããå ´åã«é害ãèµ·ãã£ã¦ãããªã½ã¼ã¹ãè¦ã«è¡ãç¶ããå¯è½æ§ãããç¹ã§ãã
2.ã¢ããªã±ã¼ã·ã§ã³ã«ããåãæ¿ãæ¹å¼
ï¼ã¤ç®ã¯ã¢ããªã±ã¼ã·ã§ã³ãè¿ãéçãªã½ã¼ã¹ã® URL ãæ示çã«åãæ¿ããæ¹æ³ã§ããBacklog 以å¤ã®ãµã¼ãã¹ã§ã¯å ¨ã¦ãã¡ãã§ããé害ã®å¯¾çãã¯ãããæã¯ã¾ã CloudFront ã®ç¬èª SSL ãªãã·ã§ã³ã« SNI ã®ãµãã¼ãããªãæ¯è¼çé«ä¾¡ã ã£ããã¨ããé ä¿¡å ãè¤æ°ããé¸æãããã£ããã¨ãæè»ãªåãæ¿ããè¡ãããã£ããã¨ã主ãªçç±ã§ãã
Typetalk ã Nulab Account ã§ã¯åºæ¬çã« CDN ã®è¨å®ãå¤åºãã«ãã¦ãããè¨å®ãã¡ã¤ã«ã®å 容ãæ¸ãæãã¦ã¢ããªã±ã¼ã·ã§ã³ãåèµ·åããã ãã§é ä¿¡å ãåãæ¿ãããããã«ãã¦ãã¾ãããã®æ¹å¼ã§ã¯å ã® DNS ã«ããåãæ¿ãã¨åæ§ããµã¼ãã¹å ¨ä½ã§é ä¿¡å ãåãæ¿ããããã«ãªã£ã¦ãã¾ãã
Cacoo ã§ã¯ããã«ä¸æ©é²ãã å½¢ã§ã¢ããªã±ã¼ã·ã§ã³åãæ¿ããå®è£ ãã¦ãã¾ããCacoo ã¯å ¨ä¸çã®åºãå°åã«ã¦ã¼ã¶ãããäºã¨æç»ã¨ãã£ã¿ã Flash ãã¡ã¤ã«ã§ãµã¤ãºã大ãããã¨ãããCloudFront é害æã«ã CDN ã®å©ç¨ã¯å¿ é ã§ããã¾ããå©ç¨å°åãåæ£ããã¦ããããç¹å®ã®ãããã¯ã¼ã¯ã®ã¿ã§çºçãããããªåé¡ãããããæ¤ç¥åºæ¥ãªãå¯è½æ§ããããã¨ããæ¤ç¥åºæ¥ãã¨ãã¦ãç¹å®ç°å¢ã®ã¿ã®åé¡ã®ããã«ãå ¨ä½ã® CDN ãåãæ¿ãããã¨ã§å¤ãã®ã¦ã¼ã¶ãéã«ä¸ä¾¿ã«ãªãå¯è½æ§ãããã¾ããããããã£ãèæ¯ãããCacoo ã§ã¯
- ã¯ã©ã¤ã¢ã³ãå´ãã CloudFront ã¸å®æçã«ãã«ã¹ãã§ãã¯
- åé¡ããã£ãå ´åããã®ã¯ã©ã¤ã¢ã³ãããã®ãªã¯ã¨ã¹ãã®ã¿ä»£æ¿ CDN ã«åãæ¿ãã
ã¨ããã¢ããã¼ããåããã¨ã«ãã¾ããã
ã¾ãä¸æºåã¨ãã¦ãã«ã¹ãã§ãã¯ç¨ã«ããã¹ããã¡ã¤ã«ãç¨æã㦠S3 ã«é åãã¾ãããã®ãã¡ã¤ã«ã¯ XHR ã«ã¦ã¢ã¯ã»ã¹ããããã CORS ãæå¹ã«ãã¦ã¯ãã¹ãã¡ã¤ã³ã§ã®ãªã¯ã¨ã¹ãã許å¯ããããã«ãã¦ããã¾ããããè¤éã«è¦ããããããã¾ããããå½å img ã¿ã°ã«ããç»åã®èªã¿è¾¼ã¿ã§ã®å¤å¥ã試ã¿ãã¨ããããã©ã¦ã¶ã®èªã¿è¾¼ã¿ã®ä¸æãªã©ã¨é害ã¨ã®å¤å¥ãé£ããã£ããããAjax ã«ãããã«ã¹ãã§ãã¯ã«åãæ¿ããã¨ããçµç·¯ãããã¾ãã
å¦çã®å¤§ã¾ããªæµãã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
- ãã¼ã¸ã®ãã¼ãå¾ã«é ä¿¡å A ã®ãã«ã¹ãã§ãã¯ãå®è¡
- æå®åæ°ã®ãªãã©ã¤å¾ã失æããå ´åã¯é ä¿¡å ã B ã«ãã¦ãã«ã¹ãã§ãã¯
- æåããå ´åãé ä¿¡å B ã表ãå¤ã Cookie ã«ã»ãããã¦ãã©ã¦ã¶ããªãã¼ã
- ãµã¼ãå´ã§ã¯ Cookie å¤ã«åºã¥ãã¦é ä¿¡å B ãéçãªã½ã¼ã¹ã® URL ã¨ã㦠HTML ã表示
ãã«ã¹ãã§ãã¯ã¯ä»¥ä¸ã®å³ã®ããã«åªå ããé çª ( CloudFront > KeyCDN > S3  ) ã«ã¦è¡ãã¾ããS3 ã¾ã§ãã§ãã¯ãã¦ãåé¡ãããå ´åã¯æçµçã«ã¯ EC2 ããé ä¿¡ãã¾ãã
ä»ã«ã以ä¸ã®ãããªå®è£ ä¸ã®å·¥å¤«ããã¦ãã¾ãã
- CDN ã®ãã©ã¼ã«ããã¯ãçºçããå ´åãä¸å®æéã¯ãã«ã¹ãã§ãã¯ãããªã
- ãªã«ããªãæ¤ç¥ããå ´åã¯é ä¿¡å ãåãæ¿ãã Cookie ãåé¤ãã
- æ示çãªé害ã®å ´åã¯åªå ããé ä¿¡å ã®é åºãå¤ã㦠( ä¾: KeyCDN > CloudFront > S3  )ããã©ã¼ã«ããã¯ãèµ·ãããªãããã«ã§ãã
ã¾ã¨ã
ãããã®æ¹å¼ã®ç¹å¾´ãã¡ãªããã»ãã¡ãªããã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
 | ç¹å¾´ | ã¡ãªãã | ãã¡ãªãã |
---|---|---|---|
DNS ã«ããåãæ¿ãæ¹å¼ |
é ä¿¡å ã®åå解決ãåãæ¿ã é害æçºçæã«ã¢ããªã±ã¼ã·ã§ã³å´ã®å¯¾å¿ã¯ä¸è¦ |
ã¢ããªã±ã¼ã·ã§ã³ã®å¤æ´ãä¸è¦ Route53 ãå©ç¨ããã°èªååãæ¿ããæ軽ã«å®ç¾å¯è½ |
ãµã¼ãã¹å ¨ä½ã§ã®åãæ¿ãããåºæ¥ãªã åå解決ã®çµæããã£ãã·ã¥ããã¦ããã¨åé¡ã解決ã§ããªã |
ã¢ããªã±ã¼ã·ã§ã³ã«ããåãæ¿ãæ¹å¼ |
ã¢ããªã±ã¼ã·ã§ã³ã§é ä¿¡å ã® URL ãåãæ¿ã é害çºçæã®æ¯ãèãã¯ä½ããã¿æ¬¡ç¬¬ |
ã»è¤æ°ã®ä»£æ¿ CDN ã®å©ç¨ ã»ã¦ã¼ã¶æ¯ã«é ä¿¡å ãå¤ãã ãªã©æè»ãªåãæ¿ããå¯è½
|
ä½ãè¾¼ã¿ã®ã³ã¹ããé«ã |
ã©ã¡ããåã ç¹å¾´ãããã¾ãããRoute53 ã使ã£ã¦ããå ´åã«ã¯èªååãæ¿ããç°¡åã«å®ç¾ã§ãã¾ãã®ã§ãã¾ã㯠DNS ã«ããåãæ¿ãã試ã価å¤ã¯é«ãã¨æãã¾ãããã®å¾ããµã¼ãã¹ã®ç¹æ§ã«ãããã¦ã¢ããªã±ã¼ã·ã§ã³ã«ããåãæ¿ããæ¤è¨ããã¨è¯ãã¨æãã¾ãã
ãã¼ã©ãã§ã¯ãµã¼ãã¹ãæ¯ããã¤ã³ãã©ã¨ã³ã¸ãã¢ã絶è³åéä¸ã§ãï¼
ãã¼ã©ãã§ã¯ãããã£ããµã¼ãã¹éç¨ã«ãããã¤ã³ãã©é¢ã®èª²é¡ããéçºãã¼ã ã¨ä¸ä¸¸ã¨ãªã£ã¦è§£æ±ºããã¤ã³ãã©ã¨ã³ã¸ãã¢ãåéãã¦ããã¾ãï¼ãã¼ã©ãã®ãµã¼ãã¹ãã¤ã³ãã©é¢ããããè¯ããã¦ãããã¨ã«èå³ãããã¾ããããæ¯éãå¿åãå¾ ã¡ãã¦ããã¾ãã詳細ã¯ãã¡ãã®æ¡ç¨æ å ±ã®ãã¼ã¸ããï¼
ã«ãã¼ã¤ã¡ã¼ã¸ : Do not fear failure by Tomasz Stasiuk