ã´ã¼ã«
- è² è·åæ£ã®ããã¤ãã®æ¹æ³ã«é¢ãã¦ç解ãã
- mod_proxy_balancerã«ããè² è·åæ£ã¯ã©ã¹ã¿ãæ§ç¯ã§ãã
åºç¤ç¥èç·¨
åºæ¬çãªè³æ
主ã«ã¯ã©ã¹ã¿ã«ããè² è·åæ£ã®è³æã
- Apache ã¢ã¸ã¥ã¼ã« mod_proxy_balancer
- mod_proxy_balancerã§ä¸?大è¦æ¨¡ãµã¼ãã¼éç¨ããã¨ãã®åæ - cyano
ãã¨ç¤¾å¤ç§è³æã
è² è·åæ£ï¼
è¤æ°å°ã®ãµã¼ãã«ã¢ã¯ã»ã¹ãåæ£ãã¦ãåã ã®ãµã¼ãã«ãããè² è·ãæ¸ãããå ¨ä½çã«å¦çã§ããã¢ã¯ã»ã¹ãå¢ãããã¨ã
以ä¸ã®ãããªã¢ããã¼ããããã
DNSã©ã¦ã³ãããã³
- DNSã§ã²ã¨ã¤ã®ãã¹ãåã«è¤æ°ã®IPã¢ãã¬ã¹ãå²ãå½ã¦ãæ¹æ³
- ã·ã³ãã«
ããããã¦ã³ãã¦ãããã¹ãã«ãã¢ã¯ã»ã¹ãæ¯ãåãããã¦ãã¾ã
- åé·åã¨ä½µç¨ã§ãªãã¨ããªãããªï¼
æ©è½ãã¨ã«ãã¹ããåå²
- ã¦ã§ããµã¼ãã¨DBãµã¼ãã®åå²ï¼åºæ¬éãããä¸å¿ãããè² è·åæ£ï¼
- æä¾ããã³ã³ãã³ããã¨ã«ãã¹ããåå²
- ã ãã¹ã±ã¼ã«ããã»ã©æ§æãè¤éã«ãªãã¨ããé£ç¹
è² è·åæ£ã¯ã©ã¹ã¿
- ãããããã¼ããã©ã³ãµãå©ç¨ããè² è·åæ£
- è¤æ°å°ã®ãã¹ããåä¸æ©è½ãæä¾
- è½ã¡ããã¹ãã«ã¯ã¢ã¯ã»ã¹ã®æ¯ãåããè¡ãããªã
- ã¹ã±ã¼ã«ãããã
é常ã«å¤§è¦æ¨¡ã«ãªãã¨ãããã®ã¢ããã¼ããä½µç¨ãããã¨ã«ãªãã¨æãã
ã¨ããããä»åã¯ä¸»ã«è² è·åæ£ã¯ã©ã¹ã¿ã®è©±ã§ã
mod_proxy_balancerã£ã¦ï¼
L7ã§ã®è² è·åæ£ãè¡ãApacheã®ã¢ã¸ã¥ã¼ã«ã Apache 2.2ãã使ããããã«ãªã£ãã
ããã«ãã£ã¦è² è·åæ£ã¯ã©ã¹ã¿ãæ§ç¯ã§ããã
ä»åãã£ã¦ããã®ã¯ããã
LVSã£ã¦ï¼
Linux Virtual Serverã®ç¥ã L4ã§ã®è² è·åæ£ãè¡ãLinuxã«ã¼ãã«ã®æ©è½ã
L7ã§ã®è² è·åæ£ããå¤ãã®ãã©ãã£ãã¯ããã°ããããéç¨ãã¦ããã«ã¯ãããªãã®ãããã¯ã¼ã¯ç¥èã¨è±èªåï¼è±èªã®æ å ±ãå§åçã«å¤ãã®ã§ï¼ãå¿ è¦ã 詳ããã¯WEB+DBãã¬ã¹ã®vol.37ããããããã£ã¤ãèªãã§ãã ããã
ãã®ä»åèã
- ãããªã«ç°¡åï¼ Linuxã§ãã¼ããã©ã³ãµ (1) - DSASéçºè
ã®é¨å±
- LVS-HOWTO
è¨å®ãã¡ã¤ã«ã®æ¸ãæ¹
è¨å®ã®åæ
- LBæ©1å° (192.168.1.100)
- ããã¯ã¨ã³ã2å° (192.168.1.101, 192.168.1.102)
LBæ©
ãã¼ãã£ã«ãã¹ããä½ã£ã¦ããã«è¨å®ãæ¸ãã¦ããã ï¼ãã¼ãã£ã«ãã¹ããå®ç¾©ããªãã¦ãããããä»åã¯ãã¼ãã£ã«ãã¹ãã«ããï¼
<VirtualHost *:80>
ProxyRequest Off
ProxyPass / balancer://cluster/
ProxyPass /balancer-manager !
<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Deny from all
Allow from 192.168.1.0/24
</Location>
<Proxy balancer://cluster/>
BalancerMember http://192.168.1.101/ loadfactor=10
BalancerMember http://192.168.1.102/ loadfactor=10
</Proxy>
</VirtualHost>
å®è·µç·¨ - åºæ¬ -
äºå°ã¸ã®è² è·åæ£ã®ç¢ºèª
æ¯ãåãå ã®ãã¹ãã«ããããç°ãªãå 容ã®ãã¡ã¤ã«ç¨æãã¦ã¢ã¯ã»ã¹ãã¦ã¿ãã
ã¢ã¯ã»ã¹ã®é½åº¦ç°ãªããã¹ãã«ã¤ãªãããã¨ã確èªããã
ããã¯ã¨ã³ãä¸å°è½ã¡ã
è½ã¡ãæ¹ã«ã¯ã¢ã¯ã»ã¹ãæ¯ãåããããªãã
ã¤ã¨ã¹ï¼
ããã¯ã¨ã³ãå ¨é¨è½ã¡ã
Service Temporarily Unavailable
ãããªæ ç«ã¡ã½ããã
ErrorDocument 503 (ç«ã®URLï¼
ãã¼ããã©ã³ãµè½ã¡ã
åé·åãã¨ãã¾ãããã
ãã©ã³ãµããã¼ã¸ã£
ã¯ã©ã¹ã¿ã®ç¶æ ã®ç¢ºèªã¨æ´æ°ãã§ããã
ããããããã£ã¦ã¿ã¾ãããã
å®è·µç·¨ - å¿ç¨ -
stickysession
以ä¸ã®è¡æ´æ°ã
ProxyPass / balancer://cluster/ stickysession=backendid
BalancerMember http://192.168.1.101/ loadfactor=10 route=1
BalancerMember http://192.168.1.102/ loadfactor=10 route=2
次ã®ãããªãã¡ã¤ã«ãããããã®ãµã¼ãã«ç½®ãã
101
<?php
setcookie('backendid', "hogehoge.1");
?>
102
<?php
setcookie('backendid', "hogehoge.2");
?>
ãhogehoge.nãããroute=nãã«å¯¾å¿ããã
stickysessionå¼µã£ãç¶æ ã§101ãè½ã¡ãã
ã®ã£ã¼ã¹ï¼ç«åã³ã
è½ã¡ã¦ããã»ãã«ã¢ã¯ã»ã¹æ¯ãåããåºå®ãããã¾ã¾ã«ãªã£ã¦ãã¾ãã
è½ã¡ã¦ãå¹³æ°ãªããã«
redirectãæå®ããã
BalancerMember http://192.168.1.101/ loadfactor=10 route=1 redirect=2
BalancerMember http://192.168.1.102/ loadfactor=10 route=2
101ãè½ã¡ã¦ããã¨102ã®æ¹ã¸ã¤ãªããã
ãããç¸äºãªãã¤ã¬ã¯ãã¯ãã¾ããããªãã®ã§ã以ä¸ã®ããã«ã¯æ¸ããªãã
BalancerMember http://192.168.1.102/ loadfactor=10 route=2 redirect=1
ã ãã102ã®æ¹ãè½ã¡ãããã£ã±ãç«ã
ãã©ã³ãµããã¼ã¸ã£ã®è¨å®æ´æ°ãGETã§æ軽ã«å©ãããããªã®ã§ãããã¯ã¨ã³ããNagiosãªã©ã§ç£è¦ãã¦ãè½ã¡ã¦ããããªãã¤ã¬ã¯ãå ãåçã«è¨å®ãããããªã¹ã¯ãªãããæ¸ããããã¦ããã¨ãããããããªãã
çé¢ç®ã«ãããã¨ããã¨æå¤ã¨ããã©ãããstickysessionã
éçãã¡ã¤ã«ããã¼ããã©ã³ãµã§è¿ã
ããã¯ã¨ã³ããåçãã¡ã¤ã«ãæ±ããµã¼ãã®å ´åããã®ãµã¼ãã«éçãã¡ã¤ã«ãæ±ãããã¨ãªã½ã¼ã¹ããã£ãããªãã ãªã®ã§éçãªãã¡ã¤ã«ã¯ãã¼ããã©ã³ãµãè¿ãããã«ããã¨ãå¾ã
以ä¸ã®è¡è¿½å ã
ProxyPass /img !
ProxyPass /css !
éçãã¡ã¤ã«ã¯åçãã¡ã¤ã«ã«æ¯ã¹ã¦è² è·ãæ°ååã®ä¸ããç¾åã®ä¸ä»¥ä¸ãªã®ã§ãå ¨é¨ãã¼ããã©ã³ãµã§ãã°ãã¦ããã£ãããããã
ããã¯ã¨ã³ãã®ãã°ã®ãªã¢ã¼ãIP
ãµã¼ãå¤æ°ã®REMOTE_ADDRããã¼ããã©ã³ãµã®IPã«ãªã£ã¦ãã¾ãã®ã§æ¬¡ã®ãããªå°ã£ããã¨ãèµ·ããã
- ããã°ã©ã å
ã§ã¯ã©ã¤ã¢ã³ãã®ãªã¢ã¼ãIPãåããªãï¼ä»ã®å¤æ°ã«è¨é²ãããã®ã§åããã¨æãã°åããããããã°ã©ã ã®æ¹å¤ãå¿
è¦ã«ãªãï¼
- IPã«ããã¢ã¯ã»ã¹å¶éãå¹ããªããªã
- ãã°ã®ãªã¢ã¼ãIPããã¹ã¦ãã¼ããã©ã³ãµã®ãã®ã«ãªã
ããã§mod_rpafã使ãã
åè : ãªãã¼ã¹ãããã·ãå°å ¥ããéã¯mod_rpaf :: Drk7jp
ããã¯ã¨ã³ãå´ã§ä»¥ä¸ã®è¨å®ã追è¨ã
<IfModule mod_rpaf-2.0.c>
RPAFenable On
RPAFsethostname Off
RPAFproxy_ips 192.168.1.100
</IfModule>