{"id":325,"date":"2013-08-08T16:20:09","date_gmt":"2013-08-08T16:20:09","guid":{"rendered":"89f0fd5c927d466d6ec9a21b9ac34ffa"},"modified":"2013-08-08T16:20:09","modified_gmt":"2013-08-08T16:20:09","slug":"","status":"publish","type":"post","link":"https:\/\/www.xiaobo.li\/notes\/archives\/325","title":{"rendered":"keepalived"},"content":{"rendered":"<p><strong>\u516b\u79cd\u8c03\u5ea6\u7b97\u6cd5\uff1a\u3000\u3000<\/strong><br \/>\n\u3000\u3000:rr|wrr|lc|wlc|lblc|dh|sh|<br \/>\n\u3000\u3000\u8f6e\u53eb\u8c03\u5ea6\uff08Round-Robin Scheduling\uff09 <br \/>\n\u3000\u3000\u52a0\u6743\u8f6e\u53eb\u8c03\u5ea6\uff08Weighted Round-Robin Scheduling\uff09 <br \/>\n\u3000\u3000\u6700\u5c0f\u8fde\u63a5\u8c03\u5ea6\uff08Least-Connection Scheduling\uff09 <br \/>\n\u3000\u3000\u52a0\u6743\u6700\u5c0f\u8fde\u63a5\u8c03\u5ea6\uff08Weighted Least-Connection Scheduling\uff09 <br \/>\n\u3000\u3000\u57fa\u4e8e\u5c40\u90e8\u6027\u7684\u6700\u5c11\u94fe\u63a5\uff08Locality-Based Least Connections Scheduling\uff09 <br \/>\n\u3000\u3000\u5e26\u590d\u5236\u7684\u57fa\u4e8e\u5c40\u90e8\u6027\u6700\u5c11\u94fe\u63a5\uff08Locality-Based Least Connections with Replication Scheduling\uff09 <br \/>\n\u3000\u3000\u76ee\u6807\u5730\u5740\u6563\u5217\u8c03\u5ea6\uff08Destination Hashing Scheduling\uff09 <br \/>\n\u3000\u3000\u6e90\u5730\u5740\u6563\u5217\u8c03\u5ea6\uff08Source Hashing Scheduling\uff09<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u4f7f\u7528\u9ed8\u8ba4\u7ec4\u64ad\u5730\u5740\uff1a<\/strong><\/p>\n<p>224.0.0.18<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u4e09\u79cd\u5747\u8861\u673a\u5236\uff1a<\/strong><\/p>\n<p style=\"word-wrap:break-word;font-family:'sans serif', tahoma, verdana, helvetica;margin:5px 0px;line-height:18px;\">\u3000\u3000IP\u8d1f\u8f7d\u5747\u8861\u6280\u672f\u662f\u5728\u8d1f\u8f7d\u8c03\u5ea6\u5668\u7684\u5b9e\u73b0\u6280\u672f\u4e2d\u6548\u7387\u6700\u9ad8\u7684\u3002<\/p>\n<p style=\"word-wrap:break-word;font-family:'sans serif', tahoma, verdana, helvetica;margin:5px 0px;line-height:18px;\">\u4e09\u79cd\u673a\u5236\u5206\u522b\u662f\uff1a<\/p>\n<p style=\"word-wrap:break-word;font-family:'sans serif', tahoma, verdana, helvetica;margin:5px 0px;line-height:18px;\">Virtual Server via Network Address Translation \uff08VS\/NAT\uff09\uff1a \u4e5f\u6709\u8bf4\u7aef\u53e3\u6620\u5c04\u7684\uff0c\u5176\u76ee\u6807\u662f\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\u56e0\u4e3a\u8fd9\u79cd\u6280\u672f\u5bb9\u6613\u5f62\u6210\u5355\u70b9\u6545\u969c\uff0c\u4ece\u800c\u9020\u6210\u7f51\u8def\u65e0\u6cd5\u8bbf\u95ee\uff0c\u5e76\u4e14\u5b58\u5728\u5e26\u5bbd\u74f6\u9888\u3002\u6240\u4ee5LVS\u53c8\u63d0\u4f9b\u4e86\u4e0b\u9762\u4e24\u79cd\u5b9e\u73b0\u3002<\/p>\n<p style=\"word-wrap:break-word;font-family:'sans serif', tahoma, verdana, helvetica;margin:5px 0px;line-height:18px;\">Virtual Server via IP Tunneling \uff08VS\/TUN \uff09\uff1a \u901a\u8fc7IP\u96a7\u9053\u5b9e\u73b0\u865a\u62df\u670d\u52a1\u3002<\/p>\n<p style=\"word-wrap:break-word;font-family:'sans serif', tahoma, verdana, helvetica;margin:5px 0px;line-height:18px;\">Virtual Server via Direct Routing \uff08VS\/DR\uff09 \uff1a\u76f4\u63a5\u8def\u7531\u5b9e\u73b0\u865a\u62df\u670d\u52a1\u5668\u7684\u65b9\u6cd5\uff08\u8d1f\u8f7d\u80fd\u529b\u6700\u5f3a\uff09\uff0c\u672c\u6587\u642d\u5efa\u7684\u5c31\u662fDR\u6a21\u5f0f\u3002&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>LVS<\/strong><\/p>\n<p>\u4f7f\u7528Keepalived\u505aLVS\u65f6\uff0c\u771f\u5b9e\u670d\u52a1\u5668(Real-Server)\u9700\u8981\u4e3aipvsadm\u5355\u72ec\u5199\u811a\u672c,Windows \u9700\u73af\u56de\u7f51\u7edc\u63a5\u53e3\uff0cipvsadm \u542f\u7528\u5e76\u5de5\u4f5c\u540e\uff0ckeepalived\u624d\u4f1a\u63a5\u7ba1\u63a7\u5236ipvsadm\u3002<\/p>\n<p>\u811a\u672c:<\/p>\n<pre class=\"brush:shell; toolbar: true; auto-links: true;\">#!\/bin\/bash\r\nVIP=192.168.2.130\r\n\/etc\/rc.d\/init.d\/functions\r\ncase \"$1\" in\r\nstart)\r\n       ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP\r\n       \/sbin\/route add -host $VIP dev lo:0\r\n       echo \"1\" &gt;\/proc\/sys\/net\/ipv4\/conf\/lo\/arp_ignore\r\n       echo \"2\" &gt;\/proc\/sys\/net\/ipv4\/conf\/lo\/arp_announce\r\n       echo \"1\" &gt;\/proc\/sys\/net\/ipv4\/conf\/all\/arp_ignore\r\n       echo \"2\" &gt;\/proc\/sys\/net\/ipv4\/conf\/all\/arp_announce\r\n       sysctl -p &gt;\/dev\/null 2&gt;&amp;1\r\n       echo \"RealServer Start OK\"\r\n \r\n       ;;\r\nstop)\r\n       ifconfig lo:0 down\r\n       route del $VIP &gt;\/dev\/null 2&gt;&amp;1\r\n       echo \"0\" &gt;\/proc\/sys\/net\/ipv4\/conf\/lo\/arp_ignore\r\n       echo \"0\" &gt;\/proc\/sys\/net\/ipv4\/conf\/lo\/arp_announce\r\n       echo \"0\" &gt;\/proc\/sys\/net\/ipv4\/conf\/all\/arp_ignore\r\n       echo \"0\" &gt;\/proc\/sys\/net\/ipv4\/conf\/all\/arp_announce\r\n       echo \"RealServer Stoped\"\r\n       ;;\r\n*)\r\n       echo \"Usage: $0 {start|stop}\"\r\n       exit 1\r\nesac\r\n \r\nexit 0<\/pre>\n<p>&nbsp;<\/p>\n<p>i<strong>pvsadm<\/strong><\/p>\n<p>ipvsadm -l<\/p>\n<p>ipvsadm -ln<\/p>\n<p>ipvsadm -lnc<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u53c2\u8003\uff1a<\/strong><\/p>\n<p><a href=\"http:\/\/51runaway.blog.163.com\/blog\/static\/24028688201002052854733\/\">http:\/\/51runaway.blog.163.com\/blog\/static\/24028688201002052854733\/<\/a><\/p>\n<p><a href=\"http:\/\/www.linuxso.com\/fuzai\/39863.html\">http:\/\/www.linuxso.com\/fuzai\/39863.html<\/a><\/p>\n<p>&nbsp;<\/p>\n<p><strong>vrrp_script \u914d\u7f6e<\/strong><\/p>\n<pre class=\"brush:ruby; toolbar: true; auto-links: true;\">vrrp_script chk_sshd {\r\nscript \"killall -0 sshd\" # cheaper than pidof\r\ninterval 2 # check every 2 seconds\r\nweight -4 # default prio: -4 if KO\r\n\r\n# weight -40 # if failed, decrease 40 of the priority\r\nfall 1 # require 2 failures for failures\r\nrise 1 # require 1 sucesses for ok\r\n}\r\n\r\nvrrp_script chk_haproxy {\r\nscript \"killall -0 haproxy\" # cheaper than pidof\r\ninterval 2 # check every 2 seconds\r\n}\r\n\r\nvrrp_script chk_http_port {\r\n#script \"\/tcp\/127.0.0.1\/80\" # connects and exits\r\n\r\n#script \"nc -z 127.0.0.1 80\" # connects and exits\r\n\r\nscript \"&lt;\/tcp\/127.0.0.1\/80\" # connects and exits\r\ninterval 1 # check every second\r\nweight -2 # default prio: -2 if connect fails\r\n}\r\n\r\nvrrp_script chk_https_port {\r\nscript \"\/tcp\/127.0.0.1\/443\"\r\ninterval 1\r\nweight -2\r\n}\r\n\r\nvrrp_script chk_smtp_port {\r\nscript \"\/tcp\/127.0.0.1\/25\"\r\ninterval 1\r\nweight -2\r\n}\r\n\r\nvrrp_instance VI_1 {\r\ninterface eth0\r\nstate MASTER\r\nvirtual_router_id 51\r\npriority 100\r\n\r\nvirtual_ipaddress {\r\n192.168.200.18\/25\r\n}\r\n\r\ntrack_interface {\r\neth1 weight 2 # prio = +2 if UP\r\neth2 weight -2 # prio = -2 if DOWN\r\neth3 # no weight, fault if down\r\n}\r\n\r\ntrack_script {\r\nchk_sshd # use default weight from the script\r\nchk_haproxy weight 2 # +2 if process is present\r\nchk_http_port\r\nchk_https_port\r\nchk_smtp_port\r\n}\r\n}\r\n\r\nvrrp_instance VI_2 {\r\ninterface eth1\r\nstate MASTER\r\nvirtual_router_id 52\r\npriority 100\r\n\r\nvirtual_ipaddress {\r\n192.168.201.18\/26\r\n}\r\n\r\ntrack_interface {\r\neth0 weight 2 # prio = +2 if UP\r\neth2 weight -2 # prio = -2 if DOWN\r\neth3 # no weight, fault if down\r\n}\r\n\r\ntrack_script {\r\nchk_haproxy weight 2\r\nchk_http_port\r\nchk_https_port\r\nchk_smtp_port\r\n}\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>\u4e00\u4f8b\u914d\u7f6e\uff1a<\/strong><\/p>\n<pre class=\"brush:perl; toolbar: true; auto-links: true;\">! Configuration File for keepalived\r\n\r\nglobal_defs {\r\n   notification_email {\r\n\tnotify@aooshi.org\r\n   }\r\n   notification_email_from servername@aooshi.org\r\n   smtp_server 192.168.2.111\r\n   smtp_connect_timeout 30\r\n   router_id webcache253-keepalived\r\n}\r\n\r\nvrrp_script check_http {\r\n\tscript \"&lt;\/dev\/tcp\/127.0.0.1\/80\" \r\n       interval 5\r\n        weight -10\r\n}\r\n\r\nvrrp_instance VI_158 {\r\n    state BACKUP\r\n    interface eth0\r\n    virtual_router_id 62\r\n    priority 99\r\n    advert_int 1\r\n    smtp_alert\r\n    authentication {\r\n        auth_type PASS\r\n        auth_pass webcache\r\n    }\r\n    virtual_ipaddress {\r\n        192.168.2.158 brd 192.168.2.255 label eth0:158\r\n    }\r\n\ttrack_script {\r\n\t\tcheck_http\r\n\t}\r\n}\r\n\r\nvrrp_instance VI_159 {\r\n    state MASTER\r\n    interface eth0\r\n    virtual_router_id 63\r\n    priority 100\r\n    advert_int 1\r\n    smtp_alert\r\n    authentication {\r\n        auth_type PASS\r\n        auth_pass webcache\r\n    }\r\n    virtual_ipaddress {\r\n        192.168.2.159 brd 192.168.2.255 label eth0:159\r\n    }\r\n\ttrack_script {\r\n\t\tcheck_http\r\n\t}\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p><strong>\u516b\u79cd\u8c03\u5ea6\u7b97\u6cd5\uff1a\u3000\u3000<\/strong><br \/>\n\u3000\u3000:rr|wrr|lc|wlc|lblc|dh|sh|<br \/>\n\u3000\u3000\u8f6e\u53eb\u8c03\u5ea6\uff08Round-Robin Scheduling\uff09 <br \/>\n\u3000\u3000\u52a0\u6743\u8f6e\u53eb\u8c03\u5ea6\uff08Weighted Round-Robin Scheduling\uff09 <br \/>\n\u3000\u3000\u6700\u5c0f\u8fde\u63a5\u8c03\u5ea6\uff08Least-Connection Scheduling\uff09 <br \/>\n\u3000\u3000\u52a0\u6743\u6700\u5c0f\u8fde\u63a5\u8c03\u5ea6\uff08Weighted Least-Connection Scheduling\uff09 <br \/>\n\u3000\u3000\u57fa\u4e8e\u5c40\u90e8\u6027\u7684\u6700\u5c11\u94fe\u63a5\uff08Locality-Based Least Connections Scheduling\uff09 <br \/>\n\u3000\u3000\u5e26\u590d\u5236\u7684\u57fa\u4e8e\u5c40\u90e8\u6027\u6700\u5c11\u94fe\u63a5\uff08Locality-Based ...<\/p>\n<p> <a href=\"https:\/\/www.xiaobo.li\/notes\/archives\/325\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[287],"tags":[133],"class_list":["post-325","post","type-post","status-publish","format-standard","hentry","category-linux","tag-keepalived"],"_links":{"self":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/comments?post=325"}],"version-history":[{"count":0,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/posts\/325\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/media?parent=325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/categories?post=325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xiaobo.li\/notes\/wp-json\/wp\/v2\/tags?post=325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}