{"id":120224,"date":"2026-10-31T08:24:59","date_gmt":"2026-10-31T00:24:59","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/120224.html"},"modified":"2026-10-31T08:24:59","modified_gmt":"2026-10-31T00:24:59","slug":"%e7%94%9f%e4%ba%a7%e5%ae%9e%e6%88%98%ef%bc%9akeepalived-nginx-mysql-%e5%8f%8c%e5%90%91%e5%a4%8d%e5%88%b6%e9%ab%98%e5%8f%af%e7%94%a8%e6%9e%b6%e6%9e%84%e9%83%a8%e7%bd%b2%e4%b8%8e%e5%8e%9f%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/120224.html","title":{"rendered":"\u751f\u4ea7\u5b9e\u6218\uff1aKeepalived + Nginx + MySQL \u53cc\u5411\u590d\u5236\u9ad8\u53ef\u7528\u67b6\u6784\u90e8\u7f72\u4e0e\u539f\u7406\u8be6\u89e3"},"content":{"rendered":"<p class=\"img-center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031002456-6ae53558ce35a.png\" \/><\/p>\n<h3 style=\"background-color:transparent\">\u524d\u8a00<\/h3>\n<p>\u5728\u751f\u4ea7\u73af\u5883\u4e2d&#xff0c;\u4e3a\u4e86\u907f\u514d\u6570\u636e\u5e93\u8bbf\u95ee\u5165\u53e3\u51fa\u73b0\u5355\u70b9\u6545\u969c&#xff0c;\u5e38\u91c7\u7528 Keepalived &#043; \u53cc Nginx &#043; MySQL \u53cc\u5411\u590d\u5236 \u7684\u67b6\u6784\u3002<\/p>\n<p>\u6574\u5957\u67b6\u6784\u5b9e\u9645\u4e0a\u5206\u4e3a\u4e09\u5c42&#xff1a;<\/p>\n<ul>\n<li>\n<p>Keepalived&#xff1a; \u8d1f\u8d23 Nginx \u4ee3\u7406\u5165\u53e3\u7684\u9ad8\u53ef\u7528&#xff0c;\u63a7\u5236 VIP \u5f52\u5c5e\u3002<\/p>\n<\/li>\n<li>\n<p>Nginx&#xff1a; \u8d1f\u8d23 MySQL \u7684 TCP \u8fde\u63a5\u8f6c\u53d1&#xff0c;\u6307\u5b9a\u9996\u9009\u548c\u5907\u7528\u6570\u636e\u5e93\u3002<\/p>\n<\/li>\n<li>\n<p>MySQL&#xff1a; \u8d1f\u8d23\u6570\u636e\u5b58\u50a8\u548c\u53cc\u5411\u590d\u5236\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u672c\u6587\u5c06\u7ed3\u5408\u5b9e\u9645\u90e8\u7f72\u7ecf\u9a8c&#xff0c;\u8be6\u7ec6\u4ecb\u7ecd\u7ec4\u4ef6\u4e4b\u95f4\u7684\u5de5\u4f5c\u673a\u5236\u3001\u4e09\u4e2a\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\u3001\u6545\u969c\u5207\u6362\u8fc7\u7a0b&#xff0c;\u4ee5\u53ca\u751f\u4ea7\u73af\u5883\u53ef\u80fd\u5b58\u5728\u7684\u98ce\u9669\u3002<\/p>\n<p>\u5b89\u5168\u8bf4\u660e&#xff1a; \u6240\u6709\u670d\u52a1\u5668 IP \u5747\u4f7f\u7528 192.0.2.0\/24 \u6587\u6863\u4e13\u7528\u5730\u5740\u6bb5&#xff0c;\u8ba4\u8bc1\u4fe1\u606f\u4f7f\u7528\u793a\u4f8b\u503c&#xff0c;\u4e0d\u5305\u542b\u771f\u5b9e\u751f\u4ea7\u73af\u5883 IP \u548c\u5bc6\u7801\u3002<\/p>\n<hr \/>\n<h3>\u4e00\u3001\u6574\u4f53\u67b6\u6784\u8bbe\u8ba1<\/h3>\n<h4>1.1 \u670d\u52a1\u5668\u89c4\u5212<\/h4>\n<table>\n<tbody>\n<tr>\u89d2\u8272\u793a\u4f8b IP\u8f6f\u4ef6 \/ \u529f\u80fd<\/tr>\n<tr>\n<td>\u4ee3\u7406\u8282\u70b9 01<\/td>\n<td>192.0.2.101<\/td>\n<td>Nginx &#043; Keepalived<\/td>\n<\/tr>\n<tr>\n<td>\u4ee3\u7406\u8282\u70b9 02<\/td>\n<td>192.0.2.102<\/td>\n<td>Nginx &#043; Keepalived<\/td>\n<\/tr>\n<tr>\n<td>\u7edf\u4e00\u5165\u53e3 VIP<\/td>\n<td>192.0.2.100<\/td>\n<td>Keepalived \u7ba1\u7406<\/td>\n<\/tr>\n<tr>\n<td>\u6570\u636e\u5e93\u8282\u70b9 01<\/td>\n<td>192.0.2.103<\/td>\n<td>MySQL&#xff0c;\u9996\u9009\u540e\u7aef<\/td>\n<\/tr>\n<tr>\n<td>\u6570\u636e\u5e93\u8282\u70b9 02<\/td>\n<td>192.0.2.104<\/td>\n<td>MySQL&#xff0c;\u5907\u7528\u540e\u7aef<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u672c\u7bc7\u901a\u7528\u90e8\u7f72\u793a\u4f8b\u7edf\u4e00\u4f7f\u7528&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5e94\u7528\u8bbf\u95ee Nginx&#xff1a;13306<\/p>\n<\/li>\n<li>\n<p>Nginx \u8bbf\u95ee MySQL&#xff1a;3306<\/p>\n<\/li>\n<\/ul>\n<p>\u6ce8\u610f\u7aef\u53e3\u5dee\u5f02&#xff1a; \u539f\u59cb\u73af\u5883\u7684 Nginx \u914d\u7f6e\u628a\u4e24\u4e2a\u6570\u636e\u5e93\u540e\u7aef\u4e5f\u5199\u6210\u4e86 13306&#xff0c;\u8bf4\u660e\u5b9e\u9645 TCP \u76ee\u6807\u7aef\u53e3\u5e76\u975e\u9ed8\u8ba4\u7684 3306\u3002\u8fd9\u53ef\u80fd\u662f MySQL \u81ea\u5b9a\u4e49\u76d1\u542c\u7aef\u53e3&#xff0c;\u4e5f\u53ef\u80fd\u662f\u53e6\u4e00\u5c42\u6570\u636e\u5e93\u4ee3\u7406\u6216\u7aef\u53e3\u6620\u5c04&#xff0c;\u4e0d\u80fd\u4ec5\u51ed Nginx \u914d\u7f6e\u786e\u5b9a\u3002\u672c\u6587\u4e3a\u4e86\u65b9\u4fbf\u65b0\u73af\u5883\u90e8\u7f72&#xff0c;\u4f7f\u7528\u540e\u7aef 3306 \u7684\u6807\u51c6\u793a\u4f8b\u3002\u5b9e\u9645\u90e8\u7f72\u5fc5\u987b\u4ee5\u6570\u636e\u5e93\u771f\u5b9e\u76d1\u542c\u7aef\u53e3\u4e3a\u51c6\u3002<\/p>\n<h4>1.2 \u6574\u4f53\u67b6\u6784\u62d3\u6251<\/h4>\n<p>\u4ee5\u4e0b\u4ee5 VIP \u5f53\u524d\u4f4d\u4e8e Nginx \u8282\u70b9 02 \u4e3a\u4f8b&#xff1a;<\/p>\n<p>                   &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n                   |  Application \/ APP   |<br \/>\n                   &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n                              |<br \/>\n                              v<br \/>\n                  VIP: 192.0.2.100:13306<br \/>\n                              |<br \/>\n                              v<br \/>\n                    Keepalived \/ VRRP<br \/>\n                              |<br \/>\n               &#043;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;&#8212;&#8212;&#8211;&#043;<br \/>\n               |                             |<br \/>\n               |                             |<br \/>\n       &#043;&#8212;&#8212;-v&#8212;&#8212;&#8211;&#043;           &#043;&#8212;&#8212;&#8211;v&#8212;&#8212;-&#043;<br \/>\n       |  Nginx Node-01 |           | Nginx Node-02  |<br \/>\n       |  192.0.2.101   |           | 192.0.2.102    |<br \/>\n       |  BACKUP        |           | MASTER         |<br \/>\n       |  No VIP        |           | VIP Owner      |<br \/>\n       &#043;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;           &#043;&#8212;&#8212;&#8211;&#043;&#8212;&#8212;-&#043;<br \/>\n                                             |<br \/>\n                                             v<br \/>\n                                   Nginx Stream :13306<br \/>\n                                             |<br \/>\n                               &#043;&#8212;&#8212;&#8212;&#8212;-&#043;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n                               |                           |<br \/>\n                               v                           v<br \/>\n                      &#043;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;          &#043;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n                      |    MySQL 01    |          |    MySQL 02    |<br \/>\n                      | 192.0.2.103    |          | 192.0.2.104    |<br \/>\n                      | Port: 3306     |          | Port: 3306     |<br \/>\n                      | PRIMARY TARGET |          | BACKUP TARGET  |<br \/>\n                      &#043;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;          &#043;&#8212;&#8212;&#8212;&#8212;&#8212;-&#043;<br \/>\n                               ^                           ^<br \/>\n                               |                           |<br \/>\n                               &#043;&#8212;&#8212; Replication &#8212;&#8212;&#8211;&#043; <\/p>\n<p>\u62d3\u6251\u89e3\u91ca&#xff1a;<\/p>\n<li>\n<p>\u5e94\u7528\u7edf\u4e00\u8fde\u63a5 192.0.2.100:13306\u3002<\/p>\n<\/li>\n<li>\n<p>Keepalived \u51b3\u5b9a VIP \u5f53\u524d\u5f52\u5c5e\u54ea\u4e2a Nginx \u8282\u70b9\u3002<\/p>\n<\/li>\n<li>\n<p>\u6301\u6709 VIP \u7684 Nginx \u63a5\u6536\u6570\u636e\u5e93 TCP \u8fde\u63a5\u3002<\/p>\n<\/li>\n<li>\n<p>Nginx \u6b63\u5e38\u60c5\u51b5\u4e0b\u4f18\u5148\u8fde\u63a5 MySQL 01\u3002<\/p>\n<\/li>\n<li>\n<p>\u9996\u9009\u6570\u636e\u5e93\u51fa\u73b0\u7b26\u5408\u6761\u4ef6\u7684 TCP \u5efa\u8fde\u6545\u969c\u65f6&#xff0c;Nginx \u53ef\u4ee5\u5c1d\u8bd5 MySQL 02\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e24\u53f0 MySQL \u901a\u8fc7\u53cc\u5411\u590d\u5236\u540c\u6b65\u6570\u636e\u3002<\/p>\n<\/li>\n<p>\u56fe\u4e2d\u7684 MASTER\/BACKUP \u6307\u7684\u662f Keepalived \u7684 VRRP \u89d2\u8272&#xff1b;PRIMARY TARGET\/BACKUP TARGET \u6307\u7684\u662f Nginx \u7684\u4ee3\u7406\u8def\u7531\u89d2\u8272&#xff0c;\u5e76\u4e0d\u81ea\u52a8\u7b49\u540c\u4e8e MySQL \u7684\u6570\u636e\u5e93\u4e3b\u4ece\u8eab\u4efd\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u4e3a\u4ec0\u4e48\u9700\u8981 Keepalived&#xff1f;<\/h3>\n<h4>2.1 \u5355\u53f0 Nginx \u7684\u95ee\u9898<\/h4>\n<p>\u5047\u8bbe\u53ea\u6709\u4e00\u53f0 Nginx&#xff1a;<\/p>\n<p>          Application<br \/>\n               |<br \/>\n               v<br \/>\n      Nginx 192.0.2.101<br \/>\n               |<br \/>\n               v<br \/>\n           MySQL Group<br \/>\n               |<br \/>\n        &#043;&#8212;&#8212;&#043;&#8212;&#8212;&#043;<br \/>\n        |             |<br \/>\n     MySQL 01      MySQL 02 <\/p>\n<p>\u8fd9\u79cd\u67b6\u6784\u53ef\u4ee5\u5b9e\u73b0 MySQL TCP \u8fde\u63a5\u7684\u9996\u9009\u548c\u5907\u7528\u8f6c\u53d1\u3002<\/p>\n<p>\u4f46\u5982\u679c Nginx \u6240\u5728\u670d\u52a1\u5668\u6545\u969c&#xff0c;\u5373\u4f7f\u4e24\u53f0 MySQL \u90fd\u6b63\u5e38&#xff0c;\u5e94\u7528\u4ecd\u53ef\u80fd\u65e0\u6cd5\u8fde\u63a5\u6570\u636e\u5e93\u3002<\/p>\n<p>\u56e0\u6b64&#xff0c;\u5355\u53f0 Nginx \u5b58\u5728\u4ee3\u7406\u5165\u53e3\u5355\u70b9\u6545\u969c\u3002<\/p>\n<h4>2.2 \u53cc Nginx &#043; Keepalived \u7684\u6539\u8fdb<\/h4>\n<p>\u90e8\u7f72\u4e24\u53f0 Nginx&#xff0c;\u5e76\u901a\u8fc7 Keepalived \u7ba1\u7406 VIP\u3002<\/p>\n<p>\u6b63\u5e38\u60c5\u51b5\u4e0b\u53ea\u6709\u4e00\u4e2a\u8282\u70b9\u6301\u6709 VIP&#xff0c;\u53e6\u4e00\u4e2a\u8282\u70b9\u7b49\u5f85\u63a5\u7ba1\u3002<\/p>\n<p>\u5f53\u6301\u6709 VIP \u7684\u670d\u52a1\u5668\u505c\u6b62\u6b63\u5e38\u53c2\u4e0e VRRP \u65f6&#xff0c;\u5907\u7528\u8282\u70b9\u53ef\u4ee5\u901a\u8fc7\u9009\u4e3e\u63a5\u7ba1 VIP\u3002<\/p>\n<h4>2.3 VIP \u6545\u969c\u6f02\u79fb\u793a\u610f\u56fe<\/h4>\n<p>\u6b63\u5e38\u72b6\u6001&#xff1a;<\/p>\n<p>APP<br \/>\n |<br \/>\n v<br \/>\nVIP 192.0.2.100<br \/>\n |<br \/>\n v<br \/>\nNginx-02 (MASTER)<br \/>\n |<br \/>\n v<br \/>\nMySQL-01 (Primary Target)<\/p>\n<p>Nginx-01 &#061; BACKUP \/ No VIP <\/p>\n<p>\u4ee3\u7406\u8282\u70b9 02 \u6545\u969c\u540e&#xff1a;<\/p>\n<p>APP<br \/>\n |<br \/>\n v<br \/>\nVIP 192.0.2.100<br \/>\n |<br \/>\n v<br \/>\nNginx-01 (NEW MASTER)<br \/>\n |<br \/>\n v<br \/>\nMySQL-01 (Primary Target)<\/p>\n<p>Nginx-02 &#061; DOWN <\/p>\n<p>\u53ef\u4ee5\u770b\u5230&#xff1a;<\/p>\n<ul>\n<li>\n<p>VIP \u5730\u5740\u6ca1\u6709\u53d8\u5316\u3002<\/p>\n<\/li>\n<li>\n<p>\u5e94\u7528\u65e0\u9700\u4fee\u6539\u6570\u636e\u5e93\u8fde\u63a5\u5730\u5740\u3002<\/p>\n<\/li>\n<li>\n<p>\u5904\u7406\u65b0\u8fde\u63a5\u7684 Nginx \u8282\u70b9\u53d1\u751f\u53d8\u5316\u3002<\/p>\n<\/li>\n<li>\n<p>MySQL \u7684\u9996\u9009\u540e\u7aef\u4e0d\u56e0 VIP \u6f02\u79fb\u800c\u81ea\u52a8\u6539\u53d8\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5df2\u6709 TCP \u8fde\u63a5\u53ef\u80fd\u4e2d\u65ad&#xff0c;\u9700\u8981\u7531\u5e94\u7528\u8fde\u63a5\u6c60\u91cd\u65b0\u5efa\u7acb\u8fde\u63a5\u3002<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u4e09\u4e2a\u6700\u6838\u5fc3\u7684\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u4ee3\u7406\u5c42\u6838\u5fc3\u914d\u7f6e\u53ea\u6709\u4e09\u4e2a&#xff1a;<\/p>\n<table>\n<tbody>\n<tr>\u6587\u4ef6\u4f5c\u7528<\/tr>\n<tr>\n<td>\/etc\/keepalived\/keepalived.conf<\/td>\n<td>\u63a7\u5236 VIP \u5f52\u5c5e\u4e0e VRRP \u9009\u4e3e<\/td>\n<\/tr>\n<tr>\n<td>\/app\/nginx1.20\/conf\/nginx.conf<\/td>\n<td>Nginx \u4e3b\u914d\u7f6e&#xff0c;\u52a0\u8f7d Stream \u6a21\u5757\u914d\u7f6e<\/td>\n<\/tr>\n<tr>\n<td>\/app\/nginx1.20\/conf\/tcp.d\/mysql-tcp-13306.conf<\/td>\n<td>\u6570\u636e\u5e93 TCP \u8f6c\u53d1\u4e0e\u4e3b\u5907\u540e\u7aef\u9009\u62e9<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e24\u4e2a Nginx \u8282\u70b9\u5747\u9700\u8981\u8fd9\u4e09\u4e2a\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<p>\u5176\u4e2d Keepalived \u7684\u8282\u70b9\u5730\u5740\u4e0e\u4f18\u5148\u7ea7\u4e0d\u540c&#xff0c;Nginx \u7684\u4ee3\u7406\u914d\u7f6e\u901a\u5e38\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<hr \/>\n<h3>\u56db\u3001Keepalived \u914d\u7f6e\u8be6\u89e3<\/h3>\n<h4>4.1 \u8282\u70b9 01 \u914d\u7f6e<\/h4>\n<p>\u6587\u4ef6&#xff1a;<\/p>\n<p>\/etc\/keepalived\/keepalived.conf<\/p>\n<p>global_defs {<br \/>\n    router_id proxy-node-01<br \/>\n}<\/p>\n<p>vrrp_instance VI_1 {<br \/>\n    state BACKUP<br \/>\n    interface ens192<br \/>\n    virtual_router_id 42<br \/>\n    priority 100<\/p>\n<p>    nopreempt<\/p>\n<p>    unicast_src_ip 192.0.2.101<br \/>\n    unicast_peer {<br \/>\n        192.0.2.102<br \/>\n    }<\/p>\n<p>    advert_int 1<\/p>\n<p>    authentication {<br \/>\n        auth_type PASS<br \/>\n        auth_pass DEMOPASS<br \/>\n    }<\/p>\n<p>    virtual_ipaddress {<br \/>\n        192.0.2.100\/24<br \/>\n    }<br \/>\n} <\/p>\n<h4>4.2 \u8282\u70b9 02 \u914d\u7f6e<\/h4>\n<p>global_defs {<br \/>\n    router_id proxy-node-02<br \/>\n}<\/p>\n<p>vrrp_instance VI_1 {<br \/>\n    state BACKUP<br \/>\n    interface ens192<br \/>\n    virtual_router_id 42<br \/>\n    priority 99<\/p>\n<p>    nopreempt<\/p>\n<p>    unicast_src_ip 192.0.2.102<br \/>\n    unicast_peer {<br \/>\n        192.0.2.101<br \/>\n    }<\/p>\n<p>    advert_int 1<\/p>\n<p>    authentication {<br \/>\n        auth_type PASS<br \/>\n        auth_pass DEMOPASS<br \/>\n    }<\/p>\n<p>    virtual_ipaddress {<br \/>\n        192.0.2.100\/24<br \/>\n    }<br \/>\n} <\/p>\n<p>DEMOPASS \u662f\u6f14\u793a\u503c&#xff0c;\u90e8\u7f72\u65f6\u9700\u66ff\u6362\u4e3a\u7b26\u5408\u73af\u5883\u8981\u6c42\u7684\u8ba4\u8bc1\u914d\u7f6e\u3002VRRP PASS \u8ba4\u8bc1\u4e0d\u662f\u5f3a\u52a0\u5bc6\u8ba4\u8bc1&#xff0c;\u4ecd\u9700\u505a\u597d\u7f51\u7edc\u9694\u79bb\u4e0e\u8bbf\u95ee\u63a7\u5236\u3002<\/p>\n<h4>4.3 \u6838\u5fc3\u53c2\u6570\u89e3\u91ca<\/h4>\n<table>\n<tbody>\n<tr>\u53c2\u6570\u8bf4\u660e<\/tr>\n<tr>\n<td>state BACKUP<\/td>\n<td>\u8282\u70b9\u542f\u52a8\u65f6\u8fdb\u5165 BACKUP \u521d\u59cb\u72b6\u6001<\/td>\n<\/tr>\n<tr>\n<td>interface ens192<\/td>\n<td>VIP \u6240\u7ed1\u5b9a\u7684\u7f51\u5361<\/td>\n<\/tr>\n<tr>\n<td>virtual_router_id 42<\/td>\n<td>VRRP \u5b9e\u4f8b\u6807\u8bc6&#xff0c;\u4e24\u8282\u70b9\u4fdd\u6301\u4e00\u81f4<\/td>\n<\/tr>\n<tr>\n<td>priority 100\/99<\/td>\n<td>\u8282\u70b9\u4f18\u5148\u7ea7<\/td>\n<\/tr>\n<tr>\n<td>nopreempt<\/td>\n<td>\u7981\u6b62\u4f18\u5148\u7ea7\u9ad8\u7684\u8282\u70b9\u4e3b\u52a8\u62a2\u5360\u6b63\u5e38 MASTER<\/td>\n<\/tr>\n<tr>\n<td>unicast_src_ip<\/td>\n<td>\u672c\u673a VRRP \u901a\u4fe1\u6e90 IP<\/td>\n<\/tr>\n<tr>\n<td>unicast_peer<\/td>\n<td>\u5bf9\u7aef Keepalived \u5730\u5740<\/td>\n<\/tr>\n<tr>\n<td>advert_int 1<\/td>\n<td>VRRP \u901a\u544a\u95f4\u9694\u7ea6\u4e3a 1 \u79d2<\/td>\n<\/tr>\n<tr>\n<td>virtual_ipaddress<\/td>\n<td>\u914d\u7f6e\u9700\u8981\u6f02\u79fb\u7684 VIP<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>router_id \u662f\u5b9e\u4f8b\u6807\u8bc6&#xff0c;\u5e76\u4e0d\u662f VIP \u9009\u4e3e\u4f7f\u7528\u7684 virtual_router_id\u3002<\/p>\n<h4>4.4 Keepalived \u5982\u4f55\u5224\u65ad VIP \u4f55\u65f6\u6f02\u79fb&#xff1f;<\/h4>\n<p>Keepalived \u4e3b\u8981\u4f9d\u9760 VRRP \u901a\u544a\u5224\u65ad\u5f53\u524d MASTER \u662f\u5426\u4ecd\u6b63\u5e38\u53c2\u4e0e\u9009\u4e3e\u3002<\/p>\n<p>\u6b63\u5e38\u60c5\u51b5\u4e0b&#xff1a;<\/p>\n<p>Nginx-02 \/ MASTER<br \/>\n        |<br \/>\n        | VRRP advertisement<br \/>\n        | approximately every 1s<br \/>\n        v<br \/>\nNginx-01 \/ BACKUP <\/p>\n<p>\u5982\u679c BACKUP \u6301\u7eed\u6536\u4e0d\u5230\u6709\u6548\u7684 MASTER \u901a\u544a&#xff0c;\u6ee1\u8db3\u8d85\u65f6\u6761\u4ef6\u540e&#xff0c;\u5c31\u4f1a\u5c1d\u8bd5\u63a5\u7ba1 VIP\u3002<\/p>\n<p>\u4ee5 advert_int&#061;1\u3001BACKUP \u4f18\u5148\u7ea7 100 \u4e3a\u4f8b&#xff0c;\u6807\u51c6 VRRP \u4e3b\u8282\u70b9\u5931\u8054\u8d85\u65f6\u7406\u8bba\u503c\u7ea6\u4e3a&#xff1a;<\/p>\n<p>[ 3&#043;\\\\frac{256-100}{256}\\\\approx3.61\\\\text{\u79d2} ]<\/p>\n<p>\u5b9e\u9645\u4e1a\u52a1\u6062\u590d\u65f6\u95f4\u8fd8\u53d6\u51b3\u4e8e\u7f51\u7edc\u90bb\u5c45\u8868\u66f4\u65b0\u3001\u5e94\u7528\u91cd\u8fde\u7b49\u56e0\u7d20\u3002<\/p>\n<h4>4.5 \u4e3a\u4ec0\u4e48 priority&#061;100 \u7684\u8282\u70b9\u53ef\u80fd\u6ca1\u6709 VIP&#xff1f;<\/h4>\n<p>\u56e0\u4e3a\u542f\u7528\u4e86&#xff1a;<\/p>\n<p>nopreempt <\/p>\n<p>\u8fd9\u610f\u5473\u7740\u5f53\u4f18\u5148\u7ea7\u4e3a 99 \u7684\u8282\u70b9\u5df2\u7ecf\u6b63\u5e38\u6210\u4e3a MASTER \u65f6&#xff0c;\u4f18\u5148\u7ea7\u4e3a 100 \u7684\u8282\u70b9\u4e0d\u4f1a\u4ec5\u56e0\u4e3a\u4f18\u5148\u7ea7\u66f4\u9ad8\u5c31\u4e3b\u52a8\u62a2\u5360\u5b83\u3002<\/p>\n<p>\u4f46 nopreempt \u5e76\u4e0d\u610f\u5473\u7740\u6c38\u8fdc\u4e0d\u4f1a\u8fdb\u884c\u6545\u969c\u63a5\u7ba1\u3002<\/p>\n<h4>4.6 Keepalived \u662f\u5426\u76d1\u63a7 Nginx&#xff1f;<\/h4>\n<p>\u8fd9\u91cc\u5fc5\u987b\u91cd\u70b9\u8bf4\u660e&#xff1a;<\/p>\n<p>\u672c\u6587\u53c2\u8003\u7684\u539f\u59cb\u67b6\u6784\u4e2d&#xff0c;\u6ca1\u6709\u914d\u7f6e Nginx \u5065\u5eb7\u68c0\u67e5\u811a\u672c\u3002<\/p>\n<p>\u56e0\u6b64&#xff1a;<\/p>\n<ul>\n<li>\n<p>Nginx \u6240\u5728\u670d\u52a1\u5668\u5b95\u673a&#xff1a;\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7 VRRP \u8d85\u65f6\u89e6\u53d1\u63a5\u7ba1\u3002<\/p>\n<\/li>\n<li>\n<p>Keepalived \u505c\u6b62\u6b63\u5e38\u53c2\u4e0e VRRP&#xff1a;\u5907\u7528\u8282\u70b9\u901a\u5e38\u53ef\u4ee5\u63a5\u7ba1\u3002<\/p>\n<\/li>\n<li>\n<p>\u53ea\u6709 Nginx \u8fdb\u7a0b\u505c\u6b62&#xff1a;Keepalived \u4e0d\u4f1a\u4ec5\u51ed\u73b0\u6709\u914d\u7f6e\u76f4\u63a5\u611f\u77e5\u8be5\u6545\u969c\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u540e\u7eed\u82e5\u5e0c\u671b Nginx \u8fdb\u7a0b\u6545\u969c\u4e5f\u89e6\u53d1 VIP \u63a5\u7ba1&#xff0c;\u9700\u8981\u53e6\u5916\u8bbe\u8ba1 vrrp_script\u3001track_script \u7b49\u5065\u5eb7\u68c0\u67e5\u8054\u52a8\u673a\u5236&#xff0c;\u5e76\u5728\u6d4b\u8bd5\u73af\u5883\u9a8c\u8bc1\u3002<\/p>\n<hr \/>\n<h3>\u4e94\u3001Nginx \u4e3b\u914d\u7f6e\u6587\u4ef6<\/h3>\n<h4>5.1 \u914d\u7f6e\u8def\u5f84<\/h4>\n<p>\/app\/nginx1.20\/conf\/nginx.conf<\/p>\n<p>\u4e24\u53f0\u670d\u52a1\u5668\u901a\u5e38\u4f7f\u7528\u4e00\u81f4\u7684 Nginx \u4e3b\u914d\u7f6e\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u7cbe\u7b80\u540e\u7684\u901a\u7528\u53c2\u8003\u914d\u7f6e&#xff1a;<\/p>\n<p>worker_processes auto;<br \/>\nworker_rlimit_nofile 20960;<\/p>\n<p>error_log logs\/error.log crit;<\/p>\n<p>events {<br \/>\n    worker_connections 4096;<br \/>\n    multi_accept on;<br \/>\n    accept_mutex on;<br \/>\n    accept_mutex_delay 500ms;<br \/>\n}<\/p>\n<p>http {<br \/>\n    server_tokens off;<\/p>\n<p>    sendfile on;<br \/>\n    tcp_nopush on;<br \/>\n    tcp_nodelay on;<\/p>\n<p>    access_log off;<\/p>\n<p>    include mime.types;<br \/>\n    default_type application\/octet-stream;<\/p>\n<p>    keepalive_timeout 300;<br \/>\n    client_max_body_size 10240M;<\/p>\n<p>    gzip on;<br \/>\n    gzip_min_length 1k;<br \/>\n    gzip_buffers 4 16k;<br \/>\n    gzip_comp_level 6;<\/p>\n<p>    gzip_types text\/plain text\/css<br \/>\n               text\/javascript application\/json<br \/>\n               application\/javascript application\/xml;<\/p>\n<p>    include \/app\/nginx1.20\/conf\/http.d\/*.conf;<br \/>\n}<\/p>\n<p>stream {<br \/>\n    log_format proxy<br \/>\n        &#039;$remote_addr [$time_local] &#039;<br \/>\n        &#039;$protocol $status &#039;<br \/>\n        &#039;$bytes_sent $bytes_received &#039;<br \/>\n        &#039;$session_time &#034;$upstream_addr&#034; &#039;<br \/>\n        &#039;&#034;$upstream_bytes_sent&#034; &#039;<br \/>\n        &#039;&#034;$upstream_bytes_received&#034; &#039;<br \/>\n        &#039;&#034;$upstream_connect_time&#034;&#039;;<\/p>\n<p>    access_log<br \/>\n        \/app\/nginx1.20\/logs\/tcp-access.log proxy;<\/p>\n<p>    include \/app\/nginx1.20\/conf\/tcp.d\/*.conf;<br \/>\n} <\/p>\n<p>client_max_body_size \u7b49\u53c2\u6570\u6cbf\u7528\u4e86\u539f\u67b6\u6784\u8bbe\u8ba1\u601d\u8def&#xff0c;\u5b9e\u9645\u90e8\u7f72\u5e94\u6839\u636e\u4e1a\u52a1\u9700\u6c42\u548c\u5b89\u5168\u57fa\u7ebf\u91cd\u65b0\u8bc4\u4f30&#xff0c;\u4e0d\u5fc5\u673a\u68b0\u7167\u642c\u3002<\/p>\n<h4>5.2 HTTP \u548c Stream \u7684\u533a\u522b<\/h4>\n<p>http \u4e3b\u8981\u5904\u7406&#xff1a;<\/p>\n<ul>\n<li>\n<p>Web \u5e94\u7528\u3002<\/p>\n<\/li>\n<li>\n<p>HTTP\/HTTPS \u53cd\u5411\u4ee3\u7406\u3002<\/p>\n<\/li>\n<li>\n<p>\u57fa\u4e8e HTTP \u534f\u8bae\u7684\u8d1f\u8f7d\u5747\u8861\u3002<\/p>\n<\/li>\n<\/ul>\n<p>stream \u4e3b\u8981\u5904\u7406&#xff1a;<\/p>\n<ul>\n<li>\n<p>TCP \u4ee3\u7406\u3002<\/p>\n<\/li>\n<li>\n<p>UDP \u4ee3\u7406\u3002<\/p>\n<\/li>\n<li>\n<p>MySQL \u7b49\u975e HTTP \u534f\u8bae\u8fde\u63a5\u3002<\/p>\n<\/li>\n<\/ul>\n<p>MySQL \u4f7f\u7528 TCP \u534f\u8bae&#xff0c;\u56e0\u6b64\u9700\u8981\u4f7f\u7528 stream \u8fdb\u884c\u900f\u660e TCP \u8f6c\u53d1\u3002<\/p>\n<h4>5.3 \u6700\u5173\u952e\u7684\u662f include<\/h4>\n<p>stream {<br \/>\n    include \/app\/nginx1.20\/conf\/tcp.d\/*.conf;<br \/>\n} <\/p>\n<p>\u8fd9\u8868\u793a Nginx \u5c06 tcp.d \u76ee\u5f55\u4e0b\u7b26\u5408\u6761\u4ef6\u7684 .conf \u6587\u4ef6\u4f5c\u4e3a Stream \u914d\u7f6e\u52a0\u8f7d\u3002<\/p>\n<p>MySQL \u9996\u9009\u540e\u7aef\u3001\u5907\u7528\u540e\u7aef\u3001\u4ee3\u7406\u76d1\u542c\u7aef\u53e3\u7b49&#xff0c;\u90fd\u5728\u8fd9\u4e2a\u76ee\u5f55\u4e0b\u914d\u7f6e\u3002<\/p>\n<hr \/>\n<h3>\u516d\u3001Nginx MySQL \u4e3b\u5907\u4ee3\u7406\u914d\u7f6e<\/h3>\n<h4>6.1 \u6838\u5fc3\u914d\u7f6e<\/h4>\n<p>\u6587\u4ef6&#xff1a;<\/p>\n<p>\/app\/nginx1.20\/conf\/tcp.d\/mysql-tcp-13306.conf<\/p>\n<p>upstream mysql_backend {<br \/>\n    server 192.0.2.103:3306<br \/>\n           weight&#061;5<br \/>\n           max_fails&#061;2<br \/>\n           fail_timeout&#061;2s;<\/p>\n<p>    server 192.0.2.104:3306<br \/>\n           weight&#061;5<br \/>\n           backup;<br \/>\n}<\/p>\n<p>server {<br \/>\n    listen 13306 so_keepalive&#061;on;<\/p>\n<p>    proxy_connect_timeout 8s;<br \/>\n    proxy_timeout 300s;<\/p>\n<p>    proxy_pass mysql_backend;<br \/>\n} <\/p>\n<p>\u8fd9\u662f\u6807\u51c6 MySQL \u540e\u7aef 3306 \u7684\u793a\u4f8b\u3002<\/p>\n<h4>6.2 \u7aef\u53e3\u8f6c\u53d1\u5173\u7cfb<\/h4>\n<p>APP<br \/>\n |<br \/>\n | TCP :13306<br \/>\n v<br \/>\nNginx<br \/>\n |<br \/>\n | proxy_pass mysql_backend<br \/>\n |<br \/>\n &#043;&#8212;- MySQL-01 192.0.2.103:3306<br \/>\n |<br \/>\n &#043;&#8212;- MySQL-02 192.0.2.104:3306<br \/>\n                   (backup only) <\/p>\n<p>\u8fd9\u91cc\u6709\u4e24\u4e2a\u4e0d\u540c\u6982\u5ff5&#xff1a;<\/p>\n<ul>\n<li>\n<p>listen 13306&#xff1a;Nginx \u5bf9\u5e94\u7528\u5f00\u653e\u7684\u7aef\u53e3\u3002<\/p>\n<\/li>\n<li>\n<p>server IP:3306&#xff1a;Nginx \u8fde\u63a5\u540e\u7aef MySQL \u65f6\u4f7f\u7528\u7684\u7aef\u53e3\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u524d\u7aef\u7aef\u53e3\u548c\u540e\u7aef\u7aef\u53e3\u4e0d\u8981\u6c42\u76f8\u540c\u3002<\/p>\n<p>\u5982\u679c\u6570\u636e\u5e93\u5b9e\u9645\u76d1\u542c 13306&#xff0c;\u5219\u9700\u8981\u628a upstream \u4e2d\u7684 3306 \u66ff\u6362\u4e3a\u771f\u5b9e\u540e\u7aef\u7aef\u53e3\u3002<\/p>\n<h4>6.3 Nginx \u600e\u4e48\u77e5\u9053\u54ea\u4e2a MySQL \u662f\u9996\u9009&#xff1f;<\/h4>\n<p>\u5173\u952e\u5c31\u5728&#xff1a;<\/p>\n<p>server 192.0.2.103:3306 &#8230;;<br \/>\nserver 192.0.2.104:3306 backup; <\/p>\n<p>backup \u662f\u5907\u7528\u540e\u7aef\u6807\u8bb0\u3002<\/p>\n<p>\u6b63\u5e38\u60c5\u51b5\u4e0b&#xff0c;MySQL 01 \u4f5c\u4e3a\u666e\u901a\u540e\u7aef\u53c2\u4e0e\u8c03\u5ea6&#xff0c;MySQL 02 \u4e0d\u53c2\u4e0e\u6b63\u5e38\u65b0\u8fde\u63a5\u5206\u914d\u3002<\/p>\n<p>\u56e0\u6b64\u5373\u4f7f\u4e24\u4e2a\u8282\u70b9\u90fd\u914d\u7f6e weight&#061;5&#xff0c;\u4e5f\u4e0d\u4f1a\u56e0\u4e3a\u6743\u91cd\u76f8\u540c\u800c\u5728\u6b63\u5e38\u60c5\u51b5\u4e0b\u5404\u5206\u5230 50% \u8fde\u63a5\u3002<\/p>\n<h4>6.4 Nginx \u5982\u4f55\u5224\u65ad MySQL 01 \u4e0d\u53ef\u7528&#xff1f;<\/h4>\n<p>\u5173\u952e\u53c2\u6570&#xff1a;<\/p>\n<p>max_fails&#061;2<br \/>\nfail_timeout&#061;2s<br \/>\nproxy_connect_timeout 8s <\/p>\n<table>\n<tbody>\n<tr>\u53c2\u6570\u529f\u80fd<\/tr>\n<tr>\n<td>max_fails&#061;2<\/td>\n<td>\u8fbe\u5230\u6307\u5b9a\u5931\u8d25\u6b21\u6570\u65f6\u4e34\u65f6\u6807\u8bb0\u540e\u7aef\u4e0d\u53ef\u7528<\/td>\n<\/tr>\n<tr>\n<td>fail_timeout&#061;2s<\/td>\n<td>\u5931\u8d25\u7edf\u8ba1\u7a97\u53e3\u53ca\u4e34\u65f6\u4e0d\u53ef\u7528\u65f6\u957f<\/td>\n<\/tr>\n<tr>\n<td>proxy_connect_timeout&#061;8s<\/td>\n<td>TCP \u540e\u7aef\u5efa\u8fde\u8d85\u65f6<\/td>\n<\/tr>\n<tr>\n<td>backup<\/td>\n<td>\u5c06\u7b2c\u4e8c\u4e2a\u6570\u636e\u5e93\u8bbe\u4e3a\u5907\u7528<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5f53\u524d\u4f7f\u7528\u7684\u662f\u88ab\u52a8\u6545\u969c\u68c0\u6d4b\u3002<\/p>\n<p>Nginx \u4e0d\u4f1a\u4e3b\u52a8\u767b\u5f55 MySQL&#xff0c;\u4e5f\u4e0d\u4f1a\u5b9a\u671f\u6267\u884c SQL \u5224\u65ad\u590d\u5236\u72b6\u6001\u3002<\/p>\n<p>\u5b83\u6839\u636e\u771f\u5b9e\u4e1a\u52a1\u8fde\u63a5\u8fc7\u7a0b\u4e2d\u53d1\u751f\u7684 TCP \u5efa\u8fde\u9519\u8bef\u548c\u8d85\u65f6\u8bb0\u5f55\u5931\u8d25\u3002<\/p>\n<h4>6.5 \u9996\u9009 MySQL \u6545\u969c\u5207\u6362\u6d41\u7a0b<\/h4>\n<p>\u6b63\u5e38\u72b6\u6001&#xff1a;<\/p>\n<p>APP<br \/>\n |<br \/>\n v<br \/>\nNginx<br \/>\n |<br \/>\n v<br \/>\nMySQL-01 :3306<br \/>\n |<br \/>\n &#043;&#8211; TCP CONNECTED <\/p>\n<p>\u9996\u9009\u540e\u7aef TCP \u5efa\u8fde\u5931\u8d25&#xff1a;<\/p>\n<p>APP<br \/>\n |<br \/>\n v<br \/>\nNginx<br \/>\n |<br \/>\n &#043;&#8212;-X&#8212;-&gt; MySQL-01 :3306<br \/>\n |           CONNECT FAILED<br \/>\n |<br \/>\n &#043;&#8212;&#8212;&#8212;&gt; MySQL-02 :3306<br \/>\n             BACKUP ATTEMPT <\/p>\n<p>\u7279\u522b\u6ce8\u610f&#xff1a;\u7531\u4e8e Stream \u7684 proxy_next_upstream \u9ed8\u8ba4\u542f\u7528&#xff0c;\u67d0\u6b21\u8fde\u63a5 MySQL 01 \u5931\u8d25\u65f6&#xff0c;\u5c31\u53ef\u4ee5\u5c1d\u8bd5 MySQL 02\u3002<\/p>\n<p>\u4e0d\u4e00\u5b9a\u9700\u8981\u5148\u7d2f\u8ba1\u4e24\u6b21\u5931\u8d25\u3002<\/p>\n<p>max_fails&#061;2 \u7684\u4f5c\u7528\u662f\u4e34\u65f6\u4e0d\u53ef\u7528\u5224\u5b9a&#xff0c;\u800c\u4e0d\u662f\u6bcf\u6b21\u8bf7\u6c42\u5207\u6362\u6240\u5fc5\u9700\u7684\u5931\u8d25\u6b21\u6570\u3002<\/p>\n<p>\u6ca1\u6709\u914d\u7f6e upstream zone \u65f6&#xff0c;Nginx \u591a\u4e2a Worker \u7684\u5931\u8d25\u72b6\u6001\u4e5f\u53ef\u80fd\u4e0d\u662f\u7edf\u4e00\u5171\u4eab\u7684\u3002<\/p>\n<h4>6.6 \u91cd\u8981\u9650\u5236<\/h4>\n<p>Nginx \u5224\u65ad\u7684\u662f TCP \u5efa\u8fde\u80fd\u529b\u3002<\/p>\n<p>\u5b83\u4e0d\u80fd\u4ec5\u51ed\u5f53\u524d\u914d\u7f6e\u5224\u65ad&#xff1a;<\/p>\n<ul>\n<li>\n<p>MySQL \u662f\u5426\u5141\u8bb8\u5199\u5165\u3002<\/p>\n<\/li>\n<li>\n<p>SQL \u662f\u5426\u6267\u884c\u6b63\u5e38\u3002<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u5e93\u590d\u5236\u662f\u5426\u4e2d\u65ad\u3002<\/p>\n<\/li>\n<li>\n<p>MySQL \u4e3b\u4ece\u89d2\u8272\u662f\u5426\u53d8\u5316\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e24\u53f0\u6570\u636e\u5e93\u7684\u6570\u636e\u662f\u5426\u5df2\u7ecf\u540c\u6b65\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u56e0\u6b64&#xff0c;\u8be5\u914d\u7f6e\u5b9e\u73b0\u7684\u662f TCP \u8fde\u63a5\u4e3b\u5907\u4ee3\u7406&#xff0c;\u800c\u4e0d\u662f\u6570\u636e\u5e93\u5c42\u9762\u7684\u81ea\u52a8\u4e3b\u5e93\u9009\u4e3e\u3002<\/p>\n<hr \/>\n<h3>\u4e03\u3001MySQL \u53cc\u5411\u590d\u5236\u4e0e\u5355\u5199\u6a21\u5f0f<\/h3>\n<h4>7.1 \u53cc\u5411\u590d\u5236\u67b6\u6784<\/h4>\n<p> &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#043;      &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#043;<br \/>\n |     MySQL-01     |      |     MySQL-02     |<br \/>\n | 192.0.2.103:3306 |&lt;&#8212;-&gt;| 192.0.2.104:3306 |<br \/>\n &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#043;      &#043;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#043;<br \/>\n         Replication in both directions <\/p>\n<p>\u53cc\u5411\u590d\u5236\u8bf4\u660e\u4e24\u4e2a\u6570\u636e\u5e93\u4e4b\u95f4\u5177\u6709\u76f8\u4e92\u590d\u5236\u5173\u7cfb&#xff0c;\u4f46\u4e0d\u610f\u5473\u7740\u5df2\u7ecf\u5b9e\u73b0\u81ea\u52a8\u4e3b\u5e93\u4ef2\u88c1\u3002<\/p>\n<h4>7.2 \u4e3a\u4ec0\u4e48\u9700\u8981\u5355\u5199&#xff1f;<\/h4>\n<p>\u4e24\u53f0 MySQL \u5373\u4f7f\u90fd\u5141\u8bb8\u5199\u5165&#xff0c;\u4e5f\u53ef\u80fd\u56e0\u4e3a\u540c\u65f6\u4fee\u6539\u76f8\u540c\u6570\u636e\u800c\u4ea7\u751f\u590d\u5236\u51b2\u7a81\u3002<\/p>\n<p>\u56e0\u6b64&#xff0c;\u5728\u91c7\u7528\u5355\u5199\u8bbe\u8ba1\u7684\u4e1a\u52a1\u7cfb\u7edf\u4e2d&#xff0c;\u9700\u8981\u786e\u4fdd\u6b63\u5e38\u4e1a\u52a1\u5199\u5165\u96c6\u4e2d\u5230\u88ab\u8ba4\u53ef\u7684\u5199\u5165\u8282\u70b9\u3002<\/p>\n<p>Nginx \u53ef\u4ee5\u5b9e\u73b0\u6b63\u5e38\u60c5\u51b5\u4e0b\u7684\u5355\u76ee\u6807\u4ee3\u7406&#xff1a;<\/p>\n<p>Normal:<br \/>\nAPP -&gt; Nginx -&gt; MySQL-01<\/p>\n<p>TCP failover:<br \/>\nAPP -&gt; Nginx -&gt; MySQL-02 <\/p>\n<p>\u4f46\u8fd9\u53ea\u662f\u4ee3\u7406\u8def\u7531\u89c4\u5219\u3002<\/p>\n<h4>7.3 \u4e3a\u4ec0\u4e48\u4e0d\u80fd\u5355\u9760 Nginx \u4fdd\u8bc1\u4e25\u683c\u5355\u5199&#xff1f;<\/h4>\n<p>\u8003\u8651\u4ee5\u4e0b\u6545\u969c\u6062\u590d\u573a\u666f&#xff1a;<\/p>\n<li>\n<p>MySQL 01 \u6545\u969c&#xff0c;Nginx \u5f00\u59cb\u5c06\u90e8\u5206\u65b0\u8fde\u63a5\u53d1\u5f80 MySQL 02\u3002<\/p>\n<\/li>\n<li>\n<p>MySQL 02 \u4e0a\u5efa\u7acb\u4e86\u4e1a\u52a1\u8fde\u63a5\u3002<\/p>\n<\/li>\n<li>\n<p>MySQL 01 \u6062\u590d TCP \u8fde\u63a5\u80fd\u529b\u3002<\/p>\n<\/li>\n<li>\n<p>Nginx \u518d\u6b21\u628a\u90e8\u5206\u65b0\u8fde\u63a5\u4f18\u5148\u53d1\u9001\u5230 MySQL 01\u3002<\/p>\n<\/li>\n<li>\n<p>MySQL 02 \u4e0a\u7684\u65e7\u8fde\u63a5\u53ef\u80fd\u4ecd\u672a\u7ed3\u675f\u3002<\/p>\n<\/li>\n<p>\u6b64\u65f6\u5982\u679c\u4e24\u4e2a\u6570\u636e\u5e93\u90fd\u5141\u8bb8\u5199\u5165&#xff0c;\u5c31\u53ef\u80fd\u540c\u65f6\u5b58\u5728\u5411\u4e0d\u540c\u6570\u636e\u5e93\u5199\u5165\u7684\u4e1a\u52a1\u4f1a\u8bdd\u3002<\/p>\n<p>\u56e0\u6b64\u8fd8\u9700\u8981\u6570\u636e\u5e93\u5c42\u9762\u7684\u5199\u5165\u7ea6\u675f\u3001\u6545\u969c\u9694\u79bb\u3001\u6570\u636e\u4e00\u81f4\u6027\u68c0\u67e5\u548c\u5207\u6362\u7ba1\u7406\u3002<\/p>\n<hr \/>\n<h3>\u516b\u3001\u751f\u4ea7\u73af\u5883\u6545\u969c\u573a\u666f<\/h3>\n<table>\n<tbody>\n<tr>\u6545\u969c\u573a\u666f\u5904\u7406\u7ec4\u4ef6\u7ed3\u679c<\/tr>\n<tr>\n<td>\u5f53\u524d\u6301\u6709 VIP \u7684\u670d\u52a1\u5668\u5b95\u673a<\/td>\n<td>Keepalived<\/td>\n<td>\u5907\u7528\u8282\u70b9\u901a\u5e38\u5c1d\u8bd5\u63a5\u7ba1 VIP<\/td>\n<\/tr>\n<tr>\n<td>Keepalived \u65e0\u6cd5\u7ee7\u7eed\u53d1\u9001\u6709\u6548 VRRP \u901a\u544a<\/td>\n<td>Keepalived<\/td>\n<td>\u53ef\u80fd\u89e6\u53d1\u4e3b\u5907\u5207\u6362<\/td>\n<\/tr>\n<tr>\n<td>Nginx \u8fdb\u7a0b\u5355\u72ec\u505c\u6b62<\/td>\n<td>\u5f53\u524d\u67b6\u6784\u672a\u914d\u7f6e\u76f4\u63a5\u68c0\u6d4b<\/td>\n<td>VIP \u4e0d\u4e00\u5b9a\u6f02\u79fb<\/td>\n<\/tr>\n<tr>\n<td>MySQL 01 TCP \u5efa\u8fde\u5931\u8d25<\/td>\n<td>Nginx<\/td>\n<td>\u53ef\u4ee5\u5c1d\u8bd5 MySQL 02<\/td>\n<\/tr>\n<tr>\n<td>MySQL 01 SQL \u903b\u8f91\u6267\u884c\u5931\u8d25<\/td>\n<td>\u6570\u636e\u5e93 \/ \u5e94\u7528<\/td>\n<td>Nginx \u4e0d\u4f1a\u4ec5\u51ed SQL \u9519\u8bef\u5207\u6362<\/td>\n<\/tr>\n<tr>\n<td>MySQL 01 \u6062\u590d TCP \u670d\u52a1<\/td>\n<td>Nginx<\/td>\n<td>\u65b0\u8fde\u63a5\u53ef\u80fd\u91cd\u65b0\u4f18\u5148\u8bbf\u95ee MySQL 01<\/td>\n<\/tr>\n<tr>\n<td>MySQL \u53cc\u5411\u590d\u5236\u4e2d\u65ad<\/td>\n<td>\u6570\u636e\u5e93\u76d1\u63a7\u4e0e\u8fd0\u7ef4\u673a\u5236<\/td>\n<td>Nginx \u4e0d\u8d1f\u8d23\u590d\u5236\u6062\u590d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>\u4e5d\u3001\u751f\u4ea7\u73af\u5883\u5e38\u7528\u53ea\u8bfb\u68c0\u67e5\u547d\u4ee4<\/h3>\n<h4>9.1 \u67e5\u770b VIP \u5f53\u524d\u5728\u54ea\u4e2a\u8282\u70b9<\/h4>\n<p>\u5206\u522b\u5728\u4e24\u53f0 Nginx \u4e0a\u6267\u884c&#xff1a;<\/p>\n<p>ip -br addr <\/p>\n<p>\u786e\u8ba4 VIP \u53ea\u7ed1\u5b9a\u5728\u9884\u671f\u8282\u70b9\u3002<\/p>\n<h4>9.2 \u67e5\u770b Keepalived \u72b6\u6001<\/h4>\n<p>systemctl status keepalived &#8211;no-pager <\/p>\n<h4>9.3 \u67e5\u770b VRRP \u5207\u6362\u65e5\u5fd7<\/h4>\n<p>journalctl -u keepalived &#8211;no-pager \\\\<br \/>\n  | grep -Ei &#039;MASTER|BACKUP|FAULT|Entering&#039; <\/p>\n<h4>9.4 \u67e5\u770b Nginx \u8fdb\u7a0b<\/h4>\n<p>ps -ef | grep &#039;[n]ginx&#039; <\/p>\n<h4>9.5 \u67e5\u770b\u4ee3\u7406\u7aef\u53e3<\/h4>\n<p>ss -lntp | grep 13306 <\/p>\n<h4>9.6 \u67e5\u770b Nginx TCP \u4ee3\u7406\u65e5\u5fd7<\/h4>\n<p>tail -n 50 \/app\/nginx1.20\/logs\/tcp-access.log <\/p>\n<p>\u65e5\u5fd7\u4e2d\u7684 $upstream_addr \u53ef\u4ee5\u5e2e\u52a9\u5224\u65ad\u5df2\u8bb0\u5f55\u7684 TCP \u4f1a\u8bdd\u7a76\u7adf\u8fde\u63a5\u5230\u54ea\u4e2a\u540e\u7aef\u3002<\/p>\n<h4>9.7 \u67e5\u770b\u6570\u636e\u5e93\u5b9e\u9645\u76d1\u542c\u7aef\u53e3<\/h4>\n<p>\u5728\u6570\u636e\u5e93\u670d\u52a1\u5668\u4e0a&#xff1a;<\/p>\n<p>ss -lntp | grep -E &#039;:3306|:13306&#039; <\/p>\n<p>\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5df2\u7ecf\u5efa\u7acb\u7684 MySQL \u7ba1\u7406\u8fde\u63a5\u6267\u884c&#xff1a;<\/p>\n<p>SHOW VARIABLES LIKE &#039;port&#039;; <\/p>\n<p>\u5fc5\u987b\u4ee5\u5b9e\u9645\u76d1\u542c\u7aef\u53e3\u4e3a\u51c6&#xff0c;\u4e0d\u53ef\u4ec5\u51ed MySQL \u9ed8\u8ba4\u7aef\u53e3\u63a8\u65ad\u73b0\u7f51\u7aef\u53e3\u3002<\/p>\n<hr \/>\n<h3>\u5341\u3001\u4ece\u96f6\u90e8\u7f72\u65f6\u7684\u68c0\u67e5\u987a\u5e8f<\/h3>\n<p>\u63a8\u8350\u6309\u4ee5\u4e0b\u987a\u5e8f\u642d\u5efa&#xff1a;<\/p>\n<li>\n<p>\u51c6\u5907\u4e24\u53f0\u4ee3\u7406\u670d\u52a1\u5668&#xff0c;\u786e\u8ba4\u7f51\u7edc\u548c\u8f6f\u4ef6\u7248\u672c\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b89\u88c5\u652f\u6301 Stream \u6a21\u5757\u7684 Nginx\u3002<\/p>\n<\/li>\n<li>\n<p>\u90e8\u7f72\u4e24\u53f0 Nginx \u7684\u4e3b\u914d\u7f6e\u548c\u6570\u636e\u5e93 TCP \u4ee3\u7406\u914d\u7f6e\u3002<\/p>\n<\/li>\n<li>\n<p>\u786e\u8ba4\u540e\u7aef MySQL \u5b9e\u9645\u76d1\u542c\u7aef\u53e3&#xff0c;\u4ee5\u53ca\u6570\u636e\u5e93\u590d\u5236\u548c\u5199\u5165\u89d2\u8272\u673a\u5236\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728\u65b0\u73af\u5883\u6821\u9a8c Nginx \u914d\u7f6e\u3002<\/p>\n<\/li>\n<li>\n<p>\u90e8\u7f72\u4e24\u53f0 Keepalived&#xff0c;\u8bbe\u7f6e VRRP \u5355\u64ad\u5bf9\u7aef\u3001\u4f18\u5148\u7ea7\u548c VIP\u3002<\/p>\n<\/li>\n<li>\n<p>\u6821\u9a8c VRRP \u901a\u4fe1\u4e0e VIP \u5f52\u5c5e\u3002<\/p>\n<\/li>\n<li>\n<p>\u901a\u8fc7\u6d4b\u8bd5\u5ba2\u6237\u7aef\u9a8c\u8bc1\u6570\u636e\u5e93\u8fde\u63a5\u6d41\u5411\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728\u6d4b\u8bd5\u73af\u5883\u6f14\u7ec3\u5165\u53e3\u6545\u969c\u548c\u6570\u636e\u5e93\u8fde\u63a5\u5931\u8d25\u3002<\/p>\n<\/li>\n<li>\n<p>\u786e\u8ba4\u5e94\u7528\u91cd\u8fde\u3001\u6545\u969c\u6062\u590d\u3001\u6570\u636e\u5e93\u5355\u5199\u548c\u590d\u5236\u4e00\u81f4\u6027\u673a\u5236\u3002<\/p>\n<\/li>\n<p>\u5728\u65b0\u90e8\u7f72\u73af\u5883\u4e2d&#xff0c;\u53ef\u4ee5\u4f7f\u7528&#xff1a;<\/p>\n<p>\/app\/nginx1.20\/sbin\/nginx -t \\\\<br \/>\n  -c \/app\/nginx1.20\/conf\/nginx.conf <\/p>\n<p>\u6821\u9a8c Nginx \u914d\u7f6e\u3002<\/p>\n<p>\u4f46\u5728\u5df2\u6709\u751f\u4ea7\u73af\u5883\u4e2d&#xff0c;\u5e94\u9075\u5faa\u53d8\u66f4\u6d41\u7a0b&#xff0c;\u4e0d\u5e94\u968f\u610f\u901a\u8fc7\u505c\u6b62\u670d\u52a1\u6a21\u62df\u6545\u969c\u3002<\/p>\n<hr \/>\n<h3>\u5341\u4e00\u3001\u5e38\u89c1\u95ee\u9898<\/h3>\n<p>Q1&#xff1a;\u4e3a\u4ec0\u4e48\u5df2\u7ecf\u6709 Nginx&#xff0c;\u8fd8\u9700\u8981 Keepalived&#xff1f;<\/p>\n<p>\u56e0\u4e3a\u666e\u901a Nginx \u672c\u8eab\u4e0d\u7ba1\u7406 VRRP VIP \u6f02\u79fb\u3002Keepalived \u4e3a\u4ee3\u7406\u5165\u53e3\u63d0\u4f9b\u8282\u70b9\u7ea7\u6545\u969c\u63a5\u7ba1\u80fd\u529b\u3002<\/p>\n<p>Q2&#xff1a;\u4e24\u53f0 Nginx \u662f\u5426\u5fc5\u987b\u7ec4\u6210\u53cc\u6d3b\u96c6\u7fa4&#xff1f;<\/p>\n<p>\u4e0d\u9700\u8981\u3002\u672c\u6587\u91c7\u7528\u4e3b\u5907\u6a21\u5f0f&#xff0c;\u6b63\u5e38\u60c5\u51b5\u4e0b\u53ea\u6709\u4e00\u4e2a\u8282\u70b9\u5904\u7406\u901a\u8fc7 VIP \u8fdb\u5165\u7684\u8fde\u63a5\u3002<\/p>\n<p>Q3&#xff1a;\u4e24\u53f0 Nginx \u914d\u7f6e\u4e3a\u4ec0\u4e48\u4e00\u6837&#xff1f;<\/p>\n<p>\u8fd9\u6837\u65e0\u8bba VIP \u5728\u54ea\u4e2a\u8282\u70b9&#xff0c;\u540e\u7aef MySQL \u8c03\u5ea6\u89c4\u5219\u90fd\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<p>Q4&#xff1a;\u6ca1\u6709 VIP \u7684\u90a3\u53f0 Nginx \u662f\u5426\u505c\u6b62\u5de5\u4f5c&#xff1f;<\/p>\n<p>\u4e0d\u662f\u3002\u5b83\u4ecd\u7136\u8fd0\u884c&#xff0c;\u53ea\u662f\u4e0d\u5904\u7406\u901a\u8fc7\u8fd9\u4e2a VIP \u8fdb\u5165\u7684\u65b0\u8fde\u63a5&#xff1b;\u901a\u8fc7\u771f\u5b9e IP \u76f4\u63a5\u8bbf\u95ee\u7684\u4e1a\u52a1\u4ecd\u53ef\u80fd\u7531\u5b83\u5904\u7406\u3002<\/p>\n<p>Q5&#xff1a;MySQL \u9ed8\u8ba4\u662f 3306&#xff0c;\u4e3a\u4ec0\u4e48 Nginx \u4f7f\u7528 13306&#xff1f;<\/p>\n<p>\u56e0\u4e3a Nginx \u5bf9\u5ba2\u6237\u7aef\u63d0\u4f9b\u7684\u4ee3\u7406\u7aef\u53e3\u53ef\u4ee5\u72ec\u7acb\u8bbe\u7f6e\u3002\u5e94\u7528\u8bbf\u95ee Nginx \u7684 13306&#xff0c;Nginx \u53ef\u4ee5\u8f6c\u53d1\u5230 MySQL \u7684 3306\u3002\u82e5\u540e\u7aef\u4e5f\u914d\u7f6e\u4e3a 13306&#xff0c;\u5219\u4ee5\u8be5\u540e\u7aef\u5b9e\u9645\u670d\u52a1\u7aef\u53e3\u4e3a\u51c6\u3002<\/p>\n<p>Q6&#xff1a;Nginx \u5982\u4f55\u77e5\u9053\u54ea\u4e2a\u6570\u636e\u5e93\u662f\u4e3b\u5e93&#xff1f;<\/p>\n<p>\u5b83\u5e76\u4e0d\u4f1a\u81ea\u52a8\u8bc6\u522b MySQL \u4e3b\u5e93&#xff0c;\u800c\u662f\u6309\u7167 upstream \u4e2d\u7684\u666e\u901a\u540e\u7aef\u548c backup \u6807\u8bb0\u9009\u62e9 TCP \u8fde\u63a5\u76ee\u6807\u3002<\/p>\n<p>Q7&#xff1a;MySQL 01 \u6062\u590d\u540e&#xff0c;Nginx \u662f\u5426\u4f1a\u81ea\u52a8\u91cd\u65b0\u4f7f\u7528\u5b83&#xff1f;<\/p>\n<p>\u540e\u7eed\u65b0\u8fde\u63a5\u53ef\u80fd\u91cd\u65b0\u4f18\u5148\u9009\u62e9 MySQL 01&#xff0c;\u4f46\u539f\u5148\u8fde\u63a5\u5230 MySQL 02 \u7684\u4f1a\u8bdd\u4e0d\u4f1a\u81ea\u52a8\u8fc1\u79fb&#xff0c;\u6570\u636e\u5e93\u5199\u5165\u5b89\u5168\u9700\u8981\u72ec\u7acb\u4fdd\u8bc1\u3002<\/p>\n<hr \/>\n<h3>\u5341\u4e8c\u3001\u603b\u7ed3<\/h3>\n<p>\u8fd9\u5957\u67b6\u6784\u7684\u6838\u5fc3\u53ef\u4ee5\u7528\u4e09\u53e5\u8bdd\u6982\u62ec&#xff1a;<\/p>\n<p>Keepalived \u7ba1\u5165\u53e3&#xff1a; \u51b3\u5b9a VIP \u5f53\u524d\u4f4d\u4e8e\u54ea\u4e2a Nginx \u8282\u70b9\u3002<\/p>\n<p>Nginx \u7ba1\u8fde\u63a5&#xff1a; \u6309\u7167 upstream \u4e2d\u7684 backup \u548c\u5931\u8d25\u5224\u5b9a\u89c4\u5219&#xff0c;\u51b3\u5b9a\u65b0\u8fde\u63a5\u4f7f\u7528\u54ea\u4e2a MySQL \u540e\u7aef\u3002<\/p>\n<p>MySQL \u7ba1\u6570\u636e&#xff1a; \u53cc\u5411\u590d\u5236\u8d1f\u8d23\u6570\u636e\u540c\u6b65&#xff0c;\u4f46\u5199\u5165\u89d2\u8272\u4ef2\u88c1\u548c\u6570\u636e\u4e00\u81f4\u6027\u4fdd\u969c\u9700\u8981\u5355\u72ec\u8bbe\u8ba1\u3002<\/p>\n<p>\u6700\u91cd\u8981\u7684\u662f\u660e\u786e\u4e24\u7c7b\u5207\u6362&#xff1a;<\/p>\n<ul>\n<li>\n<p>VIP \u6f02\u79fb&#xff1a; \u53d1\u751f\u5728 Nginx \u4ee3\u7406\u5165\u53e3\u5c42&#xff0c;\u7531 Keepalived \u8d1f\u8d23\u3002<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u5e93\u8fde\u63a5\u8f6c\u53d1&#xff1a; \u53d1\u751f\u5728 MySQL \u4ee3\u7406\u5c42&#xff0c;\u7531 Nginx Stream \u8d1f\u8d23\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u8fd9\u4e24\u5c42\u9ad8\u53ef\u7528\u76f8\u4e92\u72ec\u7acb\u3002\u5373\u4f7f\u5168\u90e8\u914d\u7f6e\u6b63\u5e38&#xff0c;\u4e5f\u4e0d\u80fd\u5c06 TCP \u81ea\u52a8\u91cd\u8fde\u7b49\u540c\u4e8e\u6570\u636e\u5e93\u65e0\u635f\u5207\u6362\u3002<\/p>\n<p>\u672a\u6765\u90e8\u7f72\u7c7b\u4f3c\u67b6\u6784\u65f6&#xff0c;\u9996\u5148\u4fdd\u5b58 Keepalived \u4e3b\u914d\u7f6e\u3001Nginx \u4e3b\u914d\u7f6e\u548c MySQL Stream \u5b50\u914d\u7f6e&#xff0c;\u518d\u7ed3\u5408\u6570\u636e\u5e93\u590d\u5236\u7ba1\u7406\u3001\u5e94\u7528\u91cd\u8fde\u548c\u751f\u4ea7\u7f51\u7edc\u6761\u4ef6\u5b8c\u6210\u6574\u4f53\u9ad8\u53ef\u7528\u8bbe\u8ba1\u3002<\/p>\n<hr \/>\n<h3>\u5b98\u65b9\u53c2\u8003\u8d44\u6599<\/h3>\n<ul>\n<li>\n<p>Keepalived \u914d\u7f6e\u6587\u6863<\/p>\n<\/li>\n<li>\n<p>Nginx Stream Core<\/p>\n<\/li>\n<li>\n<p>Nginx Stream Upstream<\/p>\n<\/li>\n<li>\n<p>Nginx Stream Proxy<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00<br \/>\n\u5728\u751f\u4ea7\u73af\u5883\u4e2d&#xff0c;\u4e3a\u4e86\u907f\u514d\u6570\u636e\u5e93\u8bbf\u95ee\u5165\u53e3\u51fa\u73b0\u5355\u70b9\u6545\u969c&#xff0c;\u5e38\u91c7\u7528 Keepalived  \u53cc Nginx  MySQL \u53cc\u5411\u590d\u5236 \u7684\u67b6\u6784\u3002<br \/>\n\u6574\u5957\u67b6\u6784\u5b9e\u9645\u4e0a\u5206\u4e3a\u4e09\u5c42&#xff1a; Keepalived&#xff1a; \u8d1f\u8d23 Nginx \u4ee3\u7406\u5165\u53e3\u7684\u9ad8\u53ef\u7528&#xff0c;\u63a7\u5236 VIP \u5f52\u5c5e\u3002  Nginx&#xff1a; \u8d1f\u8d23 MySQL \u7684 TCP \u8fde\u63a5\u8f6c\u53d1&#xff0c;\u6307\u5b9a\u9996\u9009\u548c\u5907\u7528\u6570\u636e\u5e93\u3002  MySQL&#xff1a; \u8d1f\u8d23\u6570\u636e\u5b58\u50a8\u548c\u53cc\u5411\u590d\u5236<\/p>\n","protected":false},"author":2,"featured_media":120223,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[2508,114,117,100,44],"topic":[],"class_list":["post-120224","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-keepalived","tag-mysql","tag-nginx","tag-100","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u751f\u4ea7\u5b9e\u6218\uff1aKeepalived + Nginx + MySQL \u53cc\u5411\u590d\u5236\u9ad8\u53ef\u7528\u67b6\u6784\u90e8\u7f72\u4e0e\u539f\u7406\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/120224.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u751f\u4ea7\u5b9e\u6218\uff1aKeepalived + Nginx + MySQL \u53cc\u5411\u590d\u5236\u9ad8\u53ef\u7528\u67b6\u6784\u90e8\u7f72\u4e0e\u539f\u7406\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u524d\u8a00 \u5728\u751f\u4ea7\u73af\u5883\u4e2d&#xff0c;\u4e3a\u4e86\u907f\u514d\u6570\u636e\u5e93\u8bbf\u95ee\u5165\u53e3\u51fa\u73b0\u5355\u70b9\u6545\u969c&#xff0c;\u5e38\u91c7\u7528 Keepalived \u53cc Nginx MySQL \u53cc\u5411\u590d\u5236 \u7684\u67b6\u6784\u3002 \u6574\u5957\u67b6\u6784\u5b9e\u9645\u4e0a\u5206\u4e3a\u4e09\u5c42&#xff1a; Keepalived&#xff1a; \u8d1f\u8d23 Nginx \u4ee3\u7406\u5165\u53e3\u7684\u9ad8\u53ef\u7528&#xff0c;\u63a7\u5236 VIP \u5f52\u5c5e\u3002 Nginx&#xff1a; \u8d1f\u8d23 MySQL \u7684 TCP \u8fde\u63a5\u8f6c\u53d1&#xff0c;\u6307\u5b9a\u9996\u9009\u548c\u5907\u7528\u6570\u636e\u5e93\u3002 MySQL&#xff1a; \u8d1f\u8d23\u6570\u636e\u5b58\u50a8\u548c\u53cc\u5411\u590d\u5236\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/120224.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-31T00:24:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031002456-6ae53558ce35a.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/120224.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/120224.html\",\"name\":\"\u751f\u4ea7\u5b9e\u6218\uff1aKeepalived + Nginx + MySQL \u53cc\u5411\u590d\u5236\u9ad8\u53ef\u7528\u67b6\u6784\u90e8\u7f72\u4e0e\u539f\u7406\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-31T00:24:59+00:00\",\"dateModified\":\"2026-10-31T00:24:59+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/120224.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/120224.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/120224.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u751f\u4ea7\u5b9e\u6218\uff1aKeepalived + Nginx + MySQL \u53cc\u5411\u590d\u5236\u9ad8\u53ef\u7528\u67b6\u6784\u90e8\u7f72\u4e0e\u539f\u7406\u8be6\u89e3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u751f\u4ea7\u5b9e\u6218\uff1aKeepalived + Nginx + MySQL \u53cc\u5411\u590d\u5236\u9ad8\u53ef\u7528\u67b6\u6784\u90e8\u7f72\u4e0e\u539f\u7406\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/120224.html","og_locale":"zh_CN","og_type":"article","og_title":"\u751f\u4ea7\u5b9e\u6218\uff1aKeepalived + Nginx + MySQL \u53cc\u5411\u590d\u5236\u9ad8\u53ef\u7528\u67b6\u6784\u90e8\u7f72\u4e0e\u539f\u7406\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u524d\u8a00 \u5728\u751f\u4ea7\u73af\u5883\u4e2d&#xff0c;\u4e3a\u4e86\u907f\u514d\u6570\u636e\u5e93\u8bbf\u95ee\u5165\u53e3\u51fa\u73b0\u5355\u70b9\u6545\u969c&#xff0c;\u5e38\u91c7\u7528 Keepalived \u53cc Nginx MySQL \u53cc\u5411\u590d\u5236 \u7684\u67b6\u6784\u3002 \u6574\u5957\u67b6\u6784\u5b9e\u9645\u4e0a\u5206\u4e3a\u4e09\u5c42&#xff1a; Keepalived&#xff1a; \u8d1f\u8d23 Nginx \u4ee3\u7406\u5165\u53e3\u7684\u9ad8\u53ef\u7528&#xff0c;\u63a7\u5236 VIP \u5f52\u5c5e\u3002 Nginx&#xff1a; \u8d1f\u8d23 MySQL \u7684 TCP \u8fde\u63a5\u8f6c\u53d1&#xff0c;\u6307\u5b9a\u9996\u9009\u548c\u5907\u7528\u6570\u636e\u5e93\u3002 MySQL&#xff1a; \u8d1f\u8d23\u6570\u636e\u5b58\u50a8\u548c\u53cc\u5411\u590d\u5236","og_url":"https:\/\/www.wsisp.com\/helps\/120224.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-31T00:24:59+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/10\/20261031002456-6ae53558ce35a.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/120224.html","url":"https:\/\/www.wsisp.com\/helps\/120224.html","name":"\u751f\u4ea7\u5b9e\u6218\uff1aKeepalived + Nginx + MySQL \u53cc\u5411\u590d\u5236\u9ad8\u53ef\u7528\u67b6\u6784\u90e8\u7f72\u4e0e\u539f\u7406\u8be6\u89e3 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-31T00:24:59+00:00","dateModified":"2026-10-31T00:24:59+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/120224.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/120224.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/120224.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u751f\u4ea7\u5b9e\u6218\uff1aKeepalived + Nginx + MySQL \u53cc\u5411\u590d\u5236\u9ad8\u53ef\u7528\u67b6\u6784\u90e8\u7f72\u4e0e\u539f\u7406\u8be6\u89e3"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/120224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=120224"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/120224\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/120223"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=120224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=120224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=120224"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=120224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}