{"id":246309,"date":"2022-07-15T10:49:14","date_gmt":"2022-07-15T02:49:14","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=246309"},"modified":"2022-07-04T12:48:00","modified_gmt":"2022-07-04T04:48:00","slug":"linux-lvskeepalived","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-lvskeepalived.html","title":{"rendered":"\u9ad8\u53ef\u7528\u67b6\u6784\u914d\u7f6e\uff08lvs+keepalived\uff09"},"content":{"rendered":"
\u4e00\u3001LVS+Keepalived\u00a0\u9ad8\u53ef\u7528\u7fa4\u96c6<\/strong><\/div>\n
1\u3001LVS<\/strong><\/span><\/div>\n

Linux\u865a\u62df\u670d\u52a1\u5668(Linux Virtual Server)<\/p>\n

LVS \u5b9e\u9645\u4e0a\u76f8\u5f53\u4e8e\u57fa\u4e8eIP\u5730\u5740\u7684\u865a\u62df\u5316\u5e94\u7528\uff0c \u4e3a\u57fa\u4e8eIP\u5730\u5740\u548c\u5185\u5bb9\u8bf7\u6c42\u5206\u53d1\u7684\u8d1f\u8f7d\u5747\u8861\u63d0\u51fa\u4e86\u4e00\u79cd\u9ad8\u6548\u7684\u89e3\u51b3\u65b9\u6cd5<\/p>\n

2\u3001Keepalived<\/strong><\/span><\/div>\n

1\u3001\u652f\u6301\u6545\u969c\u81ea\u52a8\u5207\u6362\uff08Failover\uff09<\/p>\n

2\u3001\u652f\u6301\u8282\u70b9\u5065\u5eb7\u72b6\u6001\u68c0\u67e5\uff08Health Checking\uff09<\/p>\n

\u5224\u65adLVS\u8d1f\u8f7d\u8c03\u5ea6\u5668\u3001\u8282\u70b9\u670d\u52a1\u5668\u7684\u53ef\u7528\u6027\uff0c\u5f53master\u4e3b\u673a\u51fa\u73b0\u6545\u969c\u53ca\u65f6\u5207\u6362\u5230backup\u8282\u70b9\u4fdd\u8bc1\u4e1a\u52a1\u6b63\u5e38\uff0c\u5f53 master \u6545\u969c\u4e3b\u673a\u6062\u590d\u540e\u5c06\u5176\u91cd\u65b0\u52a0\u5165\u7fa4\u96c6\u5e76\u4e14\u4e1a\u52a1\u91cd\u65b0\u5207\u6362\u56de master \u8282\u70b9\u3002<\/p>\n

3\u3001Keepalived\u5b9e\u73b0\u539f\u7406\u5256\u6790<\/strong><\/span><\/div>\n

1\u3001keepalived\u91c7\u7528VRRP\u70ed\u5907\u4efd\u534f\u8bae\u5b9e\u73b0Linux \u670d\u52a1\u5668\u7684\u591a\u673a\u70ed\u5907\u529f\u80fd<\/p>\n

2\u3001VRRP\uff08\u865a\u62df\u8def\u7531\u5197\u4f59\u534f\u8bae\uff09\u662f\u9488\u5bf9\u8def\u7531\u5668\u7684\u4e00\u79cd\u5907\u4efd\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n

3\u3001\u7531\u591a\u53f0\u8def\u7531\u5668\u7ec4\u6210\u4e00\u4e2a\u70ed\u5907\u4efd\u7ec4\uff0c\u901a\u8fc7\u5171\u7528\u7684\u865a\u62dfIP\u5730\u5740\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1<\/p>\n

4\u3001\u6bcf\u4e2a\u70ed\u5907\u7ec4\u5185\u540c\u65f6\u53ea\u6709\u4e00\u53f0\u4e3b\u8def\u7531\u5668\u63d0\u4f9b\u670d\u52a1\uff0c\u5176\u4ed6\u8def\u7531\u5668\u5904\u4e8e\u5197\u4f59\u72b6\u6001<\/p>\n

5\u3001\u82e5\u5f53\u524d\u5728\u7ebf\u7684\u8def\u7531\u5668\u5931\u6548\uff0c\u5219\u5176\u4ed6\u8def\u7531\u5668\u4f1a\u6839\u636e\u8bbe\u7f6e\u7684\u4f18\u5148\u7ea7\u81ea\u52a8\u63a5\u66ff\u865a\u62dfIP\u5730\u5740\uff0c\u7ee7\u7eed\u63d0\u4f9b\u670d\u52a1<\/p>\n

4\u3001\u5e38\u7528\u7684\u914d\u7f6e<\/strong><\/span><\/div>\n

router_id HA_TEST_R1:\u672c\u8def\u7531\u5668(\u670d\u52a1\u5668)\u7684\u540d\u79f0\u3001\u4e3b\u5907\u540d\u79f0\u8981\u4e0d\u4e00\u6837
\nvrrp_instance Vl_1\u2236\u5b9a\u4e49VRRP\u70ed\u5907\u5b9e\u4f8b
\nstate MASTER:\u70ed\u5907\u72b6\u6001,MASTER\u8868\u793a\u4e3b\u670d\u52a1\u5668
\ninterface ens33:\u627f\u8f7dVIP\u5730\u5740\u7684\u7269\u7406\u63a5\u53e3
\nvirtual_router_id 1 :\u865a\u62df\u8def\u7531\u5668\u7684ID\u53f7,\u6bcf\u4e2a\u70ed\u5907\u7ec4\u4fdd\u6301\u4e00\u81f4
\npriority 100:\u4f18\u5148\u7ea7,\u6570\u503c\u8d8a\u5927\u4f18\u5148\u7ea7\u8d8a\u9ad8
\nadvert_int 1:\u901a\u544a\u95f4\u9694\u79d2\u6570(\u5fc3\u8df3\u9891\u7387)
\nauth_type PASS:\u8ba4\u8bc1\u7c7b\u578b
\nauth_pass 123456:\u5bc6\u7801\u5b57\u4e32
\nvirtual_ipaddress { vip}:\u6307\u5b9a\u6f02\u79fb\u5730\u5740(VIP),\u53ef\u4ee5\u6709\u591a\u4e2a<\/p>\n

\u4e8c\u3001LVS+Keepalived \u9ad8\u53ef\u7528\u7fa4\u96c6\u7684\u90e8\u7f72<\/strong><\/div>\n

\u73af\u5883<\/p>\n

\u4e3bDR \u670d\u52a1\u5668\uff1a192.168.131.18<\/p>\n

\u5907DR \u670d\u52a1\u5668\uff1a192.168.131.19<\/p>\n

Web \u670d\u52a1\u56681\uff1a192.168.131.22<\/p>\n

Web \u670d\u52a1\u56682\uff1a192.168.131.23<\/p>\n

vip\u5730\u5740:192.168.131.100<\/p>\n

\uff08\u4e00\uff09\u3001\u914d\u7f6eKeepalived master\u670d\u52a1\u5668 \u00a0(192.168.131.18)<\/strong><\/span><\/div>\n

1. #\u5173\u95ed\u9632\u706b\u5899<\/p>\n

systemctl stop firewalld.service\r\n\r\nsetenforce 0\r\n<\/pre>\n

2. #\u5b89\u88c5\u670d\u52a1<\/p>\n

yum -y install ipvsadm keepalived\r\n<\/pre>\n

3. #\u4fee\u6539\u914d\u7f6e\u6587\u4ef6keeplived.conf<\/p>\n

cd \/etc\/keepalived\/\r\n\r\ncp keepalived.conf keepalived.conf.bak\r\n\r\nvim keepalived.conf\r\n\r\n......\r\n\r\nglobal_defs { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 #\u5b9a\u4e49\u5168\u5c40\u53c2\u6570\r\n\r\n--10\u884c--\u4fee\u6539\uff0c\u90ae\u4ef6\u670d\u52a1\u6307\u5411\u672c\u5730\r\n\r\n\u00a0 \u00a0smtp_server 127.0.0.1\r\n\r\n--12\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u670d\u52a1\u5668\uff08\u8def\u7531\u5668\uff09\u7684\u540d\u79f0\uff0c\u4e3b\u5907\u670d\u52a1\u5668\u540d\u79f0\u987b\u4e0d\u540c\uff0c\u4e3b\u4e3aLVS_01\uff0c\u5907\u4e3aLVS_02\r\n\r\n\u00a0 \u00a0router_id LVS_01\r\n\r\n}\r\n\r\nrrp_instance VI_1 { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 #\u5b9a\u4e49VRRP\u70ed\u5907\u5b9e\u4f8b\u53c2\u6570\r\n\r\n--20\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u70ed\u5907\u72b6\u6001\uff0c\u4e3b\u4e3aMASTER\uff0c\u5907\u4e3aBACKUP\r\n\r\n\u00a0 \u00a0state MASTER\r\n\r\n--21\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u627f\u8f7dvip\u5730\u5740\u7684\u7269\u7406\u63a5\u53e3\r\n\r\n\u00a0 \u00a0interface ens33\r\n\r\n--22\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u865a\u62df\u8def\u7531\u5668\u7684ID\u53f7\uff0c\u6bcf\u4e2a\u70ed\u5907\u7ec4\u4fdd\u6301\u4e00\u81f4 \u00a0\r\n\r\n\u00a0 \u00a0virtual_router_id 51\r\n\r\n--23\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u4f18\u5148\u7ea7\uff0c\u6570\u503c\u8d8a\u5927\u4f18\u5148\u7ea7\u8d8a\u9ad8\uff0c\u4e3b\u4e3a100\uff0c\u5907\u4e3a99\r\n\r\n\u00a0 \u00a0priority 100\r\n\r\n\u00a0 \u00a0advert_int 1 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u901a\u544a\u95f4\u9694\u79d2\u6570(\u5fc3\u8df3\u9891\u7387)\r\n\r\n\u00a0 \u00a0authentication { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u5b9a\u4e49\u8ba4\u8bc1\u4fe1\u606f,\u6bcf\u4e2a\u70ed\u5907\u7ec4\u4fdd\u6301\u4e00\u81f4\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0auth_type PASS \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u8ba4\u8bc1\u7c7b\u578b\r\n\r\n--27\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u9a8c\u8bc1\u5bc6\u7801\uff0c\u4e3b\u5907\u670d\u52a1\u5668\u4fdd\u6301\u4e00\u81f4\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0auth_pass 150411\r\n\r\n\u00a0 \u00a0}\r\n\r\n\u00a0 \u00a0virtual_ipaddress { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 #\u6307\u5b9a\u7fa4\u96c6vip\u5730\u5740\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0192.168.131.100\r\n\r\n\u00a0 \u00a0}\r\n\r\n}\r\n\r\n--36\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u865a\u62df\u670d\u52a1\u5668\u5730\u5740(VIP)\u3001\u7aef\u53e3\uff0c\u5b9a\u4e49\u865a\u62df\u670d\u52a1\u5668\u548cWeb\u670d\u52a1\u5668\u6c60\u53c2\u6570\r\n\r\nvirtual_server 192.168.131.100 80 {\r\n\r\n\u00a0 \u00a0delay_loop 6 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u5065\u5eb7\u68c0\u67e5\u7684\u95f4\u9694\u65f6\u95f4(\u79d2)\r\n\r\n\u00a0 \u00a0lb_algo rr \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u6307\u5b9a\u8c03\u5ea6\u7b97\u6cd5\uff0c\u8f6e\u8be2(rr)\r\n\r\n--39\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u7fa4\u96c6\u5de5\u4f5c\u6a21\u5f0f\uff0c\u76f4\u63a5\u8def\u7531(DR)\r\n\r\n\u00a0 \u00a0lb_kind DR\r\n\r\n\u00a0 \u00a0persistence_timeout 50 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u8fde\u63a5\u4fdd\u6301\u65f6\u95f4(\u79d2)\r\n\r\nprotocol TCP \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u5e94\u7528\u670d\u52a1\u91c7\u7528\u7684\u662f TCP\u534f\u8bae\r\n\r\n--43\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u7b2c\u4e00\u4e2aWeb\u8282\u70b9\u7684\u5730\u5740\u3001\u7aef\u53e3\r\n\r\n\u00a0 \u00a0real_server 192.168.131.22 80 {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0weight 1 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u8282\u70b9\u7684\u6743\u91cd\r\n\r\n--45\u884c--\u5220\u9664\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u5065\u5eb7\u68c0\u67e5\u65b9\u5f0f \u00a0 \u00a0 \u00a0 \u00a0\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0TCP_CHECK {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0connect_port 80 \u00a0 \u00a0 \u00a0 \u00a0 #\u6dfb\u52a0\u68c0\u67e5\u7684\u76ee\u6807\u7aef\u53e3\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0connect_timeout 3 \u00a0 \u00a0 \u00a0 #\u6dfb\u52a0\u8fde\u63a5\u8d85\u65f6(\u79d2)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0nb_get_retry 3 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u6dfb\u52a0\u91cd\u8bd5\u6b21\u6570\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0delay_before_retry 3 \u00a0 \u00a0#\u6dfb\u52a0\u91cd\u8bd5\u95f4\u9694\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0}\r\n\r\n\u00a0 \u00a0}\r\n\r\n\u00a0 \u00a0real_server 192.168.131.23 80 { \u00a0 \u00a0 #\u6dfb\u52a0\u7b2c\u4e8c\u4e2a Web\u8282\u70b9\u7684\u5730\u5740\u3001\u7aef\u53e3\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0weight 1\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0TCP_CHECK {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0connect_port 80\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0connect_timeout 3\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0nb_get_retry 3\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0delay_before_retry 3\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0}\r\n\r\n\u00a0 \u00a0}\r\n\r\n}\r\n\r\n##\u5220\u9664\u540e\u9762\u591a\u4f59\u7684\u914d\u7f6e##\r\n<\/pre>\n

4. #\u542f\u52a8\u670d\u52a1\u3001\u67e5\u770b\u865a\u62df\u7f51\u5361vip(\u7b49\u914d\u7f6e\u597d\u5168\u90e8\uff0c\u5f00\u542f\u6b64\u670d\u52a1)<\/p>\n

systemctl start keepalived\r\n\r\nip addr show dev ens33\r\n<\/pre>\n

5. #\u8c03\u6574proce\u54cd\u5e94\u53c2\u6570\uff0c\u5173\u95edLinux\u5185\u6838\u7684\u91cd\u5b9a\u5411\u53c2\u6570\u54cd\u5e94<\/p>\n

vim \/etc\/sysctl.conf\r\n\r\nnet.ipv4.ip_forward = 1\r\n\r\nnet.ipv4.conf.all.send_redirects = 0\r\n\r\nnet.ipv4.conf.default.send_redirects = 0\r\n\r\nnet.ipv4.conf.ens33.send_redirects = 0\r\n<\/pre>\n

6. #\u5237\u65b0\u4e00\u4e0b<\/p>\n

sysctl -p<\/pre>\n
\u914d\u7f6eipvsadm\r\n\r\n7. #\u914d\u7f6e\u8d1f\u8f7d\u5206\u914d\u7b56\u7565\uff0c\u5e76\u542f\u52a8\u670d\u52a1\r\n<\/pre>\n
ipvsadm-save >\/etc\/sysconfig\/ipvsadm\r\n\r\nsystemctl start ipvsadm.service\r\n<\/pre>\n

8. #\u6e05\u7a7aipvsadm\uff0c\u5e76\u505a\u7b56\u7565<\/p>\n

ipvsadm -C\r\n\r\nipvsadm -A -t 192.168.131.100:80 -s rr\r\n\r\nipvsadm -a -t 192.168.131.100:80 -r 192.168.131.23:80 -g\r\n\r\nipvsadm -a -t 192.168.131.100:80 -r 192.168.131.22:80 -g\r\n<\/pre>\n

9. #\u4fdd\u5b58\u8bbe\u7f6e<\/p>\n

ipvsadm\r\n\r\nipvsadm -ln\r\n\r\nipvsadm-save >\/etc\/sysconfig\/ipvsadm\r\n<\/pre>\n
\uff08\u4e8c\uff09\u3001\u914d\u7f6eKeepalived master\u670d\u52a1\u5668 (192.168.131.19) \u00a0<\/strong><\/span><\/div>\n

1. #\u5173\u95ed\u9632\u706b\u5899<\/p>\n

systemctl stop firewalld.service\r\n\r\nsetenforce 0\r\n<\/pre>\n

2. #\u5b89\u88c5\u670d\u52a1<\/p>\n

yum -y install ipvsadm keepalived\r\n<\/pre>\n

3. #\u4fee\u6539\u914d\u7f6e\u6587\u4ef6keeplived.conf<\/p>\n

cd \/etc\/keepalived\/\r\n\r\ncp keepalived.conf keepalived.conf.bak\r\n\r\nvim keepalived.conf\r\n\r\n......\r\n\r\nglobal_defs { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 #\u5b9a\u4e49\u5168\u5c40\u53c2\u6570\r\n\r\n--10\u884c--\u4fee\u6539\uff0c\u90ae\u4ef6\u670d\u52a1\u6307\u5411\u672c\u5730\r\n\r\n\u00a0 \u00a0smtp_server 127.0.0.1\r\n\r\n--12\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u670d\u52a1\u5668\uff08\u8def\u7531\u5668\uff09\u7684\u540d\u79f0\uff0c\u4e3b\u5907\u670d\u52a1\u5668\u540d\u79f0\u987b\u4e0d\u540c\uff0c\u4e3b\u4e3aLVS_01\uff0c\u5907\u4e3aLVS_02\r\n\r\n\u00a0 \u00a0router_id LVS_01\r\n\r\n}\r\n\r\nvrrp_instance VI_1 { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u5b9a\u4e49VRRP\u70ed\u5907\u5b9e\u4f8b\u53c2\u6570\r\n\r\n--20\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u70ed\u5907\u72b6\u6001\uff0c\u4e3b\u4e3aMASTER\uff0c\u5907\u4e3aBACKUP\r\n\r\n\u00a0 \u00a0state BACKUP\r\n\r\n--21\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u627f\u8f7dvip\u5730\u5740\u7684\u7269\u7406\u63a5\u53e3\r\n\r\n\u00a0 \u00a0interface ens33\r\n\r\n--22\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u865a\u62df\u8def\u7531\u5668\u7684ID\u53f7\uff0c\u6bcf\u4e2a\u70ed\u5907\u7ec4\u4fdd\u6301\u4e00\u81f4 \u00a0\r\n\r\n\u00a0 \u00a0virtual_router_id 10\r\n\r\n--23\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u4f18\u5148\u7ea7\uff0c\u6570\u503c\u8d8a\u5927\u4f18\u5148\u7ea7\u8d8a\u9ad8\uff0c\u4e3b\u4e3a100\uff0c\u5907\u4e3a99\r\n\r\n\u00a0 \u00a0priority 99\r\n\r\n\u00a0 \u00a0advert_int 1 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u901a\u544a\u95f4\u9694\u79d2\u6570(\u5fc3\u8df3\u9891\u7387)\r\n\r\n\u00a0 \u00a0authentication { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u5b9a\u4e49\u8ba4\u8bc1\u4fe1\u606f,\u6bcf\u4e2a\u70ed\u5907\u7ec4\u4fdd\u6301\u4e00\u81f4\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0auth_type PASS \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u8ba4\u8bc1\u7c7b\u578b\r\n\r\n--27\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u9a8c\u8bc1\u5bc6\u7801\uff0c\u4e3b\u5907\u670d\u52a1\u5668\u4fdd\u6301\u4e00\u81f4\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0auth_pass 150411\r\n\r\n\u00a0 \u00a0}\r\n\r\n\u00a0 \u00a0virtual_ipaddress { \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 #\u6307\u5b9a\u7fa4\u96c6vip\u5730\u5740\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0192.168.131.100\r\n\r\n\u00a0 \u00a0}\r\n\r\n}\r\n\r\n--36\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u865a\u62df\u670d\u52a1\u5668\u5730\u5740(VIP)\u3001\u7aef\u53e3\uff0c\u5b9a\u4e49\u865a\u62df\u670d\u52a1\u5668\u548cWeb\u670d\u52a1\u5668\u6c60\u53c2\u6570\r\n\r\nvirtual_server 192.168.131.100 80 {\r\n\r\n\u00a0 \u00a0delay_loop 6 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u5065\u5eb7\u68c0\u67e5\u7684\u95f4\u9694\u65f6\u95f4(\u79d2)\r\n\r\n\u00a0 \u00a0lb_algo rr \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u6307\u5b9a\u8c03\u5ea6\u7b97\u6cd5\uff0c\u8f6e\u8be2(rr)\r\n\r\n--39\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u7fa4\u96c6\u5de5\u4f5c\u6a21\u5f0f\uff0c\u76f4\u63a5\u8def\u7531(DR)\r\n\r\n\u00a0 \u00a0lb_kind DR\r\n\r\n\u00a0 \u00a0persistence_timeout 50 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u8fde\u63a5\u4fdd\u6301\u65f6\u95f4(\u79d2)\r\n\r\n\u00a0 \u00a0protocol TCP \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u5e94\u7528\u670d\u52a1\u91c7\u7528\u7684\u662f TCP\u534f\u8bae\r\n\r\n--43\u884c--\u4fee\u6539\uff0c\u6307\u5b9a\u7b2c\u4e00\u4e2aWeb\u8282\u70b9\u7684\u5730\u5740\u3001\u7aef\u53e3\r\n\r\n\u00a0 \u00a0real_server 192.168.131.22 80 {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0weight 1 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u8282\u70b9\u7684\u6743\u91cd\r\n\r\n--45\u884c--\u5220\u9664\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u5065\u5eb7\u68c0\u67e5\u65b9\u5f0f \u00a0 \u00a0 \u00a0 \u00a0\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0TCP_CHECK {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0connect_port 80 \u00a0 \u00a0 \u00a0 \u00a0 #\u6dfb\u52a0\u68c0\u67e5\u7684\u76ee\u6807\u7aef\u53e3\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0connect_timeout 3 \u00a0 \u00a0 \u00a0 #\u6dfb\u52a0\u8fde\u63a5\u8d85\u65f6(\u79d2)\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0nb_get_retry 3 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u6dfb\u52a0\u91cd\u8bd5\u6b21\u6570\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0delay_before_retry 3 \u00a0 \u00a0#\u6dfb\u52a0\u91cd\u8bd5\u95f4\u9694\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0}\r\n\r\n\u00a0 \u00a0}\r\n\r\n\u00a0 \u00a0real_server 192.168.131.23 80 { \u00a0 \u00a0 #\u6dfb\u52a0\u7b2c\u4e8c\u4e2a Web\u8282\u70b9\u7684\u5730\u5740\u3001\u7aef\u53e3\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0weight 1\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0TCP_CHECK {\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0connect_port 80\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0connect_timeout 3\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0nb_get_retry 3\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0delay_before_retry 3\r\n\r\n\u00a0 \u00a0 \u00a0 \u00a0}\r\n\r\n\u00a0 \u00a0}\r\n\r\n}\r\n\r\n##\u5220\u9664\u540e\u9762\u591a\u4f59\u7684\u914d\u7f6e##\r\n<\/pre>\n

4. #\u542f\u52a8\u670d\u52a1\u3001\u67e5\u770b\u865a\u62df\u7f51\u5361vip\uff08\u7b49\u5168\u90e8\u914d\u7f6e\uff0c\u5f00\u542f\u670d\u52a1\uff09<\/p>\n

systemctl start keepalived\r\n\r\nip addr show dev ens33\r\n<\/pre>\n

5. #\u8c03\u6574proce\u54cd\u5e94\u53c2\u6570\uff0c\u5173\u95edLinux\u5185\u6838\u7684\u91cd\u5b9a\u5411\u53c2\u6570\u54cd\u5e94<\/p>\n

vim \/etc\/sysctl.conf\r\n\r\nnet.ipv4.ip_forward = 1\r\n\r\nnet.ipv4.conf.all.send_redirects = 0\r\n\r\nnet.ipv4.conf.default.send_redirects = 0\r\n\r\nnet.ipv4.conf.ens33.send_redirects = 0\r\n<\/pre>\n

6. #\u5237\u65b0\u4e00\u4e0b<\/p>\n

sysctl -p\r\n<\/pre>\n

\u914d\u7f6eipvsadm<\/p>\n

7. #\u914d\u7f6e\u8d1f\u8f7d\u5206\u914d\u7b56\u7565\uff0c\u5e76\u542f\u52a8\u670d\u52a1<\/p>\n

ipvsadm-save >\/etc\/sysconfig\/ipvsadm\r\n\r\nsystemctl start ipvsadm.service\r\n<\/pre>\n

8. #\u6e05\u7a7aipvsadm\uff0c\u5e76\u505a\u7b56\u7565<\/p>\n

ipvsadm -C\r\n\r\nipvsadm -A -t 192.168.131.100:80 -s rr\r\n\r\nipvsadm -a -t 192.168.131.100:80 -r 192.168.131.22:80 -g\r\n\r\nipvsadm -a -t 192.168.131.100:80 -r 192.168.131.23:80 -g\r\n<\/pre>\n

9. #\u4fdd\u5b58\u8bbe\u7f6e<\/p>\n

ipvsadm\r\n\r\nipvsadm -ln\r\n\r\nipvsadm-save >\/etc\/sysconfig\/ipvsadm\r\n<\/pre>\n
\uff08\u4e09\uff09\u3001\u914d\u7f6eweb\u8282\u70b9\u670d\u52a1\u56681\uff08192.168.131.22\uff09<\/strong><\/span><\/div>\n

1. #\u5173\u95ed\u9632\u706b\u5899<\/p>\n

systemctl stop firewalld\r\n\r\nsetenforce 0\r\n<\/pre>\n

2. #\u5b89\u88c5\u5e76\u5f00\u542fhttpd\u670d\u52a1<\/p>\n

yum -y install httpd\r\n\r\nsystemctl start httpd\r\n<\/pre>\n

3. #\u914d\u7f6e\u7ad9\u70b9\u6587\u4ef6<\/p>\n

vim \/var\/www\/html\/index.html\r\n\r\ncat \/var\/www\/html\/index.html<\/pre>\n
\r\n\u8dc3\u8dc3\u5c0f\u5b9d\u8d1d\r\n\r\n<\/pre>\n

4. #\u914d\u7f6e\u865a\u62dfvip<\/p>\n

vim \/etc\/sysconfig\/network-scripts\/ifcfg-lo:0\r\n\r\nDEVICE=lo:0\r\n\r\nONBOOT=yes\r\n\r\nIPADDR=192.168.131.100\r\n\r\nNETMASK=255.255.255.255\r\n<\/pre>\n

5. #\u91cd\u542f\u7f51\u7edc\u670d\u52a1\uff0c\u5f00\u542f\u865a\u62df\u7f51\u5361<\/p>\n

systemctl restart network\r\n\r\nifup lo:0\r\n\r\nifconfig lo:0\r\n<\/pre>\n

6. #\u8bbe\u7f6e\u8def\u7531<\/p>\n

route add -host 192.168.131.100 dev lo:0\r\n\r\nroute -n\r\n<\/pre>\n

7. #\u8c03\u6574 proc \u54cd\u5e94\u53c2\u6570<\/p>\n

#\u6dfb\u52a0\u7cfb\u7edf\u53ea\u54cd\u5e94\u76ee\u7684IP\u4e3a\u672c\u5730IP\u7684ARP\u8bf7\u6c42<\/p>\n

#\u7cfb\u7edf\u4e0d\u4f7f\u7528\u539f\u5730\u5740\u6765\u8bbe\u7f6eARP\u8bf7\u6c42\u7684\u6e90\u5730\u5740\uff0c\u800c\u662f\u7269\u7406mac\u5730\u5740\u4e0a\u7684IP<\/p>\n

vim \/etc\/sysctl.conf\r\n\r\nnet.ipv4.conf.all.arp_ignore = 1\r\n\r\nnet.ipv4.conf.all.arp_announce = 2\r\n\r\nnet.ipv4.conf.lo.arp_ignore = 1\r\n\r\nnet.ipv4.conf.lo.arp_announce = 2\r\n<\/pre>\n

8. #\u5237\u65b0proc\u53c2\u6570<\/p>\n

sysctl -p\r\n<\/pre>\n
\uff08\u56db\uff09\u3001\u914d\u7f6eweb\u8282\u70b9\u670d\u52a1\u56682\uff08192.168.131.23\uff09<\/strong><\/span><\/div>\n

1. #\u5173\u95ed\u9632\u706b\u5899<\/p>\n

systemctl stop firewalld\r\n\r\nsetenforce 0\r\n<\/pre>\n

2. #\u5b89\u88c5\u5e76\u5f00\u542fhttpd\u670d\u52a1<\/p>\n

yum -y install httpd\r\n\r\nsystemctl start httpd\r\n<\/pre>\n

3. #\u914d\u7f6e\u7ad9\u70b9\u6587\u4ef6<\/p>\n

vim \/var\/www\/html\/index.html\r\n\r\ncat \/var\/www\/html\/index.html<\/pre>\n
\r\n\u8dc3\u8dc3\u5c0f\u5b9d\u8d1d\r\n\r\n<\/pre>\n

4. #\u914d\u7f6e\u865a\u62dfvip<\/p>\n

vim \/etc\/sysconfig\/network-scripts\/ifcfg-lo:0\r\n\r\nDEVICE=lo:0\r\n\r\nONBOOT=yes\r\n\r\nIPADDR=192.168.131.100\r\n\r\nNETMASK=255.255.255.255\r\n<\/pre>\n

5. #\u91cd\u542f\u7f51\u7edc\u670d\u52a1\uff0c\u5f00\u542f\u865a\u62df\u7f51\u5361<\/p>\n

systemctl restart network\r\n\r\nifup lo:0\r\n\r\nifconfig lo:0\r\n<\/pre>\n

6. #\u8bbe\u7f6e\u8def\u7531<\/p>\n

route add -host 192.168.131.100 dev lo:0\r\n\r\nroute -n\r\n<\/pre>\n

7. #\u8c03\u6574 proc \u54cd\u5e94\u53c2\u6570<\/p>\n

#\u6dfb\u52a0\u7cfb\u7edf\u53ea\u54cd\u5e94\u76ee\u7684IP\u4e3a\u672c\u5730IP\u7684ARP\u8bf7\u6c42<\/p>\n

#\u7cfb\u7edf\u4e0d\u4f7f\u7528\u539f\u5730\u5740\u6765\u8bbe\u7f6eARP\u8bf7\u6c42\u7684\u6e90\u5730\u5740\uff0c\u800c\u662f\u7269\u7406mac\u5730\u5740\u4e0a\u7684IP<\/p>\n

vim \/etc\/sysctl.conf\r\n\r\nnet.ipv4.conf.all.arp_ignore = 1\r\n\r\nnet.ipv4.conf.all.arp_announce = 2\r\n\r\nnet.ipv4.conf.lo.arp_ignore = 1\r\n\r\nnet.ipv4.conf.lo.arp_announce = 2\r\n<\/pre>\n

8. #\u5237\u65b0proc\u53c2\u6570<\/p>\n

sysctl -p\r\n<\/pre>\n
\uff08\u4e94\uff09\u3001\u6d4b\u8bd5<\/strong><\/span><\/div>\n

\u200b\u200b1\uff09\u5f53\u524d\u4f7f\u7528\u7684\u4e3a\u4e3bDR\u670d\u52a1\u5668<\/p>\n

\u9a8c\u8bc1ip a<\/p>\n

\u4e3bDR\u670d\u52a1\u5668\uff1a\u200b<\/p>\n

\"\"<\/p>\n

\u65ad\u5f00\u4e3bDR\u670d\u52a1\u5668\u7684Keepalived\u6d4b\u8bd5\uff0csystemctl stop keepalived.service
\n\"\"
\n\"\"
\n\"\"<\/p>\n","protected":false},"excerpt":{"rendered":"

Linux\u865a\u62df\u670d\u52a1\u5668(Linux Virtual Server) LVS \u5b9e\u9645\u4e0a\u76f8\u5f53\u4e8e\u57fa\u4e8eIP\u5730\u5740\u7684\u865a\u62df\u5316\u5e94\u7528 […]<\/p>\n","protected":false},"author":1469,"featured_media":246316,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-246309","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\/246309","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\/1469"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=246309"}],"version-history":[{"count":9,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/246309\/revisions"}],"predecessor-version":[{"id":247100,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/246309\/revisions\/247100"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/246316"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=246309"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=246309"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=246309"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}