linux¸ºÔØƽºâÔõôÉèÖÃ
ÔÚ linux ϵͳÖУ¬¸ºÔØƽºâͨ¹ý½«ÍøÂçÇëÇóÂþÑܵ½¶à¸öЧÀÍÆ÷£¬Ìá¸ßÁË´¦Öóͷ£ÄÜÁ¦ºÍϵͳ¿É¿¿ÐÔ¡£³£Óù¤¾ß°üÀ¨ haproxy¡¢nginx¡¢lvs ºÍ keepalived¡£ÉèÖð취Ϊ£º1£©×°ÖøºÔØƽºâÈí¼þ£»2£©ÉèÖÃЧÀÍÆ÷²ÎÊý£»3£©Æô¶¯Ð§ÀÍ£»4£©²âÊÔ¸ºÔØƽºâ£»5£©£¨¿ÉÑ¡£©½¨É輯ȺÖÎÀí¡£
Linux¸ºÔØƽºâÉèÖÃ
¸ºÔØƽºâµÄ×÷ÓÃ
¸ºÔØƽºâÔÚLinuxϵͳÖÐÊÎÑÝ×ÅÖÁ¹ØÖ÷ÒªµÄ½ÇÉ«£¬Ëü¿ÉÒÔ½«ÍøÂçÇëÇóÂþÑܵ½¶à¸öЧÀÍÆ÷ÉÏ£¬ÒÔÌá¸ß´¦Öóͷ£ÄÜÁ¦£¬Ôöǿϵͳ¿É¿¿ÐÔ£¬²¢×èÖ¹µ¥µã¹ÊÕÏ¡£
³£ÓõÄLinux¸ºÔØƽºâ¹¤¾ß
LinuxϵͳÖг£ÓõĸºÔØƽºâ¹¤¾ß°üÀ¨£º
HAProxy
Nginx
LVS (Linux Virtual Server)
Keepalived
¸ºÔØƽºâµÄÉèÖð취
1. ×°ÖøºÔØƽºâÈí¼þ
ƾ֤ÐèҪѡÔñµÄ¸ºÔØƽºâ¹¤¾ß£¬Í¨¹ý¿¯ÐаæµÄ°ü¹ÜÀí¹¤¾ß¾ÙÐÐ×°Öá£ÀýÈ磬¹ØÓÚUbuntuϵͳװÖÃHAProxy£º
apt-get install haproxy
µÇ¼ºó¸´ÖÆ
2. ÉèÖøºÔØƽºâЧÀÍÆ÷
±à¼¸ºÔØƽºâÈí¼þµÄÉèÖÃÎļþ£¬Ö¸¶¨ÐèҪƽºâµÄЧÀÍÆ÷£¬¶Ë¿ÚºÍËã·¨µÈ²ÎÊý¡£ÀýÈ磬HAProxyµÄÉèÖÃƬ¶Ï£º
frontend http-in bind *:80 default_backend servers backend servers server server1 192.168.1.101:8080 server server2 192.168.1.102:8080
µÇ¼ºó¸´ÖÆ
3. Æô¶¯¸ºÔØƽºâЧÀÍ
Æô¶¯¸ºÔØƽºâЧÀÍ£¬×îÏÈ´¦Öóͷ£ÍøÂçÇëÇó¡£ÀýÈ磬Æô¶¯HAProxy£º
service haproxy start
µÇ¼ºó¸´ÖÆ
4. ²âÊÔ¸ºÔØƽºâ
ʹÓÃcurl»òÆäËû¹¤¾ß²âÊÔ¸ºÔØƽºâÊÇ·ñÕý³£ÊÂÇé¡£ÀýÈ磬²âÊÔHAProxy£º
curl http://loadbalancer.example.com
µÇ¼ºó¸´ÖÆ
5. ¼¯ÈºÖÎÀí£¨¿ÉÑ¡£©
ÈôÊÇÐèÒª½¨É踺ÔØƽºâ¼¯Èº£¬¿ÉÒÔʹÓÃKeepalivedµÈ¹¤¾ßʵÏÖ¹ÊÕÏתÒƺ͸߿ÉÓÃÐÔ¡£
ÒÔÉϾÍÊÇlinux¸ºÔØƽºâÔõôÉèÖõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡