ÔõÑùÔÚLinuxÉÏʵÏÖ¸ºÔØƽºâ
ÔõÑùÔÚlinuxÉÏʵÏÖ¸ºÔØƽºâ
¸ºÔØƽºâÊÇÖ¸½«ÇëÇó·Ö·¢µ½¶à¸öЧÀÍÆ÷ÉÏ£¬ÒÔƽºâЧÀÍÆ÷µÄ¸ºÔØ£¬Ìá¸ßϵͳµÄ¿ÉÓÃÐÔºÍÐÔÄÜ¡£ÔÚLinuxϵͳÖУ¬¸ºÔØƽºâ¿ÉÒÔͨ¹ýʹÓÃLVS£¨Linux Virtual Server£©ºÍNginxÀ´ÊµÏÖ¡£ÏÂÃ潫ÏÈÈÝÔõÑùʹÓÃLVSºÍNginx¾ÙÐиºÔØƽºâµÄÉèÖá£
ʹÓÃLVSʵÏÖ¸ºÔØƽºâ
LVSÊÇÒ»ÖÖ»ùÓÚÄÚºËÄ£¿éµÄ¸ºÔØƽºâÈí¼þ£¬Ëü¿ÉÒÔ½«ÇëÇó·Ö·¢µ½¶à¸öºó¶ËЧÀÍÆ÷ÉÏ¡£ÒÔÏÂÊÇʹÓÃLVSʵÏÖ¸ºÔØƽºâµÄ°ì·¨£º
£¨1£©×°ÖÃLVSÈí¼þ°ü
ÔÚ Linux ϵͳÉÏ×°Öà LVS °ü£¬Ê¹ÓÃÒÔÏÂÏÂÁ
sudo apt-get install ipvsadm
µÇ¼ºó¸´ÖÆ
£¨2£©ÉèÖÃÐéÄâЧÀÍÆ÷
½¨ÉèÒ»¸öÐéÄâЧÀÍÆ÷£¬²¢½«ÇëÇó·Ö·¢µ½¶à¸öºó¶ËЧÀÍÆ÷ÉÏ¡£ÒÔÏÂÊÇÒ»¸öʾÀýµÄÐéÄâЧÀÍÆ÷µÄÉèÖãº
sudo ipvsadm -A -t <VIP>:<PORT> -s <SCHEDULER> sudo ipvsadm -a -t <VIP>:<PORT> -r <RSERVER1>:<RPORT> -g sudo ipvsadm -a -t <VIP>:<PORT> -r <RSERVER2>:<RPORT> -g sudo ipvsadm -a -t <VIP>:<PORT> -r <RSERVER3>:<RPORT> -g
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬ ÊÇÐéÄâ IP µØµã£¬ ÊÇÎüÊÕÇëÇóµÄ¶Ë¿ÚºÅ£¬ Êǵ÷ÀíÆ÷µÄÀàÐÍ£¨Èç wrr¡¢lc¡¢rr£©£¬ ¡¢ ºÍ ÊǺó¶ËЧÀÍÆ÷µÄ IP µØµã£¬ ÊǺó¶ËЧÀÍÆ÷µÄ¶Ë¿ÚºÅ¡£
£¨3£©¿ªÆô IP ת·¢
ÔÚ Linux ϵͳÉÏ¿ªÆô IP ת·¢£¬Ê¹ÓÃÒÔÏÂÏÂÁ
sudo sysctl -w net.ipv4.ip_forward=1
µÇ¼ºó¸´ÖÆ
ʹÓÃNginxʵÏÖ¸ºÔØƽºâ
Nginx ÊÇÒ»ÖÖ¸ßÐÔÄܵĿªÔ´ Web ЧÀÍÆ÷Èí¼þ£¬ËüÒ²¿ÉÒÔÓÃÓÚʵÏÖ¸ºÔØƽºâ¡£ÒÔÏÂÊÇʹÓà Nginx ʵÏÖ¸ºÔØƽºâµÄ°ì·¨£º
£¨1£©×°ÖÃNginxÈí¼þ°ü
ÔÚ Linux ϵͳÉÏ×°Öà Nginx Èí¼þ°ü£¬Ê¹ÓÃÒÔÏÂÏÂÁ
sudo apt-get install nginx
µÇ¼ºó¸´ÖÆ
£¨2£©ÐÞ¸ÄNginxÉèÖÃÎļþ
±à¼ Nginx µÄÉèÖÃÎļþ£¬Í¨³£ÊÇλÓÚ /etc/nginx/nginx.conf£¬ÕÒµ½¡°http¡±¿éÖеġ°server¡±¿é£¬½«ÆäÐÞ¸ÄΪÈçÏÂËùʾ£º
http { upstream myapp { server <RSERVER1>:<RPORT>; server <RSERVER2>:<RPORT>; server <RSERVER3>:<RPORT>; } server { listen <VIP>:<PORT>; location / { proxy_pass http://myapp; } } }
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬ ¡¢ ºÍ ÊǺó¶ËЧÀÍÆ÷µÄ IP µØµã£¬ ÊǺó¶ËЧÀÍÆ÷µÄ¶Ë¿ÚºÅ£¬ ÊÇÐéÄâ IP µØµã£¬ ÊÇÎüÊÕÇëÇóµÄ¶Ë¿ÚºÅ¡£
£¨3£©ÖØÆôNginxЧÀÍ
ʹÓÃÒÔÏÂÏÂÁîÖØÆô Nginx ЧÀÍ£º
sudo service nginx restart
µÇ¼ºó¸´ÖÆ
ÐèҪעÖصÄÊÇ£¬Nginx »¹Ö§³ÖÆäËûµÄ¸ºÔØƽºâËã·¨ºÍÉèÖÃÑ¡Ï¿ÉÒÔƾ֤ÏÖʵÐèÇó¾ÙÐе÷½â¡£
ÒÔÉϾÍÊÇÔÚ Linux ϵͳÉÏÔõÑùʹÓà LVS ºÍ Nginx ʵÏÖ¸ºÔØƽºâµÄ°ì·¨¡£Í¨¹ýºÏÀíÉèÖúÍʹÓÃÕâЩ¹¤¾ß£¬¿ÉÒÔÓÐÓÃÌá¸ßϵͳµÄ¿ÉÓÃÐÔºÍÐÔÄÜ£¬Ó¦ÓÃÓÚÖÖÖÖ»¥ÁªÍøÓ¦ÓúÍЧÀÍÖС£
ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏʵÏÖ¸ºÔØƽºâµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡