{"id":667,"date":"2022-03-03T17:57:12","date_gmt":"2022-03-03T09:57:12","guid":{"rendered":"https:\/\/www.buyao007.icu\/?p=667"},"modified":"2022-03-03T17:59:37","modified_gmt":"2022-03-03T09:59:37","slug":"13-keepalived%e5%ae%9e%e7%8e%b0nginx%e9%ab%98%e5%8f%af%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.buyao007.icu\/?p=667","title":{"rendered":"13.keepalived\u5b9e\u73b0nginx\u9ad8\u53ef\u7528"},"content":{"rendered":"\n<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6\u7fa4\u67b6\u6784\u4e0e\u81ea\u52a8\u5316\u8fd0\u7ef4\uff0c\u66fe\u8d1f\u8d23\u56fd\u5185\u67d0\u5927\u578b\u535a\u5ba2\u7f51\u7ad9\u8fd0\u7ef4\u5de5\u4f5c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">1.Keepalived\u9ad8\u53ef\u7528\u57fa\u672c\u6982\u8ff0<\/h2>\n\n\n\n<p><strong><em>1.\u4ec0\u4e48\u662f\u9ad8\u53ef\u7528<\/em><\/strong><\/p>\n\n\n\n<p>\u4e00\u822c\u662f\u63072\u53f0\u673a\u5668\u542f\u52a8\u7740\u76f8\u540c\u7684\u4e1a\u52a1\u7cfb\u7edf,\u5f53\u6709\u4e00\u53f0\u673a\u5668down\u673a\u4e86, \u53e6\u5916\u4e00\u53f0 \u670d\u52a1\u5668\u80fd\u5feb\u901f\u7684\u63a5\u7ba1, \u5bf9\u4e8e\u8bbf\u95ee\u7684\u7528\u6237\u662f\u65e0\u611f\u77e5\u7684\u3002<\/p>\n\n\n\n<p><strong><em>2.keepalived\u662f\u5982\u4f55\u5b9e\u73b0\u9ad8\u53ef\u7528\u7684\uff1f<\/em><\/strong><\/p>\n\n\n\n<p>keepalived\u8f6f\u4ef6\u662f\u57fa\u4e8eVRRP\u534f\u8bae\u5b9e\u73b0\u7684\u3002VRRP\u865a\u62df\u8def\u7531\u5197\u4f59\u534f\u8bae\uff0c\u4e3b\u8981\u7528 \u4e8e\u89e3\u51b3\u5355\u70b9\u6545\u969c\u95ee\u9898<\/p>\n\n\n\n<p><strong><em>3.\u9ad8\u53ef\u7528\u6838\u5fc3\u6982\u5ff5<\/em><\/strong><\/p>\n\n\n\n<p>1.\u5982\u4f55\u786e\u5b9a\u8c01\u662f\u4e3b\u8282\u70b9\u8c01\u662f\u5907\u8282\u70b9\u3002(\u6295\u7968\u9009\u4e3e\uff1f\u4f18\u5148\u7ea7\uff1f\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bbe\u7f6e)<br>2.\u5982\u679cMaster\u6545\u969c\uff0cBackup\u81ea\u52a8\u63a5\u7ba1\uff0c\u90a3Master\u6062\u590d\u540e\u4f1a\u593a\u6743\u5417\uff1f(\u62a2\u5360\u5f0f\u3001\u975e\u62a2\u5360\u5f0f)<br>3.\u5982\u679c\u4e24\u53f0\u670d\u52a1\u5668\u90fd\u8ba4\u4e3a\u81ea\u5df1\u662fMaster\u4f1a\u51fa\u73b0\u4ec0\u4e48\u95ee\u9898\uff1f (\u90fd\u8ba4\u4e3a\u5bf9\u65b9\u6302\u4e86) (\u8111\u88c2)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">2.Keepalived\u9ad8\u53ef\u7528\u5b89\u88c5\u914d\u7f6e<\/h2>\n\n\n\n<p><strong><em>1.\u5b9e\u8df5\u73af\u5883\uff0c\u914d\u7f6e\u5b9e\u73b0\u865aIP\u8f6c\u79fb<\/em><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>\u72b6\u6001<\/td><td>Ip<\/td><td>\u89d2\u8272<\/td><td>\u4e3b\u673a\u540d<\/td><\/tr><tr><td>\u8282\u70b91<\/td><td>10.0.0.5<\/td><td>Master<\/td><td>Lb01<\/td><\/tr><tr><td>\u8282\u70b92<\/td><td>10.0.0.6<\/td><td>Backup<\/td><td>Lb02<\/td><\/tr><tr><td>Vip<\/td><td>10.0.0.3<\/td><td>&nbsp;<\/td><td>&nbsp;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong><em>2.\u5728master\u4e0ebackup\u4e0a\u5206\u522b\u5b89\u88c5 keepalived\uff0c\u5e76\u8fdb\u884c\u914d\u7f6e<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@lb01 ~]# yum install keepalived -y\n&#91;root@lb02 ~]# yum install keepalived -y\n\n###<strong>lb02\u914d\u7f6e<\/strong>\n&#91;root@lb02 ~]# cat \/etc\/keepalived\/keepalived.conf \nglobal_defs {\n  router_id lb02\n}\nvrrp_instance VI_1 {\n state BACKUP\n interface eth0\n virtual_router_id 50\n priority 100\n advert_int 1\n authentication {\n auth_type PASS\n auth_pass 1111\n}\n virtual_ipaddress {\n 10.0.0.3\n}\n}\n\n<strong>#lb01\u914d\u7f6e<\/strong>\n\n&#91;root@lb01 ~]# cat \/etc\/keepalived\/keepalived.conf \nglobal_defs {\n  router_id lb01\n}\nvrrp_instance VI_1 {\n state MASTER\n interface eth0\n virtual_router_id 50\n priority 150\n advert_int 1\n authentication {\n auth_type PASS\n auth_pass 1111\n}\n virtual_ipaddress {\n 10.0.0.3\n}\n}\n\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"865\" height=\"304\" src=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-3.png\" alt=\"\" class=\"wp-image-668\" srcset=\"https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-3.png 865w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-3-300x105.png 300w, https:\/\/www.buyao007.icu\/wp-content\/uploads\/2022\/03\/image-3-768x270.png 768w\" sizes=\"(max-width: 865px) 100vw, 865px\" \/><\/figure>\n\n\n\n<p><strong><em>3.\u914d\u7f6e\u6587\u4ef6\u8be6\u89e3<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>global_defs  #\u5168\u5c40\u5b9a\u4e49\u90e8\u5206\nvrrp_instance #vrrp\u5b9e\u4f8b \u8fd9\u91cc\u9762\u914d\u7f6evip \u4e3b\/\u5907 \u4f18\u5148\u7ea7 id\u53f7\u7b49\u7b49\nvirtual_server #lvs\u4e13\u7528  keepalived for lvs \u6682\u4e0d\u4f7f\u7528\n#global_defs \u5168\u5c40\u5b9a\u4e49\u90e8\u5206\nglobal_defs {\n\trouter_id lb01  #\u6bcf\u4e2akeepalived\u8f6f\u4ef6\u540d\u5b57 \u5728\u540c\u4e00\u4e2a\u5c40\u57df\u7f51\u4e2d \u552f\u4e00\u5373\u53ef.\n}\n#vrrp\u5b9e\u4f8b\u8bbe\u7f6e\u90e8\u5206\nvrrp_instance \u5b9e\u4f8b\u540d\u5b57 {  #\u5b9e\u4f8b\u540d\u5b57 \u5728\u540c\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\u4e2d\u552f\u4e00. \u5728\u540c\u4e00\u7ec4\u4e3b\u5907\u4e4b\u95f4,\u540d\u5b57\u4e00\u81f4\nstate MASTER   # \u72b6\u6001(\u5927\u5199)   MASTER\/BACKUP\ninterface eth0   #\u6307\u5b9a\u7f51\u5361\nvirtual_router_id 51 #\u540c\u4e00\u7ec4 \u4e3b\u5907\u4e4b\u95f4 id\u4fdd\u6301\u4e00\u81f4#\u5728\u540c\u4e00\u4e2akeepalived\u914d\u7f6e\u6587\u4ef6\u4e2d \u4fdd\u6301 \u552f\u4e00\npriority 100 #\u4f18\u5148\u7ea7 \u4e3b\u5907\u4e4b\u95f4 \u5dee50\u5373\u53ef.\u4e3b 100 \u5907 50\nadvert_int 1  #advert interval \u5fc3\u8df3\u95f4\u9694\nauthentication {   #\u8ba4\u8bc1\u6a21\u5f0f \u63a8\u8350\u4f7f\u7528PASS\u7b80\u5355\u5bc6\u7801\u8ba4\u8bc1 \u5373\u53ef.\nauth_type PASS\nauth_pass 1111\n}\nvirtual_ipaddress {  #vip \u865a\u62dfip\u5730\u5740\n 10.0.0.3\/24 dev eth0 label eth0:0\n}\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">3.Keepalived\u9ad8\u53ef\u7528\u5730\u5740\u6f02\u79fb<\/h2>\n\n\n\n<p><strong><em>1.\u5728Master\u4e0a\u8fdb\u884c\u5982\u4e0b\u64cd\u4f5c<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u5148\u786e\u8ba4Master\u5b58\u5728vip\u5730\u5740\n&#91;root@lb01 ~]# ip addr |grep 10.0.0.3\ninet 10.0.0.3\/24 scope global secondary eth0\n# \u505c\u6b62Master\u4e0a\u7684keepalived, \u68c0\u6d4bvip\u5df2\u4e0d\u5b58\u5728\n&#91;root@lb01 ~]# systemctl stop keepalived\n&#91;root@lb01 ~]# ip addr |grep 10.0.0.3\n<\/code><\/pre>\n\n\n\n<p><strong><em>2.\u5728Backup\u4e0a\u8fdb\u884c\u5982\u4e0b\u64cd\u4f5c<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u4e3b\u8282\u70b9\u505c\u6b62\u540e\uff0c\u5907\u8282\u70b9\u65e0\u9700\u4efb\u4f55\u64cd\u4f5c\u53d1\u73b0\u5730\u5740\u5df2\u7ecf\u6f02\u79fb\u81f3Backup\u7aef\n&#91;root@lb02 ~]# ip addr|grep 10.0.0.3\ninet 10.0.0.3\/24 scope global secondary eth0\n<\/code><\/pre>\n\n\n\n<p><strong><em>3.\u6b64\u65f6\u91cd\u65b0\u542f\u52a8Master\u4e0a\u7684Keepalived,\u4f1a\u53d1\u73b0VIP\u88ab\u5f3a\u884c\u62a2\u5360<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@lb01 ~]# systemctl start keepalived\n&#91;root@lb01 ~]# ip addr |grep 10.0.0.3\ninet 10.0.0.3\/24 scope global secondary eth0\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">4.Keepalived\u9ad8\u53ef\u7528\u975e\u62a2\u5360\u5f0f<\/h2>\n\n\n\n<p>\u901a\u5e38master\u670d\u52a1\u6545\u969c\u540ebackup\u4f1a\u53d8\u6210master\uff0c\u4f46\u662f\u5f53master\u670d\u52a1\u53c8\u6062\u590d\u7684 \u65f6\u5019\uff0cmaster\u4f1a\u62a2\u5360VIP\uff0c\u8fd9\u6837\u5c31\u4f1a\u53d1\u751f\u4e24\u6b21\u5207\u6362\u5bf9\u4e1a\u52a1\u7e41\u5fd9\u7684\u7f51\u7ad9\u6765\u8bf4\u5e76 \u4e0d\u662f\u592a\u53cb\u597d\uff0c\u6b64\u65f6\u6211\u4eec\u53ef\u4ee5\u914d\u7f6ekeepalived\u4e3a\u975e\u62a2\u5360\u5f0f(\u524d\u63d0\u4e24\u53f0\u4e3b\u673a\u7684\u786c\u4ef6 \u914d\u7f6e\u4fe1\u606f\u4e00\u81f4)<\/p>\n\n\n\n<p>\u914d\u7f6e\u975e\u62a2\u5360\u5f0f\u6b65\u9aa4\u5982\u4e0b<br>1.\u4e24\u4e2a\u8282\u70b9\u7684state\u90fd\u5fc5\u987b\u914d\u7f6e\u4e3aBACKUP(\u5b98\u65b9\u5efa\u8bae)<br>2.\u4e24\u4e2a\u8282\u70b9\u90fd\u5728vrrp_instance\u4e2d\u6dfb\u52a0nopreempt\u53c2\u6570<br>3.\u5176\u4e2d\u4e00\u4e2a\u8282\u70b9\u7684\u4f18\u5148\u7ea7\u5fc5\u987b\u8981\u9ad8\u4e8e\u53e6\u5916\u4e00\u4e2a\u8282\u70b9\u7684\u4f18\u5148\u7ea7\u3002<\/p>\n\n\n\n<p>\u4e24\u53f0\u670d\u52a1\u5668\u90fd\u89d2\u8272\u72b6\u6001\u542f\u7528nopreempt\u540e\uff0c\u5fc5\u987b\u4fee\u6539\u89d2\u8272\u72b6\u6001\u7edf\u4e00\u4e3a BACKUP\uff0c\u552f\u4e00\u7684\u533a\u5206\u5c31\u662f\u4f18\u5148\u7ea7\u3002<br>#\u5f53\u9ad8\u4f18\u5148\u7ea7\u673a\u5668\u8054\u673a\u65f6\uff0cVRRP\u901a\u5e38\u4f1a\u62a2\u5360\u4f4e\u4f18\u5148\u7ea7\u673a\u5668\u3002<br>#\u201cnopreempt\u201d\u5141\u8bb8\u4f4e\u4f18\u5148\u7ea7\u673a\u5668\u7ef4\u62a4\u4e3b\u89d2\u8272\uff0c\u5373\u4f7f\u9ad8\u4f18\u5148\u7ea7\u673a\u5668\u91cd\u65b0\u8054\u673a\u3002<br>#\u6ce8\u610f\uff1a\u8981\u4f7f\u5176\u5de5\u4f5c\uff0c\u6b64\u9879\u7684\u521d\u59cb\u72b6\u6001\u5fc5\u987b\u662fBACKUP\u3002<\/p>\n\n\n\n<p>\u5177\u4f53\u914d\u7f6e\u53c2\u8003\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Master\nvrrp_instance VI_1 {\nstate BACKUP\npriority 150\nnopreempt###\u975e\u62a2\u5360\n}\n#Backup\nvrrp_instance VI_1 {\nstate BACKUP\npriority 150\nnopreempt###\u975e\u62a2\u5360\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">5.keepalived\u76d1\u63a7nginx \u9ad8\u53ef\u7528<\/h2>\n\n\n\n<p>keepalived \u53ea\u5728keepalived\u670d\u52a1\u5173\u95ed\u6216\u65ad\u7f51,\u670d\u52a1\u5668\u5b95\u673a,\u624d\u4f1a\u8fdb\u884c\u4e3b\u5907\u5207\u6362.\u8981\u4f7f\u7528keepalived\u76d1\u63a7\u67d0\u4e2a\u670d\u52a1,\u9700\u8981\u4e66\u5199\u76d1\u63a7\u811a\u672c,\u7136\u540ekeepalived \u5b9a\u65f6\u6267\u884c\u811a\u672c.<\/p>\n\n\n\n<p>\u76d1\u63a7\u811a\u672c\u601d\u8def:<br>1.\u68c0\u67e5nginx\u8fdb\u7a0b\/\u7aef\u53e3\u662f\u5426\u5b58\u5728<br>2.\u5982\u679c\u6ca1\u6709,\u5c31\u628akeepaliived \u5173\u95ed<\/p>\n\n\n\n<p><strong><em>1.\u4e66\u5199\u811a\u672c<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@lb01 ~]# cat   \/server\/scripts\/chk_lb.sh\n#!\/bin\/bash\nproc_cnt=`ps -C nginx --no-heading |wc -l`\nif &#91; $proc_cnt -eq 0 ];then\nsystemctl stop keepalived\nfi\n<\/code><\/pre>\n\n\n\n<p><strong><em>2.<\/em>\u6d4b<em>\u8bd5\u811a\u672c\u6267\u884c<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@lb01 ~]# systemctl is-active nginx   keepalived.service\nactive\nactive\n&#91;root@lb01 ~]# pkill nginx\n&#91;root@lb01 ~]# systemctl is-active nginx keepalived.service\nfailed\nactive\n&#91;root@lb01 ~]# sh \/server\/scripts\/chk_lb.sh\n&#91;root@lb01 ~]# systemctl is-active nginx   keepalived.service\nfailed\nfailed<\/code><\/pre>\n\n\n\n<p>\u68c0\u67e5\u811a\u672c\u5347\u7ea7: \u7ed9nginx\u4e00\u6b21\u673a\u4f1a,\u542f\u52a8\u4e00\u6b21\u770b\u770b<br>\u76d1\u63a7\u811a\u672c\u601d\u8def:<br>\u68c0\u67e5nginx\u8fdb\u7a0b\/\u7aef\u53e3\u662f\u5426\u5b58\u5728<br>1) \u5982\u679c\u4e0d\u5b58\u5728,\u5219\u91cd\u542fnginx<br>2) \u7b49\u5f852-3\u79d2<br>3) \u518d\u6b21\u68c0\u67e5nginx\u8fdb\u7a0b\/\u7aef\u53e3 \u662f\u5426\u5b58\u5728<br>a \u4ecd\u7136\u4e0d\u5b58\u5728<br>b.\u5c31\u628akeepaliived \u5173\u95ed<\/p>\n\n\n\n<p><strong><em>3.\u4e66\u5199\u5347\u7ea7\u540e\u7684\u811a\u672c<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@lb01 ~]# cat \/server\/scripts\/chk_lb-v2.sh\n#!\/bin\/bash\n#\u7b2c1\u6b21\u68c0\u67e5\u811a\u672c\u72b6\u6001\nproc_cnt=`ps -C nginx --no-heading |wc -l`\nif &#91; $proc_cnt -eq 0 ];then\nsystemctl start nginx\nsleep 3\n#\u7b49\u5f853\u79d2\u540e,\u518d\u6b21\u68c0\u67e5nginx\u72b6\u6001\n\tproc_cnt=`ps -C nginx --no-heading |wc -l`\n\tif &#91; $proc_cnt -eq 0 ];then\n\tsystemctl stop keepalived\n\tfi\nfi\n<\/code><\/pre>\n\n\n\n<p><strong><em>4.keep\u6267\u884c\u76d1\u63a7\u811a\u672c<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@lb01 script]# cat \/etc\/keepalived\/keepalived.conf\n! Configuration File for keepalived\nglobal_defs {\n  router_id lb02\n}\n\nvrrp_script chk_lb {      #&lt;==\u5b9a\u4e49vrrp\u811a\u672c\uff0c\u68c0 \u6d4bHTTP\u7aef\u53e3\nscript \"\/server\/scripts\/chk_lb.sh\" #&lt;==\u6267\u884c\u811a\u672c\uff0c\u5f53nginx \u670d\u52a1\u6709\u95ee\u9898\uff0c\u5c31\u505c\u6389keepalived\u670d\u52a1\u3002\ninterval 2          #&lt;==\u95f4\u96942\u79d2\nweight 2 ####\u6743\u91cd\uff0c\u53ef\u4ee5\u4e0d\u52a0\n}\n\nvrrp_instance VI_1 {\n state BACKUP\n interface eth0\n virtual_router_id 50\n priority 100\n advert_int 1\n authentication {\n auth_type PASS\n auth_pass 1111\n}\n virtual_ipaddress {\n 10.0.0.3\n}\n\ntrack_script {        #\u6307\u5b9avrrp\u5b9e\u4f8b\u4f7f\u7528\u7684\u76d1\u63a7\u811a\u672c\nchk_lb      #&lt;==\u89e6\u53d1\u68c0\u67e5\n}\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">6.keepalived\u9ad8\u53ef\u7528\u6545\u969c\u8111\u88c2<\/h2>\n\n\n\n<p>\u7531\u4e8e\u67d0\u4e9b\u539f\u56e0\uff0c\u5bfc\u81f4\u4e24\u53f0keepalived\u9ad8\u53ef\u7528\u670d\u52a1\u5668\u5728\u6307\u5b9a\u65f6\u95f4\u5185\uff0c\u65e0\u6cd5\u68c0\u6d4b\u5230\u5bf9\u65b9\u7684\u5fc3\u8df3\u6d88\u606f\uff0c\u5404\u81ea\u53d6\u5f97\u8d44\u6e90\u53ca\u670d\u52a1\u7684\u6240\u6709\u6743\uff0c\u800c\u6b64\u65f6\u7684\u4e24\u53f0\u9ad8\u53ef\u7528 \u670d\u52a1\u5668\u53c8\u90fd\u8fd8\u6d3b\u7740\u3002<br>1.\u670d\u52a1\u5668\u7f51\u7ebf\u677e\u52a8\u7b49\u7f51\u7edc\u6545\u969c<br>2.\u670d\u52a1\u5668\u786c\u4ef6\u6545\u969c\u53d1\u751f\u635f\u574f\u73b0\u8c61\u800c\u5d29\u6e83<br>3.\u4e3b\u5907\u90fd\u5f00\u542ffirewalld\u9632\u706b\u5899<\/p>\n\n\n\n<p>\u4f46\u662f\u8111\u88c2\u5e76\u4e0d\u5f71\u54cdweb\u670d\u52a1\u56e0\u4e3a\u662f\u65e0\u72b6\u6001\u7684\uff0c\u4f46\u662f\u6570\u636e\u5e93\u670d\u52a1\u7528keepalived\u505a\u9ad8\u53ef\u7528\u53d1\u751f\u4e86\u8111\u88c2\u4f1a\u4ea7\u751f\u5f71\u54cd<\/p>\n\n\n\n<p><strong><em>1.keepalived\u8111\u88c2\u6f14\u793a<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#lb01\u548clb02\u90fd\u5f00\u542f\u9632\u706b\u5899\n&#91;root@lb01 ~]# systemctl start firewalld\n&#91;root@lb02 ~]# systemctl start firewalld\n#lb01\u548clb02\u90fd\u653e\u884chttp\u548chttps\u534f\u8bae\uff0c\u8fd9\u662f\u4e3a\u4e86\u8ba9\u7528\u6237\u80fd\u6b63\u5e38\u8bbf\u95ee\u7f51\u7ad9\n&#91;root@lb01 ~]# firewall-cmd --add-service={http,https}\n&#91;root@lb02 ~]# firewall-cmd --add-service={http,https}\n#lb01\u548clb02\u68c0\u67e5\u662f\u5426\u6709vip\n&#91;root@lb01 ~]# ip addr |grep 10.0.0.3\ninet 10.0.0.3\/24 scope global secondary eth0\n&#91;root@lb02 ~]# ip addr |grep 10.0.0.3\ninet 10.0.0.3\/24 scope global secondary eth0<\/code><\/pre>\n\n\n\n<p><strong><em>2.\u8111\u88c2\u68c0\u67e5\u811a\u672c\u601d\u8def<\/em><\/strong><\/p>\n\n\n\n<p>1.\u68c0\u67e5\u5907\u8282\u70b9\u662f\u5426\u6709vip<br>2.\u68c0\u67e5\u5907\u8282\u70b9\u662f\u5426\u53ef\u4ee5ping\u901a \u4e3b\u8282\u70b9<br>1\u548c2\u540c\u65f6\u6210\u7acb \u8111\u88c2<\/p>\n\n\n\n<p>\u811a\u672c\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@lb02 ~]# cat   \/server\/scripts\/chk_break_brain.sh\n#!\/bin\/bash\nvip=10.0.0.3\nmaster_ip=10.0.0.5\nwhile true\ndo\nvip_cnt=`ip a |grep  $vip -w|wc -l`\n#\u4f7f\u7528ping\u68c0\u67e5\u6307\u5b9aip\u662f\u5426\u53ef\u4ee5\u8bbf\u95ee\nping -c1 -W1 $master_ip &amp;&gt;\/dev\/null\nif &#91; $? -eq 0 -a $vip_cnt 1 ] ; then\necho \u53d1\u751f\u8111\u88c2;\nelse\necho \u4e00\u5207\u6b63\u5e38\nfi\nsleep 3 \ndone\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":337,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/667"}],"collection":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=667"}],"version-history":[{"count":2,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/667\/revisions"}],"predecessor-version":[{"id":671,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/667\/revisions\/671"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/media\/337"}],"wp:attachment":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}