ÔõÑùÔÚLinuxÉÏÉèÖÃÍøÂ縺ÔØƽºâ
ÔõÑùÔÚlinuxÉÏÉèÖÃÍøÂ縺ÔØƽºâ
ÍøÂ縺ÔØƽºâÊÇÒ»ÖÖÊÖÒÕ£¬Ëü¿ÉÒÔ½«ÍøÂçÁ÷Á¿ÔȳƵطÖÅɸø¶ą̀ЧÀÍÆ÷£¬ÒÔÌá¸ßϵͳµÄ¿ÉÓÃÐԺͿÉÀ©Õ¹ÐÔ¡£ÔÚLinuxϵͳÉÏ£¬ÎÒÃÇ¿ÉÒÔʹÓÃһЩ¹¤¾ßºÍÊÖÒÕÀ´ÊµÏÖÍøÂ縺ÔØƽºâ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚlinuxÉÏÉèÖÃÍøÂ縺ÔØƽºâ£¬²¢ÌṩÏìÓ¦µÄ´úÂëʾÀý¡£
Ò»¡¢Ê¹ÓÃIPVSʵÏÖÍøÂ縺ÔØƽºâ
IPVS£¨IP Virtual Server£©ÊÇLinuxÄÚºËÖеÄÒ»¸öÄ£¿é£¬¿ÉÒÔÌṩÍøÂ縺ÔØƽºâµÄ¹¦Ð§¡£ÏÂÃæÊÇÉèÖÃIPVSµÄ°ì·¨£º
×°ÖÃIPVSÄ£¿éºÍÏà¹Ø¹¤¾ß£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Íê³É£º
sudo apt-get update sudo apt-get install ipvsadm keepalived
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÉèÖÃIPVS¹æÔò£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Ìí¼ÓIPVS¹æÔò£º
sudo ipvsadm -A -t 192.168.1.100:80 -s rr sudo ipvsadm -a -t 192.168.1.100:80 -r 192.168.1.101:80 -m sudo ipvsadm -a -t 192.168.1.100:80 -r 192.168.1.102:80 -m
µÇ¼ºó¸´ÖÆ
ÉÏÊöÏÂÁ½¨ÉèÒ»¸öIPVS¹æÔò£¬½«ËùÓд«ÈëIPµØµãΪ192.168.1.100ÇÒÄ¿µÄ¶Ë¿ÚΪ80µÄÇëÇóת·¢¸ø192.168.1.101ºÍ192.168.1.102¡£
Æô¶¯IPVSЧÀÍ£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Æô¶¯IPVSЧÀÍ£º
sudo service ipvs start
µÇ¼ºó¸´ÖÆ
ÖÁ´Ë£¬IPVSµÄÉèÖþÍÍê³ÉÁË¡£Äã¿ÉÒÔͨ¹ý»á¼û192.168.1.100:80À´²âÊÔ¸ºÔØƽºâµÄЧ¹û¡£
¶þ¡¢Ê¹ÓÃNGINXʵÏÖÍøÂ縺ÔØƽºâ
NGINXÊÇÒ»ÖÖ¹¦Ð§Ç¿Ê¢µÄWebЧÀÍÆ÷£¬ËüÒ²¿ÉÒÔÓÃÓÚʵÏÖÍøÂ縺ÔØƽºâ¡£ÏÂÃæÊÇÉèÖÃNGINXµÄ°ì·¨£º
×°ÖÃNGINX£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Íê³É£º
sudo apt-get update sudo apt-get install nginx
µÇ¼ºó¸´ÖÆ
ÉèÖÃNGINX·´ÏòÊðÀí£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´ÐÞ¸ÄNGINXµÄÉèÖÃÎļþ£º
sudo nano /etc/nginx/conf.d/load_balancer.conf
µÇ¼ºó¸´ÖÆ
ÔÚÉèÖÃÎļþÖÐÌí¼ÓÒÔÏÂÄÚÈÝ£º
upstream backend { server 192.168.1.101:80; server 192.168.1.102:80; } server { listen 80; location / { proxy_pass http://backend; } }
µÇ¼ºó¸´ÖÆ
ÉÏÊöÉèÖý«ËùÓÐÇëÇóת·¢¸ø192.168.1.101ºÍ192.168.1.102¡£
ÖØÆôNGINXЧÀÍ£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´ÖØÆôNGINXЧÀÍ£º
sudo service nginx restart
µÇ¼ºó¸´ÖÆ
ÖÁ´Ë£¬NGINXµÄÉèÖþÍÍê³ÉÁË¡£Äã¿ÉÒÔͨ¹ý»á¼ûhttp://localhostÀ´²âÊÔ¸ºÔØƽºâµÄЧ¹û¡£
Èý¡¢Ê¹ÓÃLVSʵÏÖÍøÂ縺ÔØƽºâ
LVS£¨Linux Virtual Server£©ÊÇ»ùÓÚIPVSµÄÒ»¸ö¿ªÔ´ÏîÄ¿£¬¾ßÓÐÓÅÒìµÄÐÔÄܺͿÉÀ©Õ¹ÐÔ¡£ÏÂÃæÊÇÉèÖÃLVSµÄ°ì·¨£º
×°ÖÃLVSÄ£¿éºÍÏà¹Ø¹¤¾ß£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Íê³É£º
sudo apt-get update sudo apt-get install ipvsadm keepalived
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÉèÖÃLVS¹æÔò£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Ìí¼ÓLVS¹æÔò£º
sudo ipvsadm -A -t 192.168.1.100:80 -s rr sudo ipvsadm -a -t 192.168.1.100:80 -r 192.168.1.101:80 -g sudo ipvsadm -a -t 192.168.1.100:80 -r 192.168.1.102:80 -g
µÇ¼ºó¸´ÖÆ
ÉÏÊöÏÂÁ½¨ÉèÒ»¸öLVS¹æÔò£¬½«ËùÓд«ÈëIPµØµãΪ192.168.1.100ÇÒÄ¿µÄ¶Ë¿ÚΪ80µÄÇëÇóת·¢¸ø192.168.1.101ºÍ192.168.1.102¡£
Æô¶¯LVSЧÀÍ£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Æô¶¯LVSЧÀÍ£º
sudo service lvs start
µÇ¼ºó¸´ÖÆ
ÖÁ´Ë£¬LVSµÄÉèÖþÍÍê³ÉÁË¡£Äã¿ÉÒÔͨ¹ý»á¼û192.168.1.100:80À´²âÊÔ¸ºÔØƽºâµÄЧ¹û¡£
×ܽá
±¾ÎÄÏÈÈÝÁËÔÚLinuxϵͳÉÏÉèÖÃÍøÂ縺ÔØƽºâµÄÈýÖÖÒªÁ죺ʹÓÃIPVS¡¢NGINXºÍLVS¡£ÎÞÂÛÄãÑ¡ÔñÄÄÖÖÒªÁ죬¶¼ÐèҪװÖÃÏìÓ¦µÄÈí¼þºÍ¹¤¾ß£¬²¢Æ¾Ö¤ÏìÓ¦µÄ°ì·¨ÉèÖøºÔØƽºâ¹æÔò¡£ÒÔÉÏ´úÂëʾÀý¿ÉÒÔ×ÊÖúÄãÃ÷È·ºÍʵ¼ù¸ºÔØƽºâÉèÖõÄÀú³Ì¡£Ï£Íû±¾ÎĶÔÄãÔÚLinuxϵͳÉÏÉèÖÃÍøÂ縺ÔØƽºâÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖÃÍøÂ縺ÔØƽºâµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡