\n\u5bfc\u8bfb<\/td>\n | LVS\u662fLinux Virtual Server\u7684\u7b80\u5199\uff0c\u610f\u5373Linux\u865a\u62df\u670d\u52a1\u5668\uff0c\u662f\u4e00\u4e2a\u865a\u62df\u7684\u670d\u52a1\u5668\u96c6\u7fa4\u7cfb\u7edf\u3002LVS\u76ee\u524d\u6709\u4e09\u79cdIP\u8d1f\u8f7d\u5747\u8861\u6280\u672f\uff08VS\/NAT\u3001VS\/TUN\u548cVS\/DR\uff09\u3001\u5341\u79cd\u8c03\u5ea6\u7b97\u6cd5\uff08rrr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq\uff09,LVS\u5728Unix-like\u7cfb\u7edf\u4e2d\u662f\u4f5c\u4e3a\u4e00\u4e2a\u524d\u7aef(Director)\u5b58\u5728\u7684\uff0c\u53c8\u79f0\u4e3a\u8c03\u5ea6\u5668\uff0c\u5b83\u672c\u8eab\u4e0d\u63d0\u4f9b\u4efb\u4f55\u7684\u670d\u52a1\uff0c\u53ea\u662f\u5c06\u901a\u8fc7\u4e92\u8054\u7f51\u8fdb\u6765\u7684\u8bf7\u6c42\u63a5\u53d7\u540e\u518d\u8f6c\u53d1\u7ed9\u540e\u53f0\u8fd0\u884c\u7684\u771f\u6b63\u7684\u670d\u52a1\u5668(RealServer)\u8fdb\u884c\u5904\u7406\uff0c\u7136\u540e\u54cd\u5e94\u7ed9\u5ba2\u6237\u7aef\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n <\/p>\n LVS\u96c6\u7fa4\u91c7\u7528IP\u8d1f\u8f7d\u5747\u8861\u6280\u672f\u548c\u57fa\u4e8e\u5185\u5bb9\u8bf7\u6c42\u5206\u53d1\u6280\u672f\u3002\u8c03\u5ea6\u5668\u5177\u6709\u5f88\u597d\u7684\u541e\u5410\u7387\uff0c\u5c06\u8bf7\u6c42\u5747\u8861\u5730\u8f6c\u79fb\u5230\u4e0d\u540c\u7684\u670d\u52a1\u5668\u4e0a\u6267\u884c\uff0c\u4e14\u8c03\u5ea6\u5668\u81ea\u52a8\u5c4f\u853d\u6389\u670d\u52a1\u5668\u7684\u6545\u969c\uff0c\u4ece\u800c\u5c06\u4e00\u7ec4\u670d\u52a1\u5668\u6784\u6210\u4e00\u4e2a\u9ad8\u6027\u80fd\u7684\u3001\u9ad8\u53ef\u7528\u7684\u865a\u62df\u670d\u52a1\u5668\u3002\u6574\u4e2a\u670d\u52a1\u5668\u96c6\u7fa4\u7684\u7ed3\u6784\u5bf9\u5ba2\u6237\u662f\u900f\u660e\u7684\uff0c\u800c\u4e14\u65e0\u9700\u4fee\u6539\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u7aef\u7684\u7a0b\u5e8f\u3002\u4e3a\u6b64\uff0c\u5728\u8bbe\u8ba1\u65f6\u9700\u8981\u8003\u8651\u7cfb\u7edf\u7684\u900f\u660e\u6027\u3001\u53ef\u4f38\u7f29\u6027\u3001\u9ad8\u53ef\u7528\u6027\u548c\u6613\u7ba1\u7406\u6027\u3002<\/p>\n LVS\u6709\u4e24\u4e2a\u91cd\u8981\u7684\u7ec4\u4ef6\uff1a\u4e00\u4e2a\u662fIPVS\uff0c\u4e00\u4e2a\u662fIPVSADM\u3002ipvs\u662fLVS\u7684\u6838\u5fc3\u7ec4\u4ef6\uff0c\u5b83\u672c\u8eab\u53ea\u662f\u4e00\u4e2a\u6846\u67b6\uff0c\u7c7b\u4f3c\u4e8eiptables\uff0c\u5de5\u4f5c\u4e8e\u5185\u6838\u7a7a\u95f4\u4e2d\u3002ipvsadm \u662f\u7528\u6765\u5b9a\u4e49LVS\u7684\u8f6c\u53d1\u89c4\u5219\u7684\uff0c\u5de5\u4f5c\u4e8e\u7528\u6237\u7a7a\u95f4\u4e2d\u3002<\/p>\n LVS\u6709\u4e09\u79cd\u8f6c\u53d1\u7c7b\u578b<\/strong><\/div>\nLVS-NAT\u6a21\u5f0f<\/strong><\/span><\/div>\n\u79f0\u4e3a\u7f51\u7edc\u5730\u5740\u8f6c\u6362\uff0c\u5b9e\u73b0\u8d77\u6765\u6bd4\u8f83\u7b80\u5355\uff0c\u6240\u6709\u7684RealServer\u96c6\u7fa4\u8282\u70b9\u548c\u524d\u7aef\u8c03\u5ea6\u5668Director\u90fd\u8981\u5728\u540c\u4e00\u4e2a\u5b50\u7f51\u4e2d\uff0c\u8fd9\u79cd\u6a21\u578b\u53ef\u4ee5\u5b9e\u73b0\u7aef\u53e3\u6620\u5c04\uff0cRealServer\u7684\u64cd\u4f5c\u7cfb\u7edf\u53ef\u4ee5\u662f\u4efb\u610f\u64cd\u4f5c\u7cfb\u7edf\uff0c\u524d\u7aef\u7684Director\u65e2\u8981\u5904\u7406\u5ba2\u6237\u7aef\u53d1\u8d77\u7684\u8bf7\u6c42\uff0c\u53c8\u8981\u5904\u7406\u540e\u53f0RealServer\u7684\u54cd\u5e94\u4fe1\u606f\uff0c\u5c06RealServer\u54cd\u5e94\u7684\u4fe1\u606f\u518d\u8f6c\u53d1\u7ed9\u5ba2\u6237\u7aef\uff0c\u524d\u7aefDirector\u5f88\u5bb9\u6613\u6210\u4e3a\u6574\u4e2a\u96c6\u7fa4\u7cfb\u7edf\u6027\u80fd\u7684\u74f6\u9888\u3002\u901a\u5e38\u60c5\u51b5\u4e0bRealServer\u7684IP\u5730\u5740(\u4ee5\u4e0b\u7b80\u6210RIP)\u4e3a\u79c1\u6709\u5730\u5740\uff0c\u4fbf\u4e8eRealServer\u96c6\u7fa4\u8282\u70b9\u4e4b\u95f4\u8fdb\u884c\u901a\u4fe1\u901a\u5e38\u60c5\u51b5\u4e0b\u524d\u7aef\u7684Director\u6709\u4e24\u4e2aIP\u5730\u5740\uff0c\u4e00\u4e2a\u4e3aVIP\uff0c\u662f\u865a\u62df\u7684IP\u5730\u5740\uff0c\u5ba2\u6237\u7aef\u5411\u6b64IP\u5730\u5740\u53d1\u8d77\u8bf7\u6c42\u3002\u4e00\u4e2a\u662fDIP\uff0c\u662f\u771f\u6b63\u7684Director\u7684IP\u5730\u5740\uff0cRIP\u7684\u7f51\u5173\u8981\u6307\u5411Director\u7684DIP\u3002<\/p>\n LVS-DR\u6a21\u5f0f<\/strong><\/span><\/div>\nDR\uff1a\u76f4\u63a5\u8def\u7531\uff08direct routing\uff09\u6a21\u5f0f\uff0c\u6b64\u79cd\u6a21\u5f0f\u901a\u8fc7MAC\u5730\u5740\u8f6c\u53d1\u5de5\u4f5c\uff0c\u6240\u6709\u7684RealServer\u96c6\u7fa4\u8282\u70b9\u548c\u524d\u7aef\u8c03\u5ea6\u5668Director\u90fd\u8981\u5728\u540c\u4e00\u4e2a\u7269\u7406\u7f51\u7edc\u4e2d\uff0c\u6b64\u79cd\u6a21\u5f0f\u4e0d\u652f\u6301\u7aef\u53e3\u6620\u5c04\uff0c\u6b64\u79cd\u6a21\u5f0f\u7684\u6027\u80fd\u8981\u4f18\u4e8eLVS-NAT\uff0cRIP\u53ef\u4ee5\u4f7f\u7528\u516c\u7f51\u7684IP\uff0cRIP\u7684\u7f51\u5173\u4e0d\u80fd\u6307\u5411DIP\u3002<\/p>\n \u4f18\u70b9\uff1a<\/p>\n \u76f8\u5bf9LVS\/NAT\u6a21\u5f0f\uff0cDR\u6a21\u5f0f\u4e0d\u9700\u8981\u628a\u8fd4\u56de\u7684\u6570\u636e\u901a\u8fc7\u8d1f\u8f7d\u5747\u8861\u8f6c\u53d1\uff0c\u60f3\u8981\u4ed6\u53d1\u6325\u4f18\u52bf\uff0c\u90a3\u4e48\u5c31\u8981\u76f8\u5e94\u7684\u6570\u636e\u5305\u7684\u6570\u91cf\u548c\u957f\u5ea6\u8fdc\u8fdc\u5927\u4e8e\u8bf7\u6c42\u6570\u636e\u5305\uff0c\u5e78\u8fd0\u7684\u662f\uff0c\u5927\u90e8\u5206WEB\u670d\u52a1\u90fd\u5177\u5907\u8fd9\u6837\u7684\u7279\u70b9\uff0c\u54cd\u5e94\u548c\u8bf7\u6c42\u5e76\u4e0d\u5bf9\u79f0\uff0c\u56e0\u6b64\u5e38\u7528\u7684WEB\u670d\u52a1\uff0c\u90fd\u53ef\u4ee5\u4f7f\u7528\u8fd9\u79cd\u6a21\u5f0f\u3002<\/p>\n \u8fd9\u79cd\u65b9\u5f0f\uff0c\u8d1f\u8f7d\u5747\u8861\u5668\u4e0d\u518d\u662f\u7cfb\u7edf\u7684\u74f6\u9888\u3002\u5982\u679c\u4f60\u7684\u8d1f\u8f7d\u5747\u8861\u5668\u53ea\u62e5\u6709100M\u7684\u5168\u53cc\u5de5\u7f51\u5361\u548c\u5e26\u5bbd\u7684\u8bdd\uff0c\u901a\u8fc7\u96c6\u7fa4\u7684\u6a2a\u5411\u6269\u5c55\u4e5f\u53ef\u4ee5\u8ba9\u6574\u4e2a\u7cfb\u7edf\u8fbe\u52301G\u7684\u6d41\u91cf\u3002<\/p>\n \u6765\u81eaLVS\u5b98\u65b9\u7ad9\u70b9\u7684\u6d4b\u8bd5\u7ed3\u679c\u4e5f\u544a\u8bc9\u6211\u4eec\uff0cLVS-DR\u53ef\u4ee5\u5bb9\u7eb3100\u53f0\u4ee5\u4e0a\u7684\u5b9e\u9645\u5e94\u7528\u670d\u52a1\u5668\uff0c\u5bf9\u4e00\u822c\u7684\u670d\u52a1\u800c\u5df2\uff0c\u8fd9\u6837\u7684\u8868\u73b0\u8db3\u591f\u4e86\u3002<\/p>\n \u4e0d\u8db3\uff1a<\/p>\n DR\u6a21\u5f0f\u4e0b\u4e0d\u80fd\u8de8\u7f51\u6bb5\u8f6c\u53d1\u6570\u636e\uff0c\u5982\u679c\u5fc5\u987b\u8981\u8de8\u7f51\u6bb5\u8fdb\u884c\u8d1f\u8f7d\uff0c\u90a3\u4e48\u5c31\u5fc5\u987b\u4f7f\u7528LVS\/TUN\u6a21\u5f0f\u3002<\/p>\n LVS-TUN\u6a21\u5f0f<\/strong><\/span><\/div>\n\u79f0\u4e3a\u96a7\u9053\u6a21\u578bRealServer\u670d\u52a1\u5668\u4e0e\u524d\u7aef\u7684Director\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u7f51\u7edc\u4e2d\uff0c\u6b64\u79cd\u6a21\u578b\u4e5f\u4e0d\u652f\u6301\u7aef\u53e3\u6620\u5c04\uff0cRealServer\u53ea\u80fd\u4f7f\u7528\u54ea\u4e9b\u652f\u6301IP\u96a7\u9053\u7684\u64cd\u4f5c\u7cfb\u7edf\uff0c\u524d\u7aef\u7684Director\u53ea\u5904\u7406\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\uff0c\u7136\u540e\u5c06\u8bf7\u6c42\u8f6c\u53d1\u7ed9RealServer\uff0c\u7531\u540e\u53f0\u7684RealServer\u76f4\u63a5\u54cd\u5e94\u5ba2\u6237\u7aef\uff0c\u4e0d\u518d\u7ecf\u8fc7Director\uff0cRIP\u4e00\u5b9a\u4e0d\u80fd\u662f\u79c1\u6709IP\uff0c\u5728DR\u3001TUN\u6a21\u5f0f\u4e2d\uff0c\u6570\u636e\u5305\u662f\u76f4\u63a5\u8fd4\u56de\u7ed9\u7528\u6237\u7684\uff0c\u6240\u4ee5\uff0c\u5728Director Server\u4e0a\u4ee5\u53ca\u96c6\u7fa4\u7684\u6bcf\u4e2a\u8282\u70b9\u4e0a\u90fd\u9700\u8981\u8bbe\u7f6e\u8fd9\u4e2a\u5730\u5740\u3002\u6b64IP\u5728Real Server\u4e0a\u4e00\u822c\u7ed1\u5b9a\u5728\u56de\u73af\u5730\u5740\u4e0a\uff0c\u4f8b\u5982lo:0\uff0c\u540c\u6837\uff0c\u5728Director Server\u4e0a\uff0c\u865a\u62dfIP\u7ed1\u5b9a\u5728\u771f\u5b9e\u7684\u7f51\u7edc\u63a5\u53e3\u8bbe\u5907\u4e0a\uff0c\u4f8b\u5982eth0:0\u3002<\/p>\n \u5f00\u59cb\u90e8\u7f72<\/strong><\/span><\/div>\n\u51c6\u5907\u56db\u53f0\u670d\u52a1\u5668\u6216\u865a\u62df\u673a\uff1a<\/p>\n \r\nWeb Nginx\uff1a10.16.8.8\/10.16.8.9\r\nKeepalived\uff1a10.16.8.10\/10.16.8.11\r\nKeepalived VIP\uff1a10.16.8.100\/10.16.8.101\r\nOS\uff1aCentOS Linux release 7.4.1708 (Core)\r\n<\/pre>\n\u5148\u51b3\u6761\u4ef6\uff1a<\/p>\n \u5b89\u88c5keepalived\u3002<\/p>\n \u65f6\u95f4\u540c\u6b65\u3002<\/p>\n \u8bbe\u7f6eSELinux\u548c\u9632\u706b\u5899\u3002<\/p>\n \u4e92\u76f8\u4e4b\u95f4\/etc\/hosts\u6587\u4ef6\u6dfb\u52a0\u5bf9\u65b9\u4e3b\u673a\u540d\uff08\u53ef\u9009\uff09\u3002<\/p>\n \u786e\u8ba4\u7f51\u7edc\u63a5\u53e3\u652f\u6301\u591a\u64ad\uff08\u7ec4\u64ad\uff09\u65b0\u7f51\u5361\u9ed8\u8ba4\u652f\u6301\u3002<\/p>\n \u4ee5\u4e0a\u90e8\u7f72\u8bf7\u53c2\u9605\uff1a\u300akeepalived \u5b89\u88c5\u53ca\u914d\u7f6e\u6587\u4ef6\u8bb2\u89e3\u300b\u3002<\/p>\n ka67\u914d\u7f6e\u6587\u4ef6<\/strong><\/span><\/div>\n\r\n$ vim \/usr\/local\/keepalived\/etc\/keepalived\/keepalived.conf\r\nglobal_defs {\r\n notification_email {\r\n root@localhost\r\n }\r\n notification_email_from ka@localhost\r\n smtp_server 127.0.0.1\r\n smtp_connect_timeout 60\r\n vrrp_mcast_group4 224.0.0.111\r\n}\r\nvrrp_instance VI_1 {\r\n state MASTER\r\n interface eth1\r\n virtual_router_id 191\r\n priority 100\r\n advert_int 1\r\n authentication {\r\n auth_type PASS\r\n auth_pass renwole0\r\n }\r\n virtual_ipaddress {\r\n 10.16.8.100\r\n }\r\n notify_master \"\/usr\/local\/keepalived\/etc\/keepalived\/notify.sh master\"\r\n notify_backup \"\/usr\/local\/keepalived\/etc\/keepalived\/notify.sh backup\"\r\n notify_fault \"\/usr\/local\/keepalived\/etc\/keepalived\/notify.sh fault\" \r\n}\r\nvrrp_instance VI_2 {\r\n state BACKUP\r\n interface eth1\r\n virtual_router_id 192\r\n priority 95\r\n advert_int 1\r\n authentication {\r\n auth_type PASS\r\n auth_pass renwole1\r\n }\r\n virtual_ipaddress {\r\n 10.16.8.101\r\n }\r\n notify_master \"\/usr\/local\/keepalived\/etc\/keepalived\/notify.sh master\"\r\n notify_backup \"\/usr\/local\/keepalived\/etc\/keepalived\/notify.sh backup\"\r\n notify_fault \"\/usr\/local\/keepalived\/etc\/keepalived\/notify.sh fault\" \r\n}\r\n<\/pre>\nka68\u914d\u7f6e\u6587\u4ef6<\/strong><\/span><\/div>\n\r\n$ vim \/usr\/local\/keepalived\/etc\/keepalived\/keepalived.conf\r\nglobal_defs {\r\n notification_email {\r\n root@localhost\r\n }\r\n notification_email_from ka@localhost\r\n smtp_server 127.0.0.1\r\n smtp_connect_timeout 60\r\n vrrp_mcast_group4 224.0.0.111\r\n}\r\nvrrp_instance VI_1 {\r\n state BACKUP\r\n interface eth1\r\n virtual_router_id 191\r\n priority 95\r\n advert_int 1\r\n authentication {\r\n auth_type PASS\r\n auth_pass renwole0\r\n }\r\n virtual_ipaddress {\r\n 10.16.8.100\r\n }\r\n notify_master \"\/usr\/local\/keepalived\/etc\/keepalived\/notify.sh master\"\r\n notify_backup \"\/usr\/local\/keepalived\/etc\/keepalived\/notify.sh backup\"\r\n notify_fault \"\/usr\/local\/keepalived\/etc\/keepalived\/notify.sh fault\" \r\n}\r\nvrrp_instance VI_2 {\r\n state MASTER\r\n interface eth1\r\n virtual_router_id 192\r\n priority 100\r\n advert_int 1\r\n authentication {\r\n auth_type PASS\r\n auth_pass renwole1\r\n }\r\n virtual_ipaddress {\r\n 10.16.8.101\r\n }\r\n notify_master \"\/usr\/local\/keepalived\/etc\/keepalived\/notify.sh master\"\r\n notify_backup \"\/usr\/local\/keepalived\/etc\/keepalived\/notify.sh backup\"\r\n notify_fault \"\/usr\/local\/keepalived\/etc\/keepalived\/notify.sh fault\" \r\n}\r\n<\/pre>\n\u521b\u5efa\u901a\u7528notify.sh\u68c0\u6d4b\u811a\u672c<\/strong><\/span><\/div>\n\u5206\u522b\u521b\u5efa\u6b64\u811a\u672c\uff1a<\/p>\n \r\n$ vim \/usr\/local\/keepalived\/etc\/keepalived\/notify.sh\r\n#!\/bin\/bash\r\n#\r\ncontact='root@localhost'\r\n \r\nnotify() {\r\n local mailsubject=\"$(hostname) to be $1, vip floating\"\r\n local mailbody=\"$(date +'%F %T'): vrrp transition, $(hostname) changed to be $1\"\r\n echo \"$mailbody\" | mail -s \"$mailsubject\" $contact\r\n}\r\n \r\ncase $1 in\r\nmaster)\r\n notify master \r\n ;;\r\nbackup)\r\n notify backup \r\n ;;\r\nfault)\r\n notify fault \r\n ;;\r\n*)\r\n echo \"Usage: $(basename $0) {master|backup|fault}\"\r\n exit 1\r\n ;;\r\nesac\r\n<\/pre>\n\u542f\u52a8keepalived\u670d\u52a1<\/strong><\/span><\/div>\n\r\n$ systemctl start keepalived\r\n$ systemctl enable keepalived\r\n<\/pre>\n\u67e5\u770b\u7ec4\u64ad\u72b6\u6001<\/strong><\/span><\/div>\n\u6211\u4eec\u8fd8\u53ef\u4ee5\u5728\u4efb\u610f\u4e00\u53f0keepalived\u8282\u70b9\uff0c\u901a\u8fc7tcpdump\u547d\u4ee4\u67e5\u770b\u7ec4\u64ad\u5fc3\u8df3\u72b6\u6001\uff0c\u4f8b\u5982\uff1a<\/p>\n \r\n$ tcpdump -nn -i eth1 host 224.0.0.111\r\ntcpdump: verbose output suppressed, use -v or -vv for full protocol decode\r\nlistening on eth1, link-type EN10MB (Ethernet), capture size 262144 bytes\r\n00:32:31.714987 IP 10.16.8.10 > 224.0.0.111: VRRPv2, Advertisement, vrid 191, prio 100, authtype simple, intvl 1s, length 20\r\n00:32:31.715739 IP 10.16.8.11 > 224.0.0.111: VRRPv2, Advertisement, vrid 192, prio 100, authtype simple, intvl 1s, length 20\r\n00:32:32.716150 IP 10.16.8.10 > 224.0.0.111: VRRPv2, Advertisement, vrid 191, prio 100, authtype simple, intvl 1s, length 20\r\n00:32:32.716292 IP 10.16.8.11 > 224.0.0.111: VRRPv2, Advertisement, vrid 192, prio 100, authtype simple, intvl 1s, length 20\r\n00:32:33.717327 IP 10.16.8.10 > 224.0.0.111: VRRPv2, Advertisement, vrid 191, prio 100, authtype simple, intvl 1s, length 20\r\n00:32:33.721361 IP 10.16.8.11 > 224.0.0.111: VRRPv2, Advertisement, vrid 192, prio 100, authtype simple, intvl 1s, length 20\r\n<\/pre>\n\u5982\u679c\u63d0\u793a\u62a5\u9519\uff1a-bash: tcpdump: command not found.<\/p>\n \u5b89\u88c5tcpdump\u5373\u53ef\uff1a<\/p>\n \r\n$ yum install tcpdump -y\r\n<\/pre>\n\u914d\u7f6eLVS<\/strong><\/span><\/div>\n\u5206\u522b\u5b89\u88c5lvs\u3002CentOS7\u5df2\u7ecf\u96c6\u6210\u4e86LVS\u7684\u6838\u5fc3\uff0c\u6240\u4ee5\u53ea\u9700\u8981\u5b89\u88c5LVS\u7684\u7ba1\u7406\u5de5\u5177\u5c31\u53ef\u4ee5\u4e86\uff1a<\/p>\n \r\n$ yum -y install ipvsadm\r\n\u5206\u522b\u505c\u6b62ka67\/ka68\u7684keepalived\u670d\u52a1\uff1a\r\n\r\n$ systemctl stop keepalived\r\n\u5206\u522b\u5728ka67\/ka68\u914d\u7f6e\u6587\u4ef6\u6700\u540e\u6dfb\u52a0Virtual Server\u914d\u7f6e\uff1a\r\n\r\n$ vim \/usr\/local\/keepalived\/etc\/keepalived\/keepalived.conf\r\nvirtual_server 10.16.8.100 80 {\r\n delay_loop 3\r\n lb_algo rr\r\n lb_kind DR\r\n protocol TCP\r\n # sorry_server 127.0.0.1 80\r\n real_server 10.16.8.8 80 {\r\n weight 1\r\n HTTP_GET {\r\n url {\r\n path \/\r\n status_code 200\r\n }\r\n connect_timeout 1\r\n nb_get_retry 3\r\n delay_before_retry 1\r\n }\r\n }\r\n real_server 10.16.8.9 80 {\r\n weight 1\r\n HTTP_GET {\r\n url {\r\n path \/\r\n status_code 200\r\n }\r\n connect_timeout 1\r\n nb_get_retry 3\r\n delay_before_retry 1\r\n }\r\n }\r\n}\r\nvirtual_server 10.16.8.101 80 {\r\n delay_loop 3\r\n lb_algo rr\r\n lb_kind DR\r\n protocol TCP\r\n # sorry_server 127.0.0.1 80\r\n real_server 10.16.8.8 80 {\r\n weight 1\r\n HTTP_GET {\r\n url {\r\n path \/\r\n status_code 200\r\n }\r\n connect_timeout 1\r\n nb_get_retry 3\r\n delay_before_retry 1\r\n }\r\n }\r\n real_server 10.16.8.9 80 {\r\n weight 1\r\n HTTP_GET {\r\n url {\r\n path \/\r\n status_code 200\r\n }\r\n connect_timeout 1\r\n nb_get_retry 3\r\n delay_before_retry 1\r\n }\r\n }\r\n}\r\n<\/pre>\n\u914d\u7f6eRS(Real Server)Web\u670d\u52a1<\/strong><\/span><\/div>\n\u5206\u522b\u5728Web\u670d\u52a1\u5668\u5b89\u88c5Apache Httpd\u6216Nginx\u4f5c\u4e3aWeb\u670d\u52a1\uff0c\u8fd9\u91cc\u5b89\u88c5Nginx\u3002<\/p>\n \u5173\u4e8eNginx\u8bf7\u53c2\u9605\uff1a\u300aCentos 7 \u6e90\u7801\u7f16\u8bd1\u5b89\u88c5 Nginx\u300b\u3002<\/p>\n \u6216\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5b89\u88c5Nginx\uff0c\u7b80\u5355\u5feb\u901f\uff1a<\/p>\n \r\n$ yum install epel-release -y\r\n$ yum install nginx -y\r\n<\/pre>\n\u6d4b\u8bd5\u73af\u5883\u4e3a\u533a\u5206\u673a\u5668\u7684\u4e0d\u540c\uff0c\u6545\u5c06\u663e\u793a\u9875\u9762\u8bbe\u7f6e\u6210\u670d\u52a1\u5668IP\u5730\u5740\uff0c\u4f46\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u83b7\u53d6\u7684\u5185\u5bb9\u662f\u4e00\u81f4\u7684\u3002<\/p>\n \u5206\u522b\u5728web8\/web9\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n \r\n$ echo \"Server 10.16.8.8\" > \/usr\/share\/nginx\/html\/index.html\r\n$ echo \"Server 10.16.8.9\" > \/usr\/share\/nginx\/html\/index.html\r\n<\/pre>\n\u6d4b\u8bd5\u662f\u5426\u8bbf\u95ee\u6b63\u5e38\uff1a<\/p>\n \r\n$ curl http:\/\/127.0.0.1\r\nServer 10.16.8.8\r\n<\/pre>\n\u6dfb\u52a0RS\u811a\u672c<\/strong><\/span><\/div>\n\u7531\u4e8e\u8be5\u811a\u672c\u90e8\u5206\u547d\u4ee4\uff0c\u5728Centos7 \u6700\u5c0f\u5316\u5b89\u88c5\u4e2d\u6ca1\u6709\uff0c\u6240\u4ee5\u8bf7\u5148\u5b89\u88c5\u7f51\u7edc\u5de5\u5177\u5305\uff1a<\/p>\n \r\n$ yum install net-tools -y\r\n\u5206\u522b\u5728web\u670d\u52a1\u5668\u4e0a\u6dfb\u52a0rs.sh\u811a\u672c\uff1a\r\n\r\n$ vim \/tmp\/rs.sh\r\n#!\/bin\/bash\r\nvip1=10.16.8.100\r\nvip2=10.16.8.101\r\ndev1=lo:1\r\ndev2=lo:2\r\ncase $1 in\r\nstart)\r\n echo 1 > \/proc\/sys\/net\/ipv4\/conf\/all\/arp_ignore\r\n echo 1 > \/proc\/sys\/net\/ipv4\/conf\/lo\/arp_ignore\r\n echo 2 > \/proc\/sys\/net\/ipv4\/conf\/all\/arp_announce\r\n echo 2 > \/proc\/sys\/net\/ipv4\/conf\/lo\/arp_announce\r\n ifconfig $dev1 $vip1 netmask 255.255.255.255 broadcast $vip1 up\r\n ifconfig $dev2 $vip2 netmask 255.255.255.255 broadcast $vip2 up\r\n echo \"VS Server is Ready!\"\r\n ;;\r\nstop)\r\n ifconfig $dev down\r\n echo 0 > \/proc\/sys\/net\/ipv4\/conf\/all\/arp_ignore\r\n echo 0 > \/proc\/sys\/net\/ipv4\/conf\/lo\/arp_ignore\r\n echo 0 > \/proc\/sys\/net\/ipv4\/conf\/all\/arp_announce\r\n echo 0 > \/proc\/sys\/net\/ipv4\/conf\/lo\/arp_announce\r\n echo \"VS Server is Cancel!\"\r\n ;;\r\n*)\r\n echo \"Usage `basename $0` start|stop\"\r\n exit 1\r\n ;;\r\nesac\r\n<\/pre>\n\u518d\u5206\u522b\u542f\u52a8\u8be5\u811a\u672c\uff1a<\/p>\n \r\n$ \/tmp\/rs.sh start\r\n\u5982\u679c\u9700\u8981\u505c\u6b62\uff0c\u8bf7\u6267\u884c\u5982\u4e0b\u547d\u4ee4\uff1a\r\n\r\n$ \/tmp\/rs.sh stop\r\n<\/pre>\n\u6d4b\u8bd5<\/strong><\/span><\/div>\n\u5728\u53e6\u4e00\u53f0\u670d\u52a1\u5668\u6d4b\u8bd5\u662f\u5426\u80fd\u591f\u8bbf\u95ee<\/p>\n \r\n[root@localhost ~]# for i in `seq 5`; do\r\n> curl 10.16.8.100\r\n> curl 10.16.8.101\r\n> done\r\nServer 10.16.8.9\r\nServer 10.16.8.8\r\nServer 10.16.8.8\r\nServer 10.16.8.9\r\nServer 10.16.8.9\r\nServer 10.16.8.8\r\nServer 10.16.8.8\r\nServer 10.16.8.9\r\nServer 10.16.8.9\r\nServer 10.16.8.8\r\n<\/pre>\n\u6839\u636e\u6d4b\u8bd5\u7ed3\u679c\u5224\u65ad\uff0c\u5df2\u7ecf\u5b9e\u73b0\u4e86Keepalived+LVS-DR+Nginx\u9ad8\u53ef\u7528\u6545\u969c\u5207\u6362\u6a21\u5f0f\u3002<\/p>\n \n\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/renwole.com\/archives\/1120<\/a><\/p>\n\u672c\u6587\u5730\u5740\uff1ahttps:\/\/lrxjmw.cn\/keepalived-lvs-dr.html<\/a>\u7f16\u8f91\uff1a\u4f55\u4e91\u8273\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"\u5bfc\u8bfb LVS\u662fLinux Virtual Server\u7684\u7b80\u5199\uff0c\u610f\u5373Linux\u865a\u62df\u670d\u52a1\u5668\uff0c\u662f\u4e00\u4e2a\u865a\u62df\u7684\u670d\u52a1\u5668\u96c6\u7fa4 […]<\/p>\n","protected":false},"author":1479,"featured_media":107801,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-107775","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/107775","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=107775"}],"version-history":[{"count":5,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/107775\/revisions"}],"predecessor-version":[{"id":293899,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/107775\/revisions\/293899"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/107801"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=107775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=107775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=107775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}} |