ã¯ããã«
ããã«ã¡ã¯ãæè¡3課ã®ç´
æã§ããå¹´å§æ©ã
ã«é¢¨éªãå¼ãã¦ãã¾ãããªããªãè¾ãæ£æãéãããã¨ã«ãªã£ã¦ãã¾ãã¾ããã
ä»åãAWSã®Elastic Load Balancingã®Classic Load Balancer (以ä¸ãELB)ã®ã¹ãã£ããã¼ã»ãã·ã§ã³æ©è½ã«ã¤ãã¦ã¾ã¨ãã¦ã¿ã¾ããã
ç®æ¬¡ã¯ä»¥ä¸ã®éãã¨ãªãã¾ãã
- ã¯ããã«
- ELBã®ã¹ãã£ããã¼ã»ãã·ã§ã³ããã®åã«
- ELBã®ã¹ãã£ããã¼ã»ãã·ã§ã³ã«ã¤ãã¦
- 注æç¹
- ãããã«
ELBã®ã¹ãã£ããã¼ã»ãã·ã§ã³ããã®åã«
ELBã®ã¹ãã£ããã¼ã»ãã·ã§ã³ã®åã«ããã®åæã¨ãªãCookieã¨ã»ãã·ã§ã³ã«ã¤ãã¦æ¦è¦ããããããã¦ã¿ã¾ãã
Cookieã«ã¤ãã¦
Cookieã¯RFC6265ã«ãã£ã¦æ¨æºåããã¦ããWebãµã¼ããã¯ã©ã¤ã¢ã³ãï¼ãã©ã¦ã¶ï¼ã«ä¸æçã«ãã¼ã¿ãä¿åãããä»çµã¿ã§ãããµã¼ãã¯ãã®æ å ±ã使ããã¨ã«ãããã¦ã¼ã¶èå¥ãã»ãã·ã§ã³ç®¡çãå®ç¾åºæ¥ã¾ãã 主ãªåä½æ¦è¦ã¨ãã¦ã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
- ãµã¼ãã¯Set-Cookieãããã®å©ç¨ã«ããCookieãã¯ã©ã¤ã¢ã³ãã«æ¸¡ãã¾ã
- ã¯ã©ã¤ã¢ã³ãã¯åããµã¼ãã«ãªã¯ã¨ã¹ããéãéããã®ãµã¼ããã渡ãããCookieã®æ å ±ã渡ããã¨ã«ããããµã¼ãã¯ãã®æ å ±ã«åºã¥ããå¦çãè¡ãã¾ã
Cookieã®åä½ä¾
Cookieã®åä½ãå ·ä½çã«ç¢ºèªãã¦ã¿ã¾ãã
ãã¹ãã³ã¼ã
<?php if (isset($_COOKIE["kure"])){ $count = $_COOKIE["kure"] + 1; }else{ $count = 1; } setcookie("kure", $count); print('訪ååæ°ã¯'.$count.'åç®ã§ã'); ?>
åä½æ¦è¦
åä½æ¦è¦ã¯ä»¥ä¸ã®éãã¨ãªãã¾ãã
- ãµã¼ãã¸ã®ååã®ãªã¯ã¨ã¹ãã¯ãã¯ã©ã¤ã¢ã³ãã«Cookieãä¿åããã¦ããªããããCookieã®éä¿¡ã¯ããã¾ãã
- ãµã¼ãã¯ã¬ã¹ãã³ã¹ã§ãSet-Cookieããããå©ç¨ããCookieï¼kure=1ï¼ãã¯ã©ã¤ã¢ã³ãã«æ¸¡ãã¾ã
- ã¯ã©ã¤ã¢ã³ãã¯2åç®ä»¥éã®ãªã¯ã¨ã¹ãã§ãéä¿¡ãããCookieæ å ±ãæ ¼ç´ãã¦ãµã¼ãã«éä¿¡ãã¾ã
- ãµã¼ãã¯ã¬ã¹ãã³ã¹ã§ãSet-Cookieããããå©ç¨ããã¤ã³ã¯ãªã¡ã³ãããå¤ï¼kure=2ï¼ãCookieã«æ ¼ç´ããã¯ã©ã¤ã¢ã³ãã«æ¸¡ãã¾ã
ã·ã¼ã±ã³ã¹å³
åä½çµæ
1åç®ã¢ã¯ã»ã¹
2åç®ã¢ã¯ã»ã¹
3åç®ã¢ã¯ã»ã¹
ãã±ãããã£ããã£
1åç®ã¢ã¯ã»ã¹ï¼ãµã¼ãâã¯ã©ã¤ã¢ã³ãï¼
2åç®ã¢ã¯ã»ã¹ï¼ã¯ã©ã¤ã¢ã³ãâãµã¼ãï¼
3åç®ã¢ã¯ã»ã¹ï¼ãµã¼ãâã¯ã©ã¤ã¢ã³ãï¼
ã»ãã·ã§ã³ã«ã¤ãã¦
Cookieã®å©ç¨ã«ãããã»ãã·ã§ã³ç¶æãå®ç¾ã§ãã¾ãã以ä¸ãåä½ã®æ¦è¦ã¨ãªãã¾ãã
- ååã¢ã¯ã»ã¹æããµã¼ãã¯ã¯ã©ã¤ã¢ã³ãæ¯ã«ç°ãªãã»ãã·ã§ã³IDçæãããã®æ å ±ãSet-Cookieããããå©ç¨ãã¯ã©ã¤ã¢ã³ãã«éä¿¡ãã¾ã
- 次å以éã¢ã¯ã»ã¹æãã¯ã©ã¤ã¢ã³ãã¯ã»ãã·ã§ã³IDæ å ±ãCookieã«æ ¼ç´ãããµã¼ãã«éä¿¡ãã¾ã
- ãµã¼ãã¯éä¿¡ãããã»ãã·ã§ã³IDã確èªããã¯ã©ã¤ã¢ã³ãæ¯ã®æ
å ±ï¼ä¾ãã°ãã·ã§ããã³ã°ãµã¤ãã§ããã°ãã¯ã©ã¤ã¢ã³ãã¨ã«ã¼ãã«å
¥ããååã®ç´ä»ãçï¼ãå¦çããè¿ä¿¡ãã¾ã
- ã¯ã©ã¤ã¢ã³ãæ¯ã®æ å ±ï¼ä¾ãã°ãã·ã§ããã³ã°ãµã¤ãã§ããã°ãã¯ã©ã¤ã¢ã³ãã¨ã«ã¼ãã«å ¥ããååã®ç´ä»ãçï¼èªä½ã¯ãµã¼ãå´ã«ä¿åãã¾ã
ELBã®ã¹ãã£ããã¼ã»ãã·ã§ã³ã«ã¤ãã¦
æ¦è¦
ELBã®ã¹ãã£ããã¼ã»ãã·ã§ã³ã¯ELBããµã¼ãã«ãªã¯ã¨ã¹ãæ¯ãåããéãç¹å®ã®Cookieã確èªãããã¨ã§ãç¹å®ã®ã¯ã©ã¤ã¢ã³ãããã®ãªã¯ã¨ã¹ããç¹å®ã®ãµã¼ãã«ç´ä»ãããã¨ãåºæ¥ãæ©è½ã§ãã ELBã®ã¹ãã£ããã¼ã»ãã·ã§ã³ã®è¨å®ã¯ä»¥ä¸3ã¤ã®ãã¿ã¼ã³ãé¸æåºæ¥ã¾ãã®ã§ãããããã©ã®ãããªåä½ã¨ãªãã確èªãã¦ã¿ã¾ãã
- ç¶æç¡ã
- ELBã«ãã£ã¦çæãããCookieã®ç¶æ
- ã¢ããªã±ã¼ã·ã§ã³ã«ãã£ã¦çæãããCookieã®ç¶æ
æ¤è¨¼æ§ææ¦è¦
ELBã«ãµã¼ãã2å°ã¶ãä¸ããå½¢ã§ã¯ã©ã¤ã¢ã³ããããªã¯ã¨ã¹ããéä¿¡ããã©ã®ãããªåä½ãããã確èªãã¾ãã
ã³ã¼ã
以ä¸ã®ã³ã¼ãã®ãã¡ã¤ã«ãããããã®ãµã¼ãã«è¨ç½®ãã¾ãã ãip-x-x-x-xãã®é¨åã«ã¯ããããã®ãµã¼ãã®ãã©ã¤ãã¼ãIPã¢ãã¬ã¹ãè¨è¼ããããã«ãã¾ãã
ããããã®ãµã¼ãã«ã¢ã¯ã»ã¹ããã¨ã
ãip-x-x-x 訪ååæ°ï¼Nã
ã表示ããã¾ãã
<?php session_start(); ?> <html> <head><title>PHP TEST</title></head> <body> ip-x-x-x-x <?php if (!isset($_SESSION["visited"])){ print('ååã®è¨ªåã§ã'); $_SESSION["visited"] = 1; }else{ $visited = $_SESSION["visited"]; $visited++; print('訪ååæ°:'.$visited); $_SESSION["visited"] = $visited; } ?> </body> </html>
ç¶æç¡ã
ã¹ãã£ããã¼ã»ãã·ã§ã³ç¡ãã®å ´åããªã¯ã¨ã¹ãã¯ELBã®è² è·åæ£æ©è½ã«ããããµã¼ãã«æ¯ãåãããã¾ãããããã£ã¦ããªã¯ã¨ã¹ãã®åº¦ã«ç°ãªããµã¼ãã«æ¯ãåããããå¯è½æ§ãããããããµã¼ãã§ã®ã»ãã·ã§ã³ç®¡çãåæã¨ããã·ã¹ãã ã®å ´åã¯æ³¨æãå¿
è¦ã§ãã
AWSã®ããã¸ã¡ã³ãã³ã³ã½ã¼ã«ä¸ã§ã¯ãELBã®ãç¶æè¨å®ã®ç·¨éãããã以ä¸ã®ç»é¢ã§ãç¶æã®ç¡å¹åããé¸æãã¾ãã
åä½ç¢ºèª
以ä¸ã5åç¶ãã¦ã¢ã¯ã»ã¹ãã¦ã¿ãçµæã§ããããããã®ãµã¼ãã«æ¯ãåãããªããã¦ãããã¨ãåããã¾ãã
1åç®ã¢ã¯ã»ã¹
2åç®ã¢ã¯ã»ã¹
3åç®ã¢ã¯ã»ã¹
4åç®ã¢ã¯ã»ã¹
5åç®ã¢ã¯ã»ã¹
ELBã«ãã£ã¦çæãããCookieã®ç¶æ
ãã®æ¹å¼ã§ã¯ãELBã«ãã£ã¦çæãããCookieã«ãã£ã¦ãªã¯ã¨ã¹ãã®æ¯ãåããµã¼ããåºå®ããã¾ããè¿ä¿¡ã®ãªã¯ã¨ã¹ããELBãçµç±ããéã«Cookieãä»å ããã¾ãã
AWSã®ããã¸ã¡ã³ãã³ã³ã½ã¼ã«ä¸ã§ã¯ãELBã®ãç¶æè¨å®ã®ç·¨éãããã以ä¸ã®ç»é¢ã§ããã¼ããã©ã³ãµã¼ã«ãã£ã¦çæãããCookieã®ç¶æãæå¹åããé¸æãã¾ããCookieã®æå¹æéã®æå®ãåºæ¥ã¾ãã
ã·ã¼ã±ã³ã¹å³
ã·ã¼ã±ã³ã¹æ¦è¦ã以ä¸ã«å³ç¤ºãã¾ãã
åä½ç¢ºèª
åä½ç¢ºèªãã¦ã¿ãã¨ãç¶ææ©è½ç¡ãã®å ´åã¨éããåããµã¼ãã«ãªã¯ã¨ã¹ããæ¯ãåãããããã¨ãåããã¾ãã
ã¢ã¯ã»ã¹1åç®
ã¢ã¯ã»ã¹2æ¥ç®
ã¢ã¯ã»ã¹3åç®
ã¢ããªã±ã¼ã·ã§ã³ã«ãã£ã¦çæãããCookieã®ç¶æ
ãã®æ¹å¼ã§ã¯ãELBã§ã¢ããªã±ã¼ã·ã§ã³ã®Cookieåãæå®ãããã®Cookieæ
å ±ãELBã確èªãã¦ãæ¯ãåãããµã¼ããåºå®ããã¾ãã
AWSã®ããã¸ã¡ã³ãã³ã³ã½ã¼ã«ä¸ã§ã¯ãELBã®ãç¶æè¨å®ã®ç·¨éãããã以ä¸ã®ç»é¢ã§ãã¢ããªã±ã¼ã·ã§ã³ã«ãã£ã¦çæãããCookieã®ç¶æãæå¹åããé¸æããCookieåãæå®ãã¾ãã
ã·ã¼ã±ã³ã¹å³
ã·ã¼ã±ã³ã¹æ¦è¦ã以ä¸ã«å³ç¤ºãã¾ãã
åä½ç¢ºèª
ããããELBã«ãã£ã¦çæãããCookieã®ç¶ææ©è½ã¨åæ§ã«åããµã¼ãã«ãªã¯ã¨ã¹ããæ¯ãåãããã¾ãã
ã¢ã¯ã»ã¹1åç®
ã¢ã¯ã»ã¹2æ¥ç®
ã¢ã¯ã»ã¹3åç®
注æç¹
注æç¹ã¨ãã¦ããµã¼ãå´ã§SSLã®çµç«¯ãè¡ãå ´åã¯ãã¹ãã£ããã¼ã»ãã·ã§ã³æ©è½ã使ããã¨ã¯ã§ãã¾ãããHTTPSã§HTTPããããæå·åãããã¨ãããã¨ãããã¾ããããµã¼ãå´ã§SSLãçµç«¯ããããããªã¹ãã¼ãTCPã§è¨å®ããã¨ãAWSã®ããã¸ã¡ã³ãã³ã³ã½ã¼ã«ä¸ããã以ä¸ã®ããã«ã¹ãã£ããã¼ã»ãã·ã§ã³ã®è¨å®ãè¡ããã¨ãåºæ¥ãªããªãã¾ãã
ãããã«
ä»åãELBã®ã¹ãã£ããã¼ã»ãã·ã§ã³ã«ã¤ãã¦ãã¾ã¨ãã¦ã¿ã¾ãããä¹¾ç¥ããå£ç¯ã§ãã®ã§ã風éªã«ã¯ç¹ã«æ°ãã¤ãã¦ãéããã¾ãããã
ç´ æè¼ï¼ããã°ãããããï¼ï¼ãµã¼ãã¹éçºé¨ï¼ è¨äºä¸è¦§
ãµã¼ãã¹éçºé¨æå±ã2015å¹´ã«ãµã¼ãã¼ã¯ã¼ã¯ã¹ã«JOINãã¯ã©ã¦ãã¤ã³ãã°ã¬ã¼ã·ã§ã³é¨ãçµã¦ãç¾å¨ã¯Cloud Automatorã®éçºã«å¾äºããã©ã¯ã¨é¨ãæ¨ããã³ãã¼ã¯â ¤ãæ¨ãã¢ã³ã¹ã¿ã¼ã¯ã¯ãã¯ã«ã¼ã