{"id":621,"date":"2022-09-05T23:19:51","date_gmt":"2022-09-05T15:19:51","guid":{"rendered":"https:\/\/frogvps.com\/?p=621"},"modified":"2022-09-05T23:19:52","modified_gmt":"2022-09-05T15:19:52","slug":"keepalived%e6%90%ad%e5%bb%balvs%e9%ab%98%e5%8f%af%e7%94%a8%e9%9b%86%e7%be%a4","status":"publish","type":"post","link":"https:\/\/frogvps.com\/?p=621","title":{"rendered":"Keepalived\u642d\u5efaLVS\u9ad8\u53ef\u7528\u96c6\u7fa4"},"content":{"rendered":"\n<p>Keepalived\u53ef\u4ee5\u914d\u5408LVS\u4f7f\u7528\uff0c\u89e3\u51b3LVS\u5355\u70b9\u5931\u8d25\u548c\u540e\u7aef\u670d\u52a1\u5668\u5065\u5eb7\u6027\u68c0\u6d4b\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"521\" src=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a6-1024x521.jpg\" alt=\"\" class=\"wp-image-622\" srcset=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a6-1024x521.jpg 1024w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a6-300x153.jpg 300w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a6-768x391.jpg 768w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a6.jpg 1439w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>\u865a\u62df\u673a\u67b6\u6784\u56fe<\/figcaption><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u73af\u5883\u51c6\u5907<\/h2>\n\n\n\n<p>\u5ba2\u6237\u7aef<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>eth0: \u4ec5\u4e3b\u673a 192.168.10.6\/24 GW:192.168.10.200<\/code><\/pre>\n\n\n\n<p>\u8def\u7531\u5668<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>eth0: NAT 10.0.0.200\/24<br>eth1: \u4ec5\u4e3b\u673a 192.168.10.200\/24<br>\u542f\u7528 IP_FORWARD<\/code><\/pre>\n\n\n\n<p>\u4e24\u53f0LVS+Keepalived<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Master eth0: 10.0.0.8 vip: 10.0.0.10\/32<br>Backup eth0: 10.0.0.18<\/code><\/pre>\n\n\n\n<p>\u4e24\u53f0\u540e\u7aef\u670d\u52a1\u5668<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RS1 eth0: 10.0.0.7<br>RS2 eth0: 10.0.0.17<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u670d\u52a1\u914d\u7f6e<\/h2>\n\n\n\n<p><strong>LVS-Master<\/strong><\/p>\n\n\n\n<p>\u5b89\u88c5keepalived<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yum -y install keepalived<\/code><\/pre>\n\n\n\n<p>\u5907\u4efd\u914d\u7f6e\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cp \/etc\/keepalived\/keepalived.conf{,.bak} <\/code><\/pre>\n\n\n\n<p>\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/keepalived\/keepalived.conf<\/code><\/pre>\n\n\n\n<p>keepalived.conf<\/p>\n\n\n\n<p>\u9ed8\u8ba4\u7ec4\u64adIP\uff1a224.0.0.18<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>! Configuration File for keepalived<br>\u200b<br>global_defs {<br> &nbsp; notification_email {<br> &nbsp; &nbsp; root@localhost<br> &nbsp; } &nbsp; <br> &nbsp; notification_email_from keepalived@localhost<br> &nbsp; smtp_server 127.0.0.1<br> &nbsp; smtp_connect_timeout 30<br> &nbsp; router_id ka1 <br> &nbsp; vrrp_skip_check_adv_addr<br> &nbsp; vrrp_garp_interval 0<br> &nbsp; vrrp_gna_interval 0<br>}<br>\u200b<br>vrrp_instance VI_1 {<br> &nbsp;  state MASTER<br> &nbsp;  interface eth0<br> &nbsp;  virtual_router_id 88<br> &nbsp;  priority 100 <br> &nbsp;  advert_int 1<br> &nbsp;  authentication {<br> &nbsp; &nbsp; &nbsp;  auth_type PASS<br> &nbsp; &nbsp; &nbsp;  auth_pass 1111<br> &nbsp;  } &nbsp; <br> &nbsp;  virtual_ipaddress {<br> &nbsp; &nbsp; &nbsp;  10.0.0.10 dev eth0 label eth0:0<br> &nbsp;  } &nbsp; <br>}<br>\u200b<br>virtual_server 10.0.0.10 80 {<br>  delay_loop 3<br>  lb_algo rr<br>  lb_kind DR<br>  protocol TCP <br>  real_server 10.0.0.7 80 {<br> &nbsp;  weight 1<br> &nbsp;  HTTP_GET { <br> &nbsp; &nbsp;  url {<br> &nbsp; &nbsp; &nbsp;  path \/<br> &nbsp; &nbsp; &nbsp;  status_code 200 <br> &nbsp; &nbsp;  } &nbsp; <br>  connect_timeout 1<br>  nb_get_retry 3<br>  delay_before_retry 1<br>}<br>}<br>  real_server 10.0.0.17 80 {<br> &nbsp;  weight 1<br> &nbsp;  TCP_CHECK {<br> &nbsp; &nbsp;  connect_timeout 5<br> &nbsp; &nbsp;  nb_get_retry 3<br> &nbsp; &nbsp;  delay_before_retry 3<br> &nbsp; &nbsp;  connect_port 80<br>}<br>}<br>}<\/code><\/pre>\n\n\n\n<p>\u91cd\u542fkeepalived\u670d\u52a1<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart keepalived<\/code><\/pre>\n\n\n\n<p>\u67e5\u770bLVS\u89c4\u5219\u662f\u5426\u5df2\u7ecf\u81ea\u52a8\u751f\u6210<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ipvsadm -Ln<\/code><\/pre>\n\n\n\n<p><strong>LVS-Backup<\/strong><\/p>\n\n\n\n<p>\u5b89\u88c5keeplived\u65b9\u6cd5\u540c\u4e0a<\/p>\n\n\n\n<p>\/etc\/keepalived\/keepalived.conf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>global_defs {<br> &nbsp; notification_email {<br> &nbsp;  root@localhost<br> &nbsp; } &nbsp; <br> &nbsp; notification_email_from keepalived@localhost<br> &nbsp; smtp_server 127.0.0.1<br> &nbsp; smtp_connect_timeout 30<br> &nbsp; router_id ka2<br> &nbsp; vrrp_skip_check_adv_addr<br> &nbsp; vrrp_garp_interval 0<br> &nbsp; vrrp_gna_interval 0<br>}<br>\u200b<br>vrrp_instance VI_1 {<br> &nbsp;  state BACKUP<br> &nbsp;  interface eth0<br> &nbsp;  virtual_router_id 88<br> &nbsp;  priority 80<br> &nbsp;  advert_int 1<br> &nbsp;  authentication {<br> &nbsp; &nbsp; &nbsp;  auth_type PASS<br> &nbsp; &nbsp; &nbsp;  auth_pass 1111<br> &nbsp;  } &nbsp; <br> &nbsp;  virtual_ipaddress {<br> &nbsp; &nbsp; &nbsp;  10.0.0.10 dev eth0 label eth0:0<br> &nbsp;  } &nbsp; <br>}<br>virtual_server 10.0.0.10 80 {<br>  delay_loop 3<br>  lb_algo rr<br>  lb_kind DR<br>  protocol TCP <br>  real_server 10.0.0.7 80 {<br> &nbsp;  weight 1<br> &nbsp;  HTTP_GET { <br> &nbsp; &nbsp;  url {<br> &nbsp; &nbsp; &nbsp;  path \/<br> &nbsp; &nbsp; &nbsp;  status_code 200 <br> &nbsp; &nbsp;  } &nbsp; <br>  connect_timeout 1<br>  nb_get_retry 3<br>  delay_before_retry 1<br>}<br>}<br>  real_server 10.0.0.17 80 {<br> &nbsp;  weight 1<br> &nbsp;  TCP_CHECK {<br> &nbsp; &nbsp;  connect_timeout 5<br> &nbsp; &nbsp;  nb_get_retry 3<br> &nbsp; &nbsp;  delay_before_retry 3<br> &nbsp; &nbsp;  connect_port 80<br>}<br>}<br>}<\/code><\/pre>\n\n\n\n<p>\u91cd\u542fkeepalived\u670d\u52a1<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart keepalived<\/code><\/pre>\n\n\n\n<p>\u67e5\u770bLVS\u89c4\u5219\u662f\u5426\u5df2\u7ecf\u81ea\u52a8\u751f\u6210<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ipvsadm -Ln<\/code><\/pre>\n\n\n\n<p><strong>\u540e\u7aefRS1<\/strong><\/p>\n\n\n\n<p>\u4f7f\u7528\u811a\u672c\u7ed1\u5b9aVIP\u81f3web\u670d\u52a1\u5668lo\u7f51\u5361<\/p>\n\n\n\n<p>lvs_dr_rs.sh<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash<br>#Author: qinwa<br>vip=10.0.0.10<br>mask=255.255.255.255<br>dev=lo:1<br>case $1 in<br>start)<br>echo 1 &gt; \/proc\/sys\/net\/ipv4\/conf\/all\/arp_ignore<br>echo 1 &gt; \/proc\/sys\/net\/ipv4\/conf\/lo\/arp_ignore<br>echo 2 &gt; \/proc\/sys\/net\/ipv4\/conf\/all\/arp_announce<br>echo 2 &gt; \/proc\/sys\/net\/ipv4\/conf\/lo\/arp_announce<br>ifconfig $dev $vip netmask $mask<br>echo \"The RS Server is Ready!\"<br>;;<br>stop)<br>ifconfig $dev down<br>echo 0 &gt; \/proc\/sys\/net\/ipv4\/conf\/all\/arp_ignore<br>echo 0 &gt; \/proc\/sys\/net\/ipv4\/conf\/lo\/arp_ignore<br>echo 0 &gt; \/proc\/sys\/net\/ipv4\/conf\/all\/arp_announce<br>echo 0 &gt; \/proc\/sys\/net\/ipv4\/conf\/lo\/arp_announce<br>echo \"The RS Server is Canceled!\"<br>;;<br>*)<br>echo \"Usage: $(basename $0) start|stop\"<br>exit 1<br>;;<br>esac<\/code><\/pre>\n\n\n\n<p>\u542f\u52a8\u811a\u672c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bash lvs_dr_rs.sh start<\/code><\/pre>\n\n\n\n<p>\u914d\u7f6ehttpd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yum -y install httpd<br>echo rs1 10.0.0.7 &gt;\/var\/www\/html\/index.html <br>systemctl start httpd<\/code><\/pre>\n\n\n\n<p><strong>\u540e\u7aefRS2<\/strong><\/p>\n\n\n\n<p>\u4f7f\u7528\u811a\u672c\u7ed1\u5b9aVIP\u81f3web\u670d\u52a1\u5668lo\u7f51\u5361<\/p>\n\n\n\n<p>lvs_dr_rs.sh<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash<br>#Author: qinwa<br>vip=10.0.0.10<br>mask=255.255.255.255<br>dev=lo:1<br>case $1 in<br>start)<br>echo 1 &gt; \/proc\/sys\/net\/ipv4\/conf\/all\/arp_ignore<br>echo 1 &gt; \/proc\/sys\/net\/ipv4\/conf\/lo\/arp_ignore<br>echo 2 &gt; \/proc\/sys\/net\/ipv4\/conf\/all\/arp_announce<br>echo 2 &gt; \/proc\/sys\/net\/ipv4\/conf\/lo\/arp_announce<br>ifconfig $dev $vip netmask $mask<br>echo \"The RS Server is Ready!\"<br>;;<br>stop)<br>ifconfig $dev down<br>echo 0 &gt; \/proc\/sys\/net\/ipv4\/conf\/all\/arp_ignore<br>echo 0 &gt; \/proc\/sys\/net\/ipv4\/conf\/lo\/arp_ignore<br>echo 0 &gt; \/proc\/sys\/net\/ipv4\/conf\/all\/arp_announce<br>echo 0 &gt; \/proc\/sys\/net\/ipv4\/conf\/lo\/arp_announce<br>echo \"The RS Server is Canceled!\"<br>;;<br>*)<br>echo \"Usage: $(basename $0) start|stop\"<br>exit 1<br>;;<br>esac<\/code><\/pre>\n\n\n\n<p>\u542f\u52a8\u811a\u672c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bash lvs_dr_rs.sh start<\/code><\/pre>\n\n\n\n<p>\u914d\u7f6ehttpd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yum -y install httpd<br>echo rs1 10.0.0.17 &gt;\/var\/www\/html\/index.html <br>systemctl start httpd<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u8bbf\u95ee\u6d4b\u8bd5<\/h2>\n\n\n\n<p>\u5728LVS\u7684Master\u8282\u70b9\u7528 ip -a \u53ef\u4ee5\u770b\u5230VIP\u662f\u98d8\u5728\u4e3b\u8282\u70b9\u4e0a\u7684\uff08\u56e0\u4e3a\u5b83\u7684\u4f18\u5148\u7ea7\u9ad8\uff09<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"329\" src=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a1-1024x329.jpg\" alt=\"\" class=\"wp-image-623\" srcset=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a1-1024x329.jpg 1024w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a1-300x96.jpg 300w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a1-768x247.jpg 768w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a1.jpg 1319w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>KA1<\/figcaption><\/figure>\n\n\n\n<p>\u5728\u5ba2\u6237\u7aef\u8bbf\u95eeVIP\u770b\u5230\u4e5f\u662f\u6b63\u5e38\u8f6e\u8be2\u7684<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"739\" height=\"293\" src=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a2.jpg\" alt=\"\" class=\"wp-image-624\" srcset=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a2.jpg 739w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a2-300x119.jpg 300w\" sizes=\"auto, (max-width: 739px) 100vw, 739px\" \/><figcaption>\u7528curl\u547d\u4ee4\u8bbf\u95eeVIP<\/figcaption><\/figure>\n\n\n\n<p>\u5728\u8def\u7531\u5668\u6293\u5305\u89c2\u5bdf\uff0c\u53ef\u4ee5\u770b\u5230\u4e3b\u8282\u70b9\u5728\u53d1\u901a\u544a\uff0c\u5ba3\u544a\u81ea\u5df1\u7684\u4f18\u5148\u7ea7<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tcpdump -i eth0 -nn host 224.0.0.18<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"251\" src=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a3-1024x251.jpg\" alt=\"\" class=\"wp-image-625\" srcset=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a3-1024x251.jpg 1024w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a3-300x73.jpg 300w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a3-768x188.jpg 768w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a3-1536x376.jpg 1536w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a3.jpg 1585w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u8fd9\u4e2a\u65f6\u5019\u628a\u4e3b\u8282\u70b9\uff0810.0.0.8\uff09\u7684keepalived\u670d\u52a1\u505c\u6b62\uff0c\u53ef\u4ee5\u770b\u5230\u4ece\u8282\u70b9\u628aVIP\u62a2\u8fc7\u6765\u4e86<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"182\" src=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a4-1024x182.jpg\" alt=\"\" class=\"wp-image-626\" srcset=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a4-1024x182.jpg 1024w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a4-300x53.jpg 300w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a4-768x137.jpg 768w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a4-1536x273.jpg 1536w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a4.jpg 1652w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>\u4ece\u8282\u70b9\u5f97\u5230\u4e86VIP<\/figcaption><\/figure>\n\n\n\n<p>\u518d\u8bbf\u95eeVIP\uff0c\u53ef\u4ee5\u770b\u5230\u5373\u4f7f\u6302\u6389\u4e00\u53f0LVS\u7f51\u9875\u8fd8\u662f\u80fd\u6b63\u5e38\u8bbf\u95ee\u7684\uff0c\u8fd9\u6837\u5c31\u5b9e\u73b0\u4e86\u9ad8\u53ef\u7528\u4e86\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"487\" height=\"239\" src=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a5.jpg\" alt=\"\" class=\"wp-image-629\" srcset=\"https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a5.jpg 487w, https:\/\/frogvps.com\/wp-content\/uploads\/2022\/09\/20220905a5-300x147.jpg 300w\" sizes=\"auto, (max-width: 487px) 100vw, 487px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Keepalived\u53ef\u4ee5\u914d\u5408LVS\u4f7f\u7528\uff0c\u89e3\u51b3LVS\u5355\u70b9\u5931\u8d25\u548c\u540e\u7aef\u670d\u52a1\u5668\u5065\u5eb7\u6027\u68c0\u6d4b\u7684\u95ee\u9898\u3002 \u73af\u5883\u51c6\u5907 \u5ba2\u6237\u7aef \u8def\u7531\u5668 \u4e24\u53f0LVS+Keepalived \u4e24\u53f0\u540e\u7aef\u670d\u52a1\u5668 \u670d\u52a1\u914d\u7f6e LVS-Master \u5b89\u88c5keepalived \u5907\u4efd\u914d\u7f6e\u6587\u4ef6 \u7f16&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[23,46,19,22],"topic":[],"class_list":["post-621","post","type-post","status-publish","format-standard","hentry","category-linux","tag-keepalived","tag-lvs","tag-19","tag-22"],"_links":{"self":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/621","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=621"}],"version-history":[{"count":3,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/621\/revisions"}],"predecessor-version":[{"id":630,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/621\/revisions\/630"}],"wp:attachment":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=621"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}