{"id":71202,"date":"2024-08-20T10:31:10","date_gmt":"2024-08-20T02:31:10","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=71202"},"modified":"2024-08-20T10:31:10","modified_gmt":"2024-08-20T02:31:10","slug":"redis-high-availability","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/redis-high-availability.html","title":{"rendered":"Redis\u00a0\u9ad8\u53ef\u7528\u6027\u5b9e\u8df5"},"content":{"rendered":"
0\u00d701 \u524d\u8a00<\/strong><\/div>\n

Redis \u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u4f7f\u7528 ANSI C \u8bed\u8a00\u7f16\u5199\u3001\u652f\u6301\u7f51\u7edc\u3001\u53ef\u57fa\u4e8e\u5185\u5b58\u4ea6\u53ef\u6301\u4e45\u5316\u7684\u65e5\u5fd7\u578b\u3001Key-Value \u6570\u636e\u5e93\uff0c\u5e76\u63d0\u4f9b\u591a\u79cd\u8bed\u8a00\u7684 API\u3002<\/p>\n

\u5982\u4eca\uff0c\u4e92\u8054\u7f51\u4e1a\u52a1\u7684\u6570\u636e\u6b63\u4ee5\u66f4\u5feb\u7684\u901f\u5ea6\u5728\u589e\u957f\uff0c\u6570\u636e\u7c7b\u578b\u8d8a\u6765\u8d8a\u4e30\u5bcc\uff0c\u8fd9\u5bf9\u6570\u636e\u5904\u7406\u7684\u901f\u5ea6\u548c\u80fd\u529b\u63d0\u51fa\u4e86\u66f4\u9ad8\u8981\u6c42\u3002Redis \u662f\u4e00\u79cd\u5f00\u6e90\u7684\u5185\u5b58\u975e\u5173\u7cfb\u578b\u6570\u636e\u5e93\uff0c\u7ed9\u5f00\u53d1\u4eba\u5458\u5e26\u6765\u7684\u4f53\u9a8c\u662f\u98a0\u8986\u6027\u7684\u3002\u5728\u81ea\u59cb\u81f3\u7ec8\u7684\u8bbe\u8ba1\u8fc7\u7a0b\u4e2d\uff0c\u90fd\u5145\u5206\u8003\u8651\u9ad8\u6027\u80fd\uff0c\u8fd9\u4f7f\u5f97 Redis \u6210\u4e3a\u5f53\u4eca\u901f\u5ea6\u6700\u5feb\u7684 NoSQL \u6570\u636e\u5e93\u3002<\/p>\n

\u8003\u8651\u9ad8\u6027\u80fd\u7684\u540c\u65f6\uff0c\u9ad8\u53ef\u7528\u4e5f\u662f\u5f88\u91cd\u8981\u7684\u8003\u8651\u56e0\u7d20\u3002\u4e92\u8054\u7f51 7\u00d724 \u65e0\u95f4\u65ad\u670d\u52a1\uff0c\u5728\u6545\u969c\u671f\u95f4\u4ee5\u6700\u5feb\u7684\u901f\u5ea6 Failover\uff0c\u80fd\u7ed9\u4f01\u4e1a\u5e26\u6765\u6700\u5c0f\u7684\u635f\u5931\u3002<\/p>\n

\u90a3\u4e48\uff0c\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u90fd\u6709\u54ea\u4e9b\u9ad8\u53ef\u7528\u67b6\u6784\u5462\uff1f\u67b6\u6784\u4e4b\u95f4\u6709\u4f55\u4f18\u52a3\uff1f\u6211\u4eec\u5e94\u8be5\u600e\u4e48\u53d6\u820d\uff1f\u6709\u54ea\u4e9b\u6700\u4f73\u5b9e\u8df5\uff1f<\/p>\n

0\u00d702 Sentinel \u539f\u7406<\/strong><\/div>\n

\u5728\u8bb2\u89e3 Redis \u9ad8\u53ef\u7528\u65b9\u6848\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u6765\u770b\u770b\u00a0Redis Sentinel<\/a>\u00a0\u539f\u7406<\/strong>\u662f\u600e\u4e48\u6837\u7684\u3002<\/p>\n

    \n
  1. Sentinel \u96c6\u7fa4\u901a\u8fc7\u7ed9\u5b9a\u7684\u914d\u7f6e\u6587\u4ef6\u53d1\u73b0 master\uff0c\u542f\u52a8\u65f6\u4f1a\u76d1\u63a7 master\u3002\u901a\u8fc7\u5411 master \u53d1\u9001 info \u4fe1\u606f\u83b7\u5f97\u8be5\u670d\u52a1\u5668\u4e0b\u9762\u7684\u6240\u6709\u4ece\u670d\u52a1\u5668\u3002<\/li>\n
  2. Sentinel \u96c6\u7fa4\u901a\u8fc7\u547d\u4ee4\u8fde\u63a5\u5411\u88ab\u76d1\u89c6\u7684\u4e3b\u4ece\u670d\u52a1\u5668\u53d1\u9001 hello \u4fe1\u606f (\u6bcf\u79d2\u4e00\u6b21)\uff0c\u8be5\u4fe1\u606f\u5305\u62ec Sentinel \u672c\u8eab\u7684 IP\u3001\u7aef\u53e3\u3001id \u7b49\u5185\u5bb9\uff0c\u4ee5\u6b64\u6765\u5411\u5176\u4ed6 Sentinel \u5ba3\u544a\u81ea\u5df1\u7684\u5b58\u5728\u3002<\/li>\n
  3. Sentinel \u96c6\u7fa4\u901a\u8fc7\u8ba2\u9605\u8fde\u63a5\u63a5\u6536\u5176\u4ed6 Sentinel \u53d1\u9001\u7684 hello \u4fe1\u606f\uff0c\u4ee5\u6b64\u6765\u53d1\u73b0\u76d1\u89c6\u540c\u4e00\u4e2a\u4e3b\u670d\u52a1\u5668\u7684\u5176\u4ed6 Sentinel\uff1b\u96c6\u7fa4\u4e4b\u95f4\u4f1a\u4e92\u76f8\u521b\u5efa\u547d\u4ee4\u8fde\u63a5\u7528\u4e8e\u901a\u4fe1\uff0c\u56e0\u4e3a\u5df2\u7ecf\u6709\u4e3b\u4ece\u670d\u52a1\u5668\u4f5c\u4e3a\u53d1\u9001\u548c\u63a5\u6536 hello \u4fe1\u606f\u7684\u4e2d\u4ecb\uff0cSentinel \u4e4b\u95f4\u4e0d\u4f1a\u521b\u5efa\u8ba2\u9605\u8fde\u63a5\u3002<\/li>\n
  4. Sentinel \u96c6\u7fa4\u4f7f\u7528 ping \u547d\u4ee4\u6765\u68c0\u6d4b\u5b9e\u4f8b\u7684\u72b6\u6001\uff0c\u5982\u679c\u5728\u6307\u5b9a\u7684\u65f6\u95f4\u5185\uff08down-after-milliseconds\uff09\u6ca1\u6709\u56de\u590d\u6216\u5219\u8fd4\u56de\u9519\u8bef\u7684\u56de\u590d\uff0c\u90a3\u4e48\u8be5\u5b9e\u4f8b\u88ab\u5224\u4e3a\u4e0b\u7ebf\u3002<\/li>\n
  5. \u5f53 failover \u4e3b\u5907\u5207\u6362\u88ab\u89e6\u53d1\u540e\uff0cfailover \u5e76\u4e0d\u4f1a\u9a6c\u4e0a\u8fdb\u884c\uff0c\u8fd8\u9700\u8981 Sentinel \u4e2d\u7684\u5927\u591a\u6570 Sentinel \u6388\u6743\u540e\u624d\u53ef\u4ee5\u8fdb\u884c failover\uff0c\u5373\u8fdb\u884c failover \u7684 Sentinel \u4f1a\u53bb\u83b7\u5f97\u6307\u5b9a quorum \u4e2a\u7684 Sentinel \u7684\u6388\u6743\uff0c\u6210\u529f\u540e\u8fdb\u5165 ODOWN \u72b6\u6001\u3002\u5982\u5728 5 \u4e2a Sentinel \u4e2d\u914d\u7f6e\u4e86 2 \u4e2a quorum\uff0c\u7b49\u5230 2 \u4e2a Sentinel \u8ba4\u4e3a master \u6b7b\u4e86\u5c31\u6267\u884c failover\u3002<\/li>\n
  6. Sentinel \u5411\u9009\u4e3a master \u7684 slave \u53d1\u9001 SLAVEOF NO ONE \u547d\u4ee4\uff0c\u9009\u62e9 slave \u7684\u6761\u4ef6\u662f Sentinel \u9996\u5148\u4f1a\u6839\u636e slaves \u7684\u4f18\u5148\u7ea7\u6765\u8fdb\u884c\u6392\u5e8f\uff0c\u4f18\u5148\u7ea7\u8d8a\u5c0f\u6392\u540d\u8d8a\u9760\u524d\u3002\u5982\u679c\u4f18\u5148\u7ea7\u76f8\u540c\uff0c\u5219\u67e5\u770b\u590d\u5236\u7684\u4e0b\u6807\uff0c\u54ea\u4e2a\u4ece master \u63a5\u6536\u7684\u590d\u5236\u6570\u636e\u591a\uff0c\u54ea\u4e2a\u5c31\u9760\u524d\u3002\u5982\u679c\u4f18\u5148\u7ea7\u548c\u4e0b\u6807\u90fd\u76f8\u540c\uff0c\u5c31\u9009\u62e9\u8fdb\u7a0b ID \u8f83\u5c0f\u7684\u3002<\/li>\n
  7. Sentinel \u88ab\u6388\u6743\u540e\uff0c\u5b83\u5c06\u4f1a\u83b7\u5f97\u5b95\u6389\u7684 master \u7684\u4e00\u4efd\u6700\u65b0\u914d\u7f6e\u7248\u672c\u53f7 (config-epoch)\uff0c\u5f53 failover \u6267\u884c\u7ed3\u675f\u4ee5\u540e\uff0c\u8fd9\u4e2a\u7248\u672c\u53f7\u5c06\u4f1a\u88ab\u7528\u4e8e\u6700\u65b0\u7684\u914d\u7f6e\uff0c\u901a\u8fc7\u5e7f\u64ad\u5f62\u5f0f\u901a\u77e5\u5176\u5b83 Sentinel\uff0c\u5176\u5b83\u7684 Sentinel \u5219\u66f4\u65b0\u5bf9\u5e94 master \u7684\u914d\u7f6e\u3002<\/li>\n<\/ol>\n

    1 \u5230 3 \u662f\u81ea\u52a8\u53d1\u73b0\u673a\u5236:<\/p>\n