{"id":44012,"date":"2024-12-01T15:18:29","date_gmt":"2024-12-01T07:18:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/44012\/"},"modified":"2024-12-01T15:18:29","modified_gmt":"2024-12-01T07:18:29","slug":"%e4%bb%8e%e5%8d%95%e7%82%b9-redis-%e5%88%b0-1-%e4%b8%bb-2-%e4%bb%8e-3-%e5%93%a8%e5%85%b5%e7%9a%84%e6%9e%b6%e6%9e%84%e6%bc%94%e8%bf%9b%e4%b9%8b%e8%b7%af","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/44012\/","title":{"rendered":"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def<\/h1>\n<p><span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u6765\u5230golang\u5b66\u4e60\u7f51\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6570\u636e\u5e93\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300a\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\u670d\u52a1\u5668\u3001Redis\u3001\u67b6\u6784\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<h2>\u200b\u4e00\u3001\u524d\u8a00<\/h2>\n<p>\u6211\u4eec\u6709\u4e2a\u9879\u76ee\u4e2d\u7528\u7684 MySQL\u3001Redis\u3001ES\u3001\u5fae\u670d\u52a1\u90fd\u662f\u5355\u8282\u70b9\u90e8\u7f72\u7684\uff0c\u6ca1\u6709\u505a\u96c6\u7fa4\u6a21\u5f0f\u90e8\u7f72\uff0c\u4e3a\u4e86\u63d0\u9ad8\u6574\u4f53\u7684\u53ef\u7528\u6027\uff0c\u5bf9\u9879\u76ee\u7684\u90e8\u7f72\u67b6\u6784\u8fdb\u884c\u4e86\u5347\u7ea7\uff0c\u652f\u6301\u9ad8\u53ef\u7528\u3002<\/p>\n<p>\u901a\u8fc7\u672c\u7bc7\uff0c\u4f60\u53ef\u4ee5\u5b66\u5230\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<blockquote style=\"margin-top: 5px;margin-bottom: 5px;padding-left: 1em;margin-left: 0px;opacity: 0.6\">\n<ul>\n<li>Redis\u771f\u5b9e\u7684\u591a\u670d\u52a1\u5668\u90e8\u7f72\u5b9e\u6218<\/li>\n<li>Redis\u771f\u5b9e\u7684\u4e3b\u4ece\u6a21\u5f0f\u90e8\u7f72\u5b9e\u6218\u3002<\/li>\n<li>Redis\u771f\u5b9e\u7684\u54e8\u5175\u96c6\u7fa4\u6a21\u5f0f\u90e8\u7f72\u5b9e\u6218\u3002<\/li>\n<li>Redis \u4e3b\u8282\u70b9\u5b95\u673a\u540e\uff0cRedis \u54e8\u5175\u5982\u4f55\u8fdb\u884c\u6545\u969c\u8f6c\u79fb\u7684\u3002<\/li>\n<\/ul>\n<\/blockquote>\n<ul>\n<li>Redis \u5207\u6362\u4e3b\u8282\u70b9\u540e\uff0c\u5ba2\u6237\u7aef\u5982\u4f55\u81ea\u52a8\u611f\u77e5\u5e76\u8fde\u63a5\u65b0\u7684\u4e3b\u8282\u70b9\u3002<\/li>\n<\/ul>\n<h2>\u4e8c\u3001\u90e8\u7f72\u62d3\u6251\u56fe<\/h2>\n<p>\u6211\u4eec\u9879\u76ee\u7684\u6d4b\u8bd5\u73af\u5883 12 \u53f0\u670d\u52a1\u5668\u5df2\u7ecf\u90e8\u7f72\u597d\u4e86\uff0c\u5176\u4e2d\u4e09\u53f0\u7528\u6765\u90e8\u7f72 Redis \u7684 \u4e00\u4e3b + \u4e24\u4ece + \u4e09\u54e8\u5175\u7684\u670d\u52a1\u5668\u3002\u670d\u52a1\u5668\u8d44\u6e90\u6e05\u5355\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230108\/167315490263ba51565e707.png\" style=\"max-width:100%\" class=\"aligncenter\" title=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe\" alt=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe\" \/> <\/p>\n<p>\u53e6\u5916 Redis \u7684\u7aef\u53e3\u90fd\u662f 6379\uff0cSentinel\uff08\u54e8\u5175\uff09 \u7684\u7aef\u53e3\u90fd\u662f&nbsp;26379\u3002<\/p>\n<p>\u90e8\u7f72\u7684\u62d3\u6251\u56fe\u5982\u4e0b\uff0c\u4e09\u53f0\u670d\u52a1\u5668\u4e0a\u90fd\u90e8\u7f72\u4e86\u4e00\u4e2a\u54e8\u5175\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230108\/167315490263ba5156b434f.png\" style=\"max-width:100%\" class=\"aligncenter\" title=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe1\" alt=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe1\" \/> <\/p>\n<h2>\u4e09\u3001\u642d\u5efa Redis \u4e00\u4e3b\u4e24\u4ece<\/h2>\n<p>\u6211\u4eec\u539f\u6765\u7684\u5355\u70b9\u7684\u670d\u52a1\u5668\u4e0a\u662f\u6709\u8fd0\u884c\u7684 Redis \u5bb9\u5668\u7684\uff0c\u628a\u8fd9\u4e2a\u5bb9\u5668\u7684\u955c\u50cf\u6253\u5305\u5907\u4efd\u4e0b\uff0c\u7136\u540e\u62f7\u8d1d\u548c\u8fd8\u539f\u5230\u65b0\u7684\u670d\u52a1\u5668\u4e0a\u5c31\u597d\u4e86\u3002<\/p>\n<p>\u642d\u5efa Redis \u4e00\u4e3b\u4e24\u4ece\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u62f7\u8d1d\u548c\u8fd8\u539f Redis \u955c\u50cf\u5230\u4e09\u53f0\u670d\u52a1\u5668\u4e0a\u3002<\/li>\n<li>\u5176\u4e2d\u4e00\u53f0\u670d\u52a1\u5668\u4f5c\u4e3a\u4e3b\u8282\u70b9\uff0c\u914d\u7f6e\u6587\u4ef6\u4e3a\u4e3b\u8282\u70b9\u7684\uff0c\u7528 docker \u542f\u52a8 Redis \u4e3b\u8282\u70b9\u3002<\/li>\n<li>\u53e6\u5916\u4e24\u53f0\u670d\u52a1\u5668\u4f5c\u4e3a\u4ece\u8282\u70b9\uff0c\u914d\u7f6e\u6587\u4ef6\u4e3a\u4ece\u8282\u70b9\u7684\uff0c\u7528 docker \u542f\u52a8\u4e24\u4e2a Redis \u4ece\u8282\u70b9\u3002<\/li>\n<li>\u8fdb\u5165\u5230\u4e3b\u8282\u70b9\u548c\u4ece\u8282\u70b9\u5bb9\u5668\u4e2d\uff0c\u67e5\u770b\u4e3b\u4ece\u590d\u5236\u72b6\u6001\u3002<\/li>\n<\/ul>\n<h3>1.\u5907\u4efd\u548c\u8fd8\u539f Redis \u955c\u50cf<\/h3>\n<p>\u6253\u5305\u6d4b\u8bd5\u73af\u5883\u7684 Redis \u955c\u50cf\uff0c\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06\u670d\u52a1\u5668\u4e0a redis \u955c\u50cf\u6253\u5305\u6210 tar \u5305\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u65b9\u4fbf\u62f7\u8d1d\u5230\u5176\u4ed6\u670d\u52a1\u5668\u4e0a\u4e86\u3002\u6267\u884c\u6253\u5305\u955c\u50cf\u547d\u4ee4\uff1a<\/p>\n<p>sudo docker save <span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>o redis<span style=\"margin: 0px;padding: 0px\">.tar<\/span> redis<span style=\"margin: 0px;padding: 0px\">:<\/span><span style=\"margin: 0px;padding: 0px\">0.1<\/span><\/p>\n<p>\u56e0\u4e3a\u4fdd\u5b58\u7684 tar \u5305\u6743\u9650\u4e0d\u591f\uff0c\u6240\u4ee5\u8bbe\u7f6e\u4e0b\u6743\u9650\u4e3a 777\u3002\u6267\u884c\u4fee\u6539\u6743\u9650\u7684\u547d\u4ee4\uff1a<\/p>\n<p>sudo chmod <span style=\"margin: 0px;padding: 0px\">777<\/span> redis<span style=\"margin: 0px;padding: 0px\">.tar<\/span><\/p>\n<p>\u5c06\u8fd9\u4e2a tar \u5305\u62f7\u8d1d\u65b0\u73af\u5883\u7684\u4e09\u53f0\u670d\u52a1\u5668\u4e0a\u3002\u6267\u884c\u5bfc\u5165\u955c\u50cf\u7684\u547d\u4ee4\uff1a<\/p>\n<p>sudo docker load <span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>i redis<span style=\"margin: 0px;padding: 0px\">.tar<\/span><\/p>\n<p>\u6dfb\u52a0\u914d\u7f6e\u6587\u4ef6 redis.conf \u653e\u5728\u672c\u5730\uff0c\u4f5c\u4e3a redis \u5bb9\u5668\u7684\u914d\u7f6e\u6587\u4ef6\u3002\u8fd9\u4e2a\u6587\u4ef6\u4e5f\u53ef\u4ee5\u5728 redis \u5b98\u7f51\u4e0b\u8f7d https:\/\/redis.io\/\u3002redis.conf \u6587\u4ef6\u653e\u5230 \/home\/redis \u76ee\u5f55\u4e0b\u3002<\/p>\n<p>sudo mkdir \/home\/redis<\/p>\n<h3>2.\u4e3b\u8282\u70b9\u914d\u7f6e<\/h3>\n<p>\u4fee\u6539\u672c\u5730\u7684 redis.conf \u6587\u4ef6\uff1a<\/p>\n<p>requirepass abc123<br \/>masterauth abc123<\/p>\n<p>requirepass&nbsp;\u548c&nbsp;masterauth\uff1a\u5bf9\u4e8e\u6570\u636e\u6bd4\u8f83\u91cd\u8981\u7684\u8282\u70b9\uff0c\u4e3b\u8282\u70b9\u4f1a\u901a\u8fc7\u8bbe\u7f6erequirepass\u53c2\u6570\u8fdb\u884c\u5bc6\u7801 \u9a8c\u8bc1\uff0c\u8fd9\u65f6\u6240\u6709\u7684\u5ba2\u6237\u7aef\u8bbf\u95ee\u5fc5\u987b\u4f7f\u7528auth\u547d\u4ee4\u5b9e\u884c\u6821\u9a8c\u3002\u4ece\u8282\u70b9\u4e0e\u4e3b\u8282\u70b9 \u7684\u590d\u5236\u8fde\u63a5\u662f\u901a\u8fc7\u4e00\u4e2a\u7279\u6b8a\u6807\u8bc6\u7684\u5ba2\u6237\u7aef\u6765\u5b8c\u6210\uff0c\u56e0\u6b64\u9700\u8981\u914d\u7f6e\u4ece\u8282\u70b9\u7684 masterauth\u53c2\u6570\u4e0e\u4e3b\u8282\u70b9\u5bc6\u7801\u4fdd\u6301\u4e00\u81f4\uff0c\u8fd9\u6837\u4ece\u8282\u70b9\u624d\u53ef\u4ee5\u6b63\u786e\u5730\u8fde\u63a5\u5230\u4e3b \u8282\u70b9\u5e76\u53d1\u8d77\u590d\u5236\u6d41\u7a0b\u3002<\/p>\n<h3>3.\u4ece\u8282\u70b9\u914d\u7f6e<\/h3>\n<p>slave<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>read<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>only yes<br \/>requirepass abc123<br \/>masterauth abc123<br \/>slaveof <span style=\"margin: 0px;padding: 0px\">10.2<\/span><span style=\"margin: 0px;padding: 0px\">.1<\/span><span style=\"margin: 0px;padding: 0px\">.61<\/span> <span style=\"margin: 0px;padding: 0px\">6379<\/span><br \/><span style=\"margin: 0px;padding: 0px\">1.4<\/span> \u542f\u52a8\u5bb9\u5668<\/p>\n<h3>4.\u542f\u52a8\u5bb9\u5668<\/h3>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\u9700\u8981\u6620\u5c04\u672c\u5730\u6587\u4ef6\u5939\u3002<\/p>\n<p>sudo docker run <span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>p <span style=\"margin: 0px;padding: 0px\">6379<\/span><span style=\"margin: 0px;padding: 0px\">:<\/span><span style=\"margin: 0px;padding: 0px\">6379<\/span> <span style=\"margin: 0px;padding: 0px\">&#8211;restart=always &#8211;name redis \\<\/span><br \/><span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>v <span style=\"margin: 0px;padding: 0px\">\/<\/span>home<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">.conf<\/span><span style=\"margin: 0px;padding: 0px\">:<\/span><span style=\"margin: 0px;padding: 0px\">\/<\/span>usr<span style=\"margin: 0px;padding: 0px\">\/<\/span>local<span style=\"margin: 0px;padding: 0px\">\/<\/span>etc<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">.conf<\/span> \\<br \/><span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>v <span style=\"margin: 0px;padding: 0px\">\/<\/span>home<span style=\"margin: 0px;padding: 0px\">\/<\/span>redisdata<span style=\"margin: 0px;padding: 0px\">:<\/span><span style=\"margin: 0px;padding: 0px\">\/<\/span>data<span style=\"margin: 0px;padding: 0px\">\/<\/span> \\<br \/><span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>d <span style=\"margin: 0px;padding: 0px\">301<\/span><\/p>\n<p>-v \u4ee3\u8868\u6620\u5c04\u7684\u6587\u4ef6\u6216\u6587\u4ef6\u5939\uff0c\u8fd9\u91cc\u6620\u5c04\u4e86 redis.conf \u6587\u4ef6\u548c data \u76ee\u5f55\u3002data \u76ee\u5f55\u4f1a\u5b58\u653e Redis \u7684&nbsp;AOF\u200b&nbsp;\u548c&nbsp;RDB&nbsp;\u6301\u4e45\u5316\u6587\u4ef6\u3002<\/p>\n<p>-d \u8868\u793a\u540e\u53f0\u8fd0\u884c\uff0c46b \u4ee3\u8868\u955c\u50cf id\u3002\u56e0\u4e3a\u6211\u4eec\u670d\u52a1\u5668\u662f\u6ca1\u6709\u5916\u7f51\u7684\uff0c\u6240\u4ee5\u7528\u7684\u662f\u672c\u5730\u955c\u50cf\u542f\u52a8\u7684\uff0c\u5982\u679c\u4f60\u7684\u670d\u52a1\u5668\u6709\u5916\u7f51\uff0c\u5b8c\u5168\u53ef\u4ee5\u7528\u5b98\u7f51\u7684 redis \u955c\u50cf\u542f\u52a8\u3002<\/p>\n<h3>5.\u67e5\u770b Redis \u72b6\u6001<\/h3>\n<p>\u8fdb\u5165\u5bb9\u5668\uff0c\u8fde\u63a5 redis\uff0cnode1\u7684 redis \u5bc6\u7801\u662f abc123\u3002<\/p>\n<p># \u67e5\u8be2\u5bb9\u5668 id<br \/>docker ps<\/p>\n<p># \u8fdb\u5165 mysql \u5bb9\u5668<br \/>docker exec <span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>it <span style=\"margin: 0px;padding: 0px\">\u5bb9\u5668 id<span style=\"margin: 0px;padding: 0px\">&gt;<\/span> <span style=\"margin: 0px;padding: 0px\">\/<\/span>bin<span style=\"margin: 0px;padding: 0px\">\/<\/span>bash<\/p>\n<p># \u8fde\u63a5 redis<br \/>redis<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>cli <span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>h localhost <span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>p <span style=\"margin: 0px;padding: 0px\">6379<\/span> <span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>a abc123<\/p>\n<p># \u67e5\u770b\u590d\u5236\u4fe1\u606f <br \/>info replication<\/span><\/p>\n<p>\u53ea\u542f\u52a8 node1 \u65f6\u67e5\u770b redis \u590d\u5236\u4fe1\u606f<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230108\/167315490363ba51570c3fd.png\" style=\"max-width:100%\" class=\"aligncenter\" title=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe2\" alt=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe2\" \/> <\/p>\n<p>\u53ef\u4ee5\u770b\u5230 role:master \u4fe1\u606f\uff0c\u4ee3\u8868\u5f53\u524d\u8282\u70b9\u4f5c\u4e3a\u4e3b\u8282\u70b9\u3002<\/p>\n<p>connected_slaves:0 \u4ee3\u8868\u8fde\u63a5\u7684\u4ece\u8282\u70b9\u4e3a 0 \u4e2a\u3002<\/p>\n<p>\u5f53\u4e09\u4e2a\u8282\u70b9\u7684 redis \u5bb9\u5668\u90fd\u542f\u52a8\u540e\uff0c\u518d\u6b21\u67e5\u770b\u4e3b\u8282\u70b9\u7684\u590d\u5236\u4fe1\u606f\u3002\u53d1\u73b0\u6709 connected_slaves:2 \u6709\u4e24\u4e2a\u4ece\u8282\u70b9\u8fde\u4e0a\u4e86\u3002<\/p>\n<p>[\u5916\u94fe\u56fe\u7247\u8f6c\u5b58\u5931\u8d25,\u6e90\u7ad9\u53ef\u80fd\u6709\u9632\u76d7\u94fe\u673a\u5236,\u5efa\u8bae\u5c06\u56fe\u7247\u4fdd\u5b58\u4e0b\u6765\u76f4\u63a5\u4e0a\u4f20(img-QPHj8Ohi-1654673955923)(..\/..\/images\/image-20220608111236463.png)]<\/p>\n<p>\u7136\u540e\u6211\u4eec\u8fdb\u5165\u5230\u4ece\u8282\u70b9\u5bb9\u5668\uff0c\u67e5\u770b\u4ece\u8282\u70b9\u7684\u590d\u5236\u4fe1\u606f\u3002<\/p>\n<p>\u53d1\u73b0 role:slave\uff0c\u8bf4\u660e\u6b64\u8282\u70b9\u4f5c\u4e3a\u4ece\u8282\u70b9\u3002<\/p>\n<p>master_host:10.2.1.61\uff0c\u8bf4\u660e\u4e86\u4e3b\u8282\u70b9\u7684 IP \u662f 10.2.1.61\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230108\/167315490363ba515772552.png\" style=\"max-width:100%\" class=\"aligncenter\" title=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe3\" alt=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe3\" \/> <\/p>\n<h3>6.\u6d4b\u8bd5\u4e3b\u4ece\u590d\u5236<\/h3>\n<p>\u6211\u4eec\u53ef\u4ee5\u7528 Redis Desktop \u5de5\u5177\u6d4b\u8bd5\u4e3b\u4ece\u6570\u636e\u662f\u5426\u4e00\u81f4\u3002\u5728\u4e3b\u8282\u70b9\u4e2d\u5199\u5165 abc=\u5f53\u524d\u65f6\u95f4\uff0c\u53d1\u73b0\u53e6\u5916\u4e24\u4e2a\u4ece\u8282\u70b9\u4e5f\u540c\u6b65\u4e86\u8fd9\u4e2a\u6570\u636e\uff0c\u8bf4\u660e\u4e3b\u4ece\u590d\u5236\u6210\u529f\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230108\/167315490363ba5157b647d.png\" style=\"max-width:100%\" class=\"aligncenter\" title=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe4\" alt=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe4\" \/> <\/p>\n<h2>\u56db\u3001\u642d\u5efa\u54e8\u5175\u96c6\u7fa4<\/h2>\n<h3>1.\u54e8\u5175\u96c6\u7fa4\u62d3\u6251\u56fe<\/h3>\n<p>\u4e09\u53f0\u673a\u5668\u4e0a\u5206\u522b\u90e8\u7f72\u4e09\u4e2a\u54e8\u5175\u670d\u52a1\u3002\u90e8\u7f72\u62d3\u6251\u56fe\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230108\/167315490463ba515811de8.png\" style=\"max-width:100%\" class=\"aligncenter\" title=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe5\" alt=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe5\" \/> <\/p>\n<h3>2.\u54e8\u5175\u670d\u52a1\u662f\u600e\u4e48\u542f\u52a8\u7684<\/h3>\n<p>\u5176\u5b9e\u54e8\u5175\u670d\u52a1\u4e5f\u662f\u7528 Redis \u5bb9\u5668\u542f\u52a8\u7684\uff0c\u53ea\u662f\u7528\u7684\u4e0d\u540c\u547d\u4ee4\u7684\u542f\u52a8\u7684\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5728 redis \u5bb9\u5668\u4e2d\u6267\u884c\u5982\u4e0b\u547d\u4ee4\u542f\u52a8\u54e8\u5175\u670d\u52a1\u3002<\/p>\n<p>redis<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>sentinel <span style=\"margin: 0px;padding: 0px\">\/<\/span>usr<span style=\"margin: 0px;padding: 0px\">\/<\/span>local<span style=\"margin: 0px;padding: 0px\">\/<\/span>etc<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">.conf<\/span><\/p>\n<p>\u56e0\u4e3a\u6211\u4eec\u662f\u901a\u8fc7 docker \u542f\u52a8\u7684\uff0c\u6240\u4ee5\u5728\u542f\u52a8 docker \u5bb9\u5668\u65f6\uff0c\u5e26\u4e0a\u8fd9\u4e2a\u547d\u4ee4\u53c2\u6570\u5c31\u53ef\u4ee5\u542f\u52a8\u54e8\u5175\u670d\u52a1\u4e86\uff0c\u5c31\u4e0d\u7528\u5230\u5bb9\u5668\u91cc\u9762\u6267\u884c\u8fd9\u4e2a\u547d\u4ee4\u4e86\u3002<\/p>\n<h3>3.\u54e8\u5175\u914d\u7f6e<\/h3>\n<p>\u9996\u5148\u521b\u5efa\u4e24\u4e2a\u6620\u5c04\u6587\u4ef6\uff1asentinel.conf \u548c sentinel-26379.log\uff0c\u7b2c\u4e00\u4e2a\u662f\u914d\u7f6e\u54e8\u5175\u53c2\u6570\u7684\uff0c\u7b2c\u4e8c\u4e2a\u6587\u4ef6\u662f\u54e8\u5175\u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u8fd9\u4e24\u4e2a\u6587\u4ef6\u90fd\u4f1a\u5728\u542f\u52a8 redis \u5bb9\u5668\u65f6\uff0c\u6620\u5c04\u5230\u5bb9\u5668\u4e2d\uff0c\u65b9\u4fbf\u6211\u4eec\u4fee\u6539\u914d\u7f6e\u4ee5\u53ca\u67e5\u770b\u65e5\u5fd7\u3002<\/p>\n<p>sentinel.conf \u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u53ef\u4ee5\u4ece\u5b98\u65b9\u7684 redis \u5b89\u88c5\u5305\u4e2d\u62f7\u8d1d\uff0c\u4e5f\u53ef\u4ee5\u81ea\u5df1\u521b\u5efa\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u4fee\u6539\u51e0\u4e2a\u53c2\u6570\u5c31\u53ef\u4ee5\u4e86\u3002\u53ef\u4ee5\u76f4\u63a5\u62f7\u8d1d\u6211\u7684\u914d\u7f6e\u3002<\/p>\n<p>mkdir <span style=\"margin: 0px;padding: 0px\">\/<\/span>home<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<br \/>vim <span style=\"margin: 0px;padding: 0px\">\/<\/span>home<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">.conf<\/span><\/p>\n<p>\u914d\u7f6e\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<p># sentile \u7aef\u53e3<br \/>port <span style=\"margin: 0px;padding: 0px\">26379<\/span><br \/># \u662f\u5426\u5728\u540e\u53f0\u542f\u52a8\uff0c\u9ed8\u8ba4\u4e3a no\uff0c\u6ce8\u610f\u8fd9\u91cc\u9700\u8981\u8bbe\u7f6e\u4e3a no\uff0c\u5426\u5219\u5bb9\u5668\u542f\u52a8\u4e0d\u8d77\u6765\u3002<br \/>daemonize no<br \/>pidfile <span style=\"margin: 0px;padding: 0px\">\/<\/span>var<span style=\"margin: 0px;padding: 0px\">\/<\/span>run<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">.pid<\/span><br \/># \u65e5\u5fd7\u6587\u4ef6<br \/>logfile <span style=\"margin: 0px;padding: 0px\">\/<\/span>var<span style=\"margin: 0px;padding: 0px\">\/<\/span>log<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span><span style=\"margin: 0px;padding: 0px\">26379<\/span><span style=\"margin: 0px;padding: 0px\">.log<\/span><br \/># \u5de5\u4f5c\u76ee\u5f55<br \/>dir <span style=\"margin: 0px;padding: 0px\">\/<\/span>tmp<br \/># \u76d1\u63a7 redis \u7684 IP \u548c\u7aef\u53e3\uff0c\u8fd9\u91cc\u76d1\u63a7\u7684 redis \u7684\u4e3b\u8282\u70b9<br \/>sentinel monitor mymaster <span style=\"margin: 0px;padding: 0px\">10.2<\/span><span style=\"margin: 0px;padding: 0px\">.1<\/span><span style=\"margin: 0px;padding: 0px\">.61<\/span> <span style=\"margin: 0px;padding: 0px\">6379<\/span> <span style=\"margin: 0px;padding: 0px\">2<\/span><br \/># down<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>after<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>milliseconds\uff1a\u6bcf\u4e2a Sentinel\u8282\u70b9\u90fd\u8981\u901a\u8fc7\u5b9a\u671f\u53d1\u9001 ping \u547d\u4ee4\u6765\u5224\u65adRedis\u6570\u636e\u8282\u70b9\u548c\u5176 \u4f59Sentinel\u8282\u70b9\u662f\u5426\u53ef\u8fbe\uff0c\u5982\u679c\u8d85\u8fc7\u4e86down<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>after<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>milliseconds\u914d\u7f6e\u7684\u65f6\u95f4\u4e14\u6ca1 \u6709\u6709\u6548\u7684\u56de\u590d\uff0c\u5219\u5224\u5b9a\u8282\u70b9\u4e0d\u53ef\u8fbe\uff0c<span style=\"margin: 0px;padding: 0px\">times<span style=\"margin: 0px;padding: 0px\">&gt;<\/span>\uff08\u5355\u4f4d\u4e3a\u6beb\u79d2\uff09\u5c31\u662f\u8d85\u65f6\u65f6 \u95f4\u3002\u8fd9\u4e2a\u914d\u7f6e\u662f\u5bf9\u8282\u70b9\u5931\u8d25\u5224\u5b9a\u7684\u91cd\u8981\u4f9d\u636e\u3002\u5bf9 Sentinel\u8282\u70b9\u3001\u4e3b\u8282\u70b9\u3001\u4ece\u8282\u70b9\u7684\u5931\u8d25\u5224\u5b9a\u540c\u65f6\u6709\u6548\u3002<br \/>sentinel down<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>after<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>milliseconds mymaster <span style=\"margin: 0px;padding: 0px\">30000<\/span><br \/># parallel<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>syncs \u5c31\u662f\u7528\u6765\u9650\u5236\u5728\u4e00\u6b21\u6545\u969c\u8f6c\u79fb\u4e4b\u540e\uff0c\u6bcf\u6b21\u5411\u65b0\u7684\u4e3b\u8282 \u70b9\u53d1\u8d77\u590d\u5236\u64cd\u4f5c\u7684\u4ece\u8282\u70b9\u4e2a\u6570\u3002<br \/>sentinel parallel<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>syncs mymaster <span style=\"margin: 0px;padding: 0px\">1<\/span><br \/># \u6545\u969c\u8f6c\u79fb\u8d85\u65f6\u65f6\u95f4<br \/>sentinel failover<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>timeout mymaster <span style=\"margin: 0px;padding: 0px\">180000<\/span><br \/>sentinel deny<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>scripts<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>reconfig yes<br \/># \u5f53 redis \u4e3b\u4ece\u590d\u5236\u914d\u7f6e\u4e86\u5bc6\u7801\u7684\u8bdd\uff0c\u5219\u9700\u8981\u5728\u8fd9\u91cc\u914d\u7f6e\u5bc6\u7801<br \/>sentinel auth<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>pass mymaster WHredis2020<span style=\"margin: 0px;padding: 0px\">!<\/span><\/span><\/p>\n<ul>\n<li>daemonize\uff1a\u662f\u5426\u5728\u540e\u53f0\u542f\u52a8\uff0c\u9ed8\u8ba4\u4e3a no\uff0c\u6ce8\u610f\u8fd9\u91cc\u9700\u8981\u8bbe\u7f6e\u4e3a no\uff0c\u5426\u5219\u5bb9\u5668\u542f\u52a8\u4e0d\u8d77\u6765\u3002<\/li>\n<li>logfile\uff1a\u65e5\u5fd7\u6587\u4ef6\uff0c\u54e8\u5175\u76d1\u63a7\u548c\u6545\u969c\u8f6c\u79fb\u7684\u65e5\u5fd7\u90fd\u4f1a\u5b58\u5230\u8fd9\u4e2a\u65e5\u5fd7\u91cc\u9762\u3002<\/li>\n<li>sentinel monitor mymaster\uff1a\u76d1\u63a7 redis \u7684 IP \u548c\u7aef\u53e3\uff0c\u8fd9\u91cc\u76d1\u63a7\u7684 redis \u7684\u4e3b\u8282\u70b9\u3002<\/li>\n<li>down-after-milliseconds\uff1a\u6bcf\u4e2a Sentinel\u8282\u70b9\u90fd\u8981\u901a\u8fc7\u5b9a\u671f\u53d1\u9001 ping \u547d\u4ee4\u6765\u5224\u65adRedis\u6570\u636e\u8282\u70b9\u548c\u5176 \u4f59Sentinel\u8282\u70b9\u662f\u5426\u53ef\u8fbe\uff0c\u5982\u679c\u8d85\u8fc7\u4e86down-after-milliseconds\u914d\u7f6e\u7684\u65f6\u95f4\u4e14\u6ca1 \u6709\u6709\u6548\u7684\u56de\u590d\uff0c\u5219\u5224\u5b9a\u8282\u70b9\u4e0d\u53ef\u8fbe\uff0c\uff08\u5355\u4f4d\u4e3a\u6beb\u79d2\uff09\u5c31\u662f\u8d85\u65f6\u65f6\u95f4\u3002\u8fd9\u4e2a\u914d\u7f6e\u662f\u5bf9\u8282\u70b9\u5931\u8d25\u5224\u5b9a\u7684\u91cd\u8981\u4f9d\u636e\u3002\u5bf9 Sentinel\u8282\u70b9\u3001\u4e3b\u8282\u70b9\u3001\u4ece\u8282\u70b9\u7684\u5931\u8d25\u5224\u5b9a\u540c\u65f6\u6709\u6548\u3002<\/li>\n<li>parallel-syncs\uff1a\u5c31\u662f\u7528\u6765\u9650\u5236\u5728\u4e00\u6b21\u6545\u969c\u8f6c\u79fb\u4e4b\u540e\uff0c\u6bcf\u6b21\u5411\u65b0\u7684\u4e3b\u8282 \u70b9\u53d1\u8d77\u590d\u5236\u64cd\u4f5c\u7684\u4ece\u8282\u70b9\u4e2a\u6570\u3002<\/li>\n<li>failover-timeout\uff1a\u6545\u969c\u8f6c\u79fb\u8d85\u65f6\u65f6\u95f4\u3002<\/li>\n<li>auth-pass\uff1a\u5f53 redis \u4e3b\u4ece\u590d\u5236\u914d\u7f6e\u4e86\u5bc6\u7801\u7684\u8bdd\uff0c\u5219\u9700\u8981\u5728\u8fd9\u91cc\u914d\u7f6e\u5bc6\u7801\u3002<\/li>\n<\/ul>\n<p>\u9996\u5148\u5728\u672c\u5730\u521b\u5efa\u65e5\u5fd7\u6587\u4ef6\u7528\u6765\u5b58\u653e\u54e8\u5175\u65e5\u5fd7\u3002<\/p>\n<p>mkdir <span style=\"margin: 0px;padding: 0px\">\/<\/span>home<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<br \/>vim <span style=\"margin: 0px;padding: 0px\">\/<\/span>home<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span><span style=\"margin: 0px;padding: 0px\">26379<\/span><span style=\"margin: 0px;padding: 0px\">.log<\/span><\/p>\n<h3>4.\u542f\u52a8\u54e8\u5175\u5bb9\u5668<\/h3>\n<h4>4.1 \u542f\u52a8\u4e00\u4e2a sentinel \u5bb9\u5668<\/h4>\n<p>docker run <span style=\"margin: 0px;padding: 0px\">&#8211;name mysentinel1 &#8211;restart=always -p 26379:26379 \\<\/span><br \/><span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>v <span style=\"margin: 0px;padding: 0px\">\/<\/span>home<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">.conf<\/span><span style=\"margin: 0px;padding: 0px\">:<\/span><span style=\"margin: 0px;padding: 0px\">\/<\/span>usr<span style=\"margin: 0px;padding: 0px\">\/<\/span>local<span style=\"margin: 0px;padding: 0px\">\/<\/span>etc<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">.conf<\/span> \\<br \/><span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>v <span style=\"margin: 0px;padding: 0px\">\/<\/span>home<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span><span style=\"margin: 0px;padding: 0px\">26379<\/span><span style=\"margin: 0px;padding: 0px\">.log<\/span><span style=\"margin: 0px;padding: 0px\">:<\/span><span style=\"margin: 0px;padding: 0px\">\/<\/span>var<span style=\"margin: 0px;padding: 0px\">\/<\/span>log<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span><span style=\"margin: 0px;padding: 0px\">26379<\/span><span style=\"margin: 0px;padding: 0px\">.log<\/span> \\<br \/><span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>d <span style=\"margin: 0px;padding: 0px\">9<\/span>a2f \\<br \/>redis<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>sentinel <span style=\"margin: 0px;padding: 0px\">\/<\/span>usr<span style=\"margin: 0px;padding: 0px\">\/<\/span>local<span style=\"margin: 0px;padding: 0px\">\/<\/span>etc<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">.conf<\/span><\/p>\n<ul>\n<li>&#8211;name mysentinel1\uff0c\u6307\u5b9a\u54e8\u5175\u5bb9\u5668\u7684\u540d\u79f0\u4e3a mysentinel1\u3002<\/li>\n<li>&#8211;restart=always\uff0c\u91cd\u542f\u673a\u5668\u540e\uff0c\u81ea\u52a8\u91cd\u542f\u5bb9\u5668\u3002<\/li>\n<li>-v\uff0c\u6302\u8f7d\u54e8\u5175\u914d\u7f6e\u6587\u4ef6\u548c\u65e5\u5fd7\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u91cc\u7684 -d 9a2f \u662f \u672c\u5730\u7684 redis \u5bb9\u5668 id\uff0c\u56e0\u4e3a\u672c\u673a\u6ca1\u6709\u7f51\u7edc\uff0c\u6240\u4ee5\u8fd9\u4e2a\u955c\u50cf\u662f\u4ece\u5176\u4ed6\u6709\u7f51\u7edc\u7684\u673a\u5668\u52a0\u8f7d\u8fdb\u6765\u7684\u3002\u5982\u679c\u4f60\u4eec\u7684\u673a\u5668\u6709\u7f51\u7edc\uff0c\u5b8c\u5168\u53ef\u4ee5\u7528&nbsp;-d redis&nbsp;\u53c2\u6570\u66ff\u6362\uff0c\u4e5f\u5c31\u662f\u4f7f\u7528\u6700\u65b0\u7684 redis \u955c\u50cf\u6765\u542f\u52a8 sentinel\u3002<\/p>\n<p>\u67e5\u770b\u542f\u52a8\u7684\u5bb9\u5668\uff0c\u7b2c\u4e00\u4e2a\u662f\u54e8\u5175\u5bb9\u5668\uff0c\u540d\u5b57\u662f&nbsp;mysentinel1\u200b, \u7b2c\u4e8c\u4e2a\u662f redis \u5bb9\u5668\uff0c\u540d\u5b57\u662f&nbsp;redis\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230108\/167315490463ba515871f5d.png\" style=\"max-width:100%\" class=\"aligncenter\" title=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe6\" alt=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe6\" \/> <\/p>\n<p>\u5f53\u5728\u4e09\u53f0\u670d\u52a1\u5668\u4e0a\u5206\u522b\u542f\u52a8 Redis \u54e8\u5175\u540e\uff0c\u67e5\u770b\u54e8\u5175\u65e5\u5fd7\u6587\u4ef6 sentinel-26379.log\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230108\/167315490463ba5158d700c.png\" style=\"max-width:100%\" class=\"aligncenter\" title=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe7\" alt=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe7\" \/> <\/p>\n<p>\u6253\u5370\u51fa\u4e86 Redis \u7684\u5f53\u524d\u7248\u672c\uff085.0.14\uff09\uff0c\u8fd0\u884c\u6a21\u5f0f\uff08\u54e8\u5175\u6a21\u5f0f\uff09\uff0c\u7aef\u53e3\u53f7 26379\uff0c\u54e8\u5175 id\uff0c\u76d1\u63a7\u7684 Redis \u4e2d\u7684\u4e3b\u8282\u70b9\uff0c\u4e24\u4e2a Redis \u4ece\u8282\u70b9\u548c\u4e00\u4e2a\u4e3b\u8282\u70b9\u7684 IP \u548c \u7aef\u53e3\u3002<\/p>\n<p>\u800c\u4e14\u5f53\u6211\u4eec\u53bb\u67e5\u770b Sentinel \u914d\u7f6e\u6587\u4ef6\u65f6\uff0c\u53d1\u73b0\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\u53d1\u751f\u4e86\u53d8\u5316\uff0c\u5728\u6587\u4ef6\u672b\u5c3e\u8ffd\u52a0\u4e86\u4ee5\u4e0b\u5185\u5bb9\uff0c\u542b\u4e49\u5c31\u662f Sentinel \u81ea\u52a8\u53d1\u73b0\u4e86\u5176\u4ed6 Redis \u4ece\u8282\u70b9<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230108\/167315490563ba5159417b1.png\" style=\"max-width:100%\" class=\"aligncenter\" title=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe8\" alt=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe8\" \/> <\/p>\n<h4>4.2 \u542f\u52a8\u7b2c\u4e8c\u4e2a\u5bb9\u5668<\/h4>\n<p>\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8\u7b2c\u4e8c\u4e2a\u5bb9\u5668\uff1a<\/p>\n<p>docker run <span style=\"margin: 0px;padding: 0px\">&#8211;name mysentinel2 &#8211;restart=always -p 26379:26379 \\<\/span><br \/><span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>v <span style=\"margin: 0px;padding: 0px\">\/<\/span>home<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">.conf<\/span><span style=\"margin: 0px;padding: 0px\">:<\/span><span style=\"margin: 0px;padding: 0px\">\/<\/span>usr<span style=\"margin: 0px;padding: 0px\">\/<\/span>local<span style=\"margin: 0px;padding: 0px\">\/<\/span>etc<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">.conf<\/span> \\<br \/><span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>v <span style=\"margin: 0px;padding: 0px\">\/<\/span>home<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span><span style=\"margin: 0px;padding: 0px\">26379<\/span><span style=\"margin: 0px;padding: 0px\">.log<\/span><span style=\"margin: 0px;padding: 0px\">:<\/span><span style=\"margin: 0px;padding: 0px\">\/<\/span>var<span style=\"margin: 0px;padding: 0px\">\/<\/span>log<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span><span style=\"margin: 0px;padding: 0px\">26379<\/span><span style=\"margin: 0px;padding: 0px\">.log<\/span> \\<br \/><span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>d <span style=\"margin: 0px;padding: 0px\">9<\/span>a2f \\<br \/>redis<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>sentinel <span style=\"margin: 0px;padding: 0px\">\/<\/span>usr<span style=\"margin: 0px;padding: 0px\">\/<\/span>local<span style=\"margin: 0px;padding: 0px\">\/<\/span>etc<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">.conf<\/span><\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230108\/167315490563ba51598a974.png\" style=\"max-width:100%\" class=\"aligncenter\" title=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe9\" alt=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe9\" \/> <\/p>\n<h4>4.3 \u542f\u52a8\u7b2c\u4e09\u4e2a\u5bb9\u5668<\/h4>\n<p>\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8\u7b2c\u4e09\u4e2a\u5bb9\u5668\uff1a<\/p>\n<p>docker run <span style=\"margin: 0px;padding: 0px\">&#8211;name mysentinel3 &#8211;restart=always -p 26379:26379 \\<\/span><br \/><span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>v <span style=\"margin: 0px;padding: 0px\">\/<\/span>home<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">.conf<\/span><span style=\"margin: 0px;padding: 0px\">:<\/span><span style=\"margin: 0px;padding: 0px\">\/<\/span>usr<span style=\"margin: 0px;padding: 0px\">\/<\/span>local<span style=\"margin: 0px;padding: 0px\">\/<\/span>etc<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">.conf<\/span> \\<br \/><span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>v <span style=\"margin: 0px;padding: 0px\">\/<\/span>home<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span><span style=\"margin: 0px;padding: 0px\">26379<\/span><span style=\"margin: 0px;padding: 0px\">.log<\/span><span style=\"margin: 0px;padding: 0px\">:<\/span><span style=\"margin: 0px;padding: 0px\">\/<\/span>var<span style=\"margin: 0px;padding: 0px\">\/<\/span>log<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span><span style=\"margin: 0px;padding: 0px\">26379<\/span><span style=\"margin: 0px;padding: 0px\">.log<\/span> \\<br \/><span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>d <span style=\"margin: 0px;padding: 0px\">9<\/span>a2f \\<br \/>redis<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>sentinel <span style=\"margin: 0px;padding: 0px\">\/<\/span>usr<span style=\"margin: 0px;padding: 0px\">\/<\/span>local<span style=\"margin: 0px;padding: 0px\">\/<\/span>etc<span style=\"margin: 0px;padding: 0px\">\/<\/span>redis<span style=\"margin: 0px;padding: 0px\">\/<\/span>sentinel<span style=\"margin: 0px;padding: 0px\">.conf<\/span><\/p>\n<h4>4.4 \u9a8c\u8bc1 Redis \u4e3b\u4ece\u5207\u6362<\/h4>\n<p>\u505c\u6389\u4e3b\u8282\u70b9\u7684 redis \u5bb9\u5668\u540e\uff0c\u8fdb\u5165\u5230\u7b2c\u4e8c\u4e2a\u54e8\u5175\u5bb9\u5668\u4e2d\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u54e8\u5175\u7684\u72b6\u6001\uff1a<\/p>\n<p>redis<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>cli <span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>h <span style=\"margin: 0px;padding: 0px\">127.0<\/span><span style=\"margin: 0px;padding: 0px\">.0<\/span><span style=\"margin: 0px;padding: 0px\">.1<\/span> <span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>p <span style=\"margin: 0px;padding: 0px\">26379<\/span> info Sentinel <\/p>\n<p>\u53d1\u73b0\u4e3b\u8282\u70b9\u7684 IP \u5df2\u7ecf\u4ece 10.2.1.61 \u5207\u6362\u4e3a\u4ece\u8282\u70b9\u7684 IP\uff0810.2.1.63\uff09\u4e86\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230108\/167315490663ba515a173c7.png\" style=\"max-width:100%\" class=\"aligncenter\" title=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe10\" alt=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe10\" \/> <\/p>\n<p>\u8fdb\u5165\u5230\u7b2c\u4e8c\u4e2a redis \u5bb9\u5668\u4e2d\uff0c\u67e5\u770b\u540c\u6b65\u72b6\u6001\u3002\u4e3b\u8282\u70b9\u7684 IP \u4e5f\u662f 10.2.1.63<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230108\/167315490663ba515a62dc8.png\" style=\"max-width:100%\" class=\"aligncenter\" title=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe11\" alt=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe11\" \/> <\/p>\n<p>\u67e5\u770b\u7b2c\u4e09\u4e2a\u54e8\u5175\u7684\u65e5\u5fd7\uff0c\u53ef\u4ee5\u770b\u5230\u54e8\u5175\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u4e86\u4e3b\u4ece\u5207\u6362\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230108\/167315490663ba515ad4586.png\" style=\"max-width:100%\" class=\"aligncenter\" title=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe12\" alt=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe12\" \/> <\/p>\n<p>\u91cd\u8981\u7684\u6b65\u9aa4\u8bf4\u660e\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u2460\u4e3b\u89c2\u5b95\u673a\uff0c+sdown&nbsp;\u8868\u793a\u5f53\u524d\u54e8\u5175\u8ba4\u4e3a\u8fd9\u4e2a Redis \u8282\u70b9\uff0810.2.1.61\uff09\u5b95\u673a\u4e86\u3002<\/li>\n<li>\u2461\u5ba2\u89c2\u5b95\u673a\uff0c+odown&nbsp;\u8868\u793a\u6709\u51e0\u4e2a\u54e8\u5175\u8ba4\u4e3a\u8fd9\u4e2a Redis \u8282\u70b9\uff0810.2.1.61\uff09\u5b95\u673a\u4e86\u3002\u770b\u5230\u7684 quorun 4\/2\uff0c\u8868\u793a\u6709 4 \u4e2a\u54e8\u5175\u8ba4\u4e3a Redis \u8282\u70b9\u5b95\u673a\u4e86\uff0c\u5927\u4e8e\u8bbe\u7f6e\u7684 2\uff0c\u6240\u4ee5\u8fd9\u4e2a Redis \u8282\u70b9\u662f\u771f\u7684\u5b95\u673a\u4e86\u3002\uff08\u8fd9\u91cc\u4e3a\u4ec0\u4e48\u662f 4\uff0c\u800c\u4e0d\u662f\u54e8\u5175\u6570 3\uff0c\u7b14\u8005\u4e5f\u6ca1\u6709\u5f04\u6e05\u695a\uff0c\u6b22\u8fce\u7559\u8a00\u8ba8\u8bba\u3002\uff09<\/li>\n<li>\u2462\u6295\u7968\u9009\u4e3e\u65b0\u7684\u54e8\u5175 Leader\uff0c\u4e09\u4e2a\u54e8\u5175\u90fd\u5c06\u7968\u6295\u7ed9\u4e86 id = 2abxxx \u7684\u54e8\u5175\uff0c\u4e5f\u5c31\u662f\u7b2c\u4e09\u4e2a\u54e8\u5175\u8282\u70b9\uff0c\u5c06\u7531\u8fd9\u4e2a\u54e8\u5175\u8fdb\u884c\u4e3b\u4ece\u5207\u6362\u3002<\/li>\n<li>\u2463\u5f00\u59cb\u6545\u969c\u8f6c\u79fb\uff0cfailover-state-select-slave \u8868\u793a\u8981\u8f6c\u79fb\u54ea\u4e2a\u6545\u969c\u8282\u70b9\u3002\u8fd9\u91cc\u5c31\u662f\u5207\u6362\u4e3b\u8282\u70b9\u3002<\/li>\n<li>\u2464\u9009\u51fa\u4e3b\u8282\u70b9\u4e3a\u7b2c\u4e09\u4e2a Redis \u8282\u70b9\uff0810.2.1.63\uff09\u3002<\/li>\n<li>\u2465\u5207\u6362\u4e3b\u8282\u70b9\u4e3a\u7b2c\u4e09\u4e2a Redis \u8282\u70b9\uff0810.2.1.63\uff09\u3002<\/li>\n<\/ul>\n<p>\u8bf4\u660e\u54e8\u5175\u96c6\u7fa4\u6a21\u5f0f\u4e0b\u5bf9 Redis \u7684\u72b6\u6001\u76d1\u63a7\u548c\u4e3b\u4ece\u5207\u6362\u6210\u529f\u3002<\/p>\n<h2>\u4e94\u3001\u5ba2\u6237\u7aef\u81ea\u52a8\u611f\u77e5\u6545\u969c<\/h2>\n<h3>\u5982\u4f55\u5b9e\u73b0\u81ea\u52a8\u611f\u77e5\u6545\u969c<\/h3>\n<p>\u6211\u4eec\u9879\u76ee\u4e2d\uff0c\u90fd\u662f\u7528 Redis \u5ba2\u6237\u7aef\u53bb\u8bfb\u5199 Redis\uff0c\u5728\u5355\u673a\u60c5\u51b5\u4e0b\uff0c\u5355\u8282\u70b9 Redis \u5b95\u673a\u540e\uff0c\u5ba2\u6237\u7aef\u80af\u5b9a\u4f1a\u62a5\u9519\uff0c\u6211\u4eec\u53ef\u4ee5\u5c1d\u8bd5\u6062\u590d\u8fd9\u4e2a\u670d\u52a1\u5668\u4e0a\u7684 Redis \u5c31\u597d\u4e86\u3002<\/p>\n<p>\u4f46\u662f\u6211\u4eec\u73b0\u5728\u662f\u6709\u591a\u4e2a Redis \u8282\u70b9\u7684\uff0c\u5e94\u7528\u7a0b\u5e8f\u8be5\u5982\u4f55\u914d\u7f6e\u5462\uff1f<\/p>\n<p>\u53ef\u80fd\u7684\u601d\u8def\u662f\u8fd9\u6837\uff1a\u5e94\u7528\u7a0b\u5e8f\u914d\u7f6e\u4e3b\u8282\u70b9\u7684 IP \u5730\u5740\u548c\u7aef\u53e3\u3002\u7f3a\u70b9\uff1a\u4e3b\u8282\u70b9\u5207\u6362\u540e\uff0c\u9700\u8981\u6539\u914d\u7f6e\u5e76\u91cd\u542f\u5e94\u7528\u3002<\/p>\n<p>\u90a3\u6709\u6ca1\u6709\u4e00\u79cd\u65b9\u6848\u662f\u81ea\u52a8\u611f\u77e5\u5230 Redis \u5b95\u673a\u540e\uff0c\u8fde\u63a5\u5230\u65b0\u7684\u4e3b\u8282\u70b9\u7684\u5462\uff1f<\/p>\n<p>\u6709\u7684\uff0c\u6211\u4eec\u52a0\u4e0b Redis \u7684\u54e8\u5175\u914d\u7f6e\u5c31\u53ef\u4ee5\u4e86\u3002\u914d\u7f6e\u5185\u5bb9\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p>spring<span style=\"margin: 0px;padding: 0px\">:<\/span><br \/> redis<span style=\"margin: 0px;padding: 0px\">:<\/span><br \/> database<span style=\"margin: 0px;padding: 0px\">:<\/span> <span style=\"margin: 0px;padding: 0px\">0<\/span><br \/> password<span style=\"margin: 0px;padding: 0px\">:<\/span> abc123 # \u5bc6\u7801\uff08\u9ed8\u8ba4\u4e3a\u7a7a\uff09<br \/> timeout<span style=\"margin: 0px;padding: 0px\">:<\/span> <span style=\"margin: 0px;padding: 0px\">10000<\/span> # \u8fde\u63a5\u8d85\u65f6\u65f6\u957f\uff08\u6beb\u79d2\uff09<br \/> sentinel<span style=\"margin: 0px;padding: 0px\">:<\/span> #\u54e8\u5175\u6a21\u5f0f<br \/> master<span style=\"margin: 0px;padding: 0px\">:<\/span> mymaster #\u4e3b\u670d\u52a1\u5668\u6240\u5728\u96c6\u7fa4\u540d\u79f0<br \/> nodes<span style=\"margin: 0px;padding: 0px\">:<\/span> <span style=\"margin: 0px;padding: 0px\">10.2<\/span><span style=\"margin: 0px;padding: 0px\">.1<\/span><span style=\"margin: 0px;padding: 0px\">.63<\/span><span style=\"margin: 0px;padding: 0px\">:<\/span><span style=\"margin: 0px;padding: 0px\">26379<\/span><span style=\"margin: 0px;padding: 0px\">,<\/span><span style=\"margin: 0px;padding: 0px\">10.2<\/span><span style=\"margin: 0px;padding: 0px\">.1<\/span><span style=\"margin: 0px;padding: 0px\">.62<\/span><span style=\"margin: 0px;padding: 0px\">:<\/span><span style=\"margin: 0px;padding: 0px\">26379<\/span><span style=\"margin: 0px;padding: 0px\">,<\/span><span style=\"margin: 0px;padding: 0px\">10.2<\/span><span style=\"margin: 0px;padding: 0px\">.1<\/span><span style=\"margin: 0px;padding: 0px\">.61<\/span><span style=\"margin: 0px;padding: 0px\">:<\/span><span style=\"margin: 0px;padding: 0px\">26379<\/span><\/p>\n<p>\u914d\u7f6e\u597d\u4e86\u540e\uff0c\u91cd\u542f\u5e94\u7528\u7a0b\u5e8f\uff0c\u7136\u540e\u505c\u6389 Redis \u4e3b\u8282\u70b9\u7684\u5bb9\u5668\u3002\u6d4b\u8bd5\u5f80 redis \u5199\u5165\u6570\u636e\uff0c\u7a0b\u5e8f\u4f1a\u62a5\u9519\u3002<\/p>\n<p>\u5199\u5165\u6570\u636e\u7684\u4ee3\u7801\uff1a<\/p>\n<p>stringRedisTemplate<span style=\"margin: 0px;padding: 0px\">.opsForValue<\/span><span style=\"margin: 0px;padding: 0px\">(<\/span><span style=\"margin: 0px;padding: 0px\">)<\/span><br \/><span style=\"margin: 0px;padding: 0px\">.setIfAbsent<\/span><span style=\"margin: 0px;padding: 0px\">(<\/span>key<span style=\"margin: 0px;padding: 0px\">,<\/span> toJson<span style=\"margin: 0px;padding: 0px\">(<\/span>value<span style=\"margin: 0px;padding: 0px\">)<\/span><span style=\"margin: 0px;padding: 0px\">,<\/span> <br \/> millisecond<span style=\"margin: 0px;padding: 0px\">,<\/span> TimeUnit<span style=\"margin: 0px;padding: 0px\">.MILLISECONDS<\/span><span style=\"margin: 0px;padding: 0px\">)<\/span><span style=\"margin: 0px;padding: 0px\">;<\/span><\/p>\n<p>\u62a5\u9519\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n<p>nested exception <span style=\"margin: 0px;padding: 0px\">is<\/span> redis<span style=\"margin: 0px;padding: 0px\">.clients<\/span><br \/><span style=\"margin: 0px;padding: 0px\">.jedis<\/span><span style=\"margin: 0px;padding: 0px\">.exceptions<\/span><span style=\"margin: 0px;padding: 0px\">.JedisConnectionException<\/span><span style=\"margin: 0px;padding: 0px\">:<\/span> <br \/> Unexpected end of stream.<\/p>\n<p>\u56e0\u4e3a\u6545\u969c\u8f6c\u79fb\u662f\u9700\u8981\u4e00\u5b9a\u65f6\u95f4\u7684\uff0c\u8fc7\u51e0\u79d2\u540e\u540e\u53d1\u73b0\u63a7\u5236\u53f0\u7a97\u53e3\u6253\u5370\u51fa Redis \u7684\u4e3b\u8282\u70b9\u4e3a 10.2.1.63:6379\uff0c\u8bf4\u660e\u6545\u969c\u8f6c\u79fb\u6210\u529f\u4e86\u3002<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230108\/167315490763ba515b2a59d.png\" style=\"max-width:100%\" class=\"aligncenter\" title=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe13\" alt=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe13\" \/> <\/p>\n<p><span style=\"margin: 0px;padding: 0px\">[<\/span>MasterListener<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>mymaster<span style=\"margin: 0px;padding: 0px\">&#8211;<\/span><span style=\"margin: 0px;padding: 0px\">[<\/span><span style=\"margin: 0px;padding: 0px\">10.2<\/span><span style=\"margin: 0px;padding: 0px\">.1<\/span><span style=\"margin: 0px;padding: 0px\">.61<\/span><span style=\"margin: 0px;padding: 0px\">:<\/span><span style=\"margin: 0px;padding: 0px\">26379<\/span><span style=\"margin: 0px;padding: 0px\">]<\/span><span style=\"margin: 0px;padding: 0px\">]<\/span> <br \/> INFO redis<span style=\"margin: 0px;padding: 0px\">.clients<\/span><span style=\"margin: 0px;padding: 0px\">.jedis<\/span><span style=\"margin: 0px;padding: 0px\">.JedisSentinelPool<\/span> <br \/><span style=\"margin: 0px;padding: 0px\">&#8211;<\/span>Created JedisPool to master at <br \/><span style=\"margin: 0px;padding: 0px\">10.2<\/span><span style=\"margin: 0px;padding: 0px\">.1<\/span><span style=\"margin: 0px;padding: 0px\">.63<\/span><span style=\"margin: 0px;padding: 0px\">:<\/span><span style=\"margin: 0px;padding: 0px\">6379<\/span><\/p>\n<p>\u518d\u6b21\u6d4b\u8bd5\u8bfb\u5199 Redis\uff0c\u90fd\u662f\u6b63\u5e38\u7684\uff0c\u4e14\u5f80\u7b2c\u4e09\u4e2a\u8282\u70b9\u5199\u5165\u6570\u636e\u540e\uff0c\u7b2c\u4e8c\u4e2a\u8282\u70b9\u4e5f\u8fdb\u884c\u4e86\u4e3b\u4ece\u590d\u5236\u3002<\/p>\n<h3>\u5ba2\u6237\u7aef\u81ea\u52a8\u611f\u77e5\u7684\u539f\u7406<\/h3>\n<p>\u6211\u4eec\u9879\u76ee\u4e2d\u7528\u7684 Jedis \u5ba2\u6237\u7aef\uff0c\u5b83\u6709\u4e00\u4e2a\u8fde\u63a5\u6c60 JedisPool\uff0c\u5f53\u8bbf\u95ee Redis \u65f6\uff0c\u4f1a\u4ece\u8fde\u63a5\u6c60\u91cc\u9762\u83b7\u53d6\u4e00\u4e2a\u8fde\u63a5\u3002\u6211\u4eec\u770b\u4e0b\u8fd9\u4e2a\u8fde\u63a5\u6c60\u91cc\u9762\u7684\u4fe1\u606f\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20230108\/167315490763ba515b6d8c7.png\" style=\"max-width:100%\" class=\"aligncenter\" title=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe14\" alt=\"\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u63d2\u56fe14\" \/> <\/p>\n<ul>\n<li>masterListeners&nbsp;\u4ee3\u8868\u5bf9\u4e09\u4e2a Redis \u8282\u70b9\u7684\u76d1\u542c\u5668\u3002\u91cc\u9762\u6307\u5b9a\u4e86 Redis \u8282\u70b9\u7684 IP \u548c Port\u3002<\/li>\n<li>currentHostMaster&nbsp;\u4ee3\u8868\u5f53\u524d\u8fde\u63a5\u7684\u4e3b\u8282\u70b9\u3002\u76ee\u524d\u4e3a\u7b2c\u4e09\u4e2a\u8282\u70b9\u3002<\/li>\n<\/ul>\n<p>\u5f53\u6211\u4eec\u505c\u6389 Redis \u4e3b\u8282\u70b9\u540e\uff0c\u54e8\u5175\u4f1a\u5207\u6362\u4e3b\u8282\u70b9\uff0c\u8fd9\u4e2a\u8fde\u63a5\u6c60\u91cc\u9762\u7684 currentHostMaster \u4e5f\u4f1a\u88ab\u66f4\u65b0\u4e3a\u65b0\u7684\u4e3b\u8282\u70b9\u3002\u5f53\u6211\u4eec\u518d\u6b21\u8bbf\u95ee Redis \u65f6\uff0c\u4f1a\u548c\u65b0\u7684\u4e3b\u8282\u70b9\u5efa\u7acb\u8fde\u63a5\u3002<\/p>\n<h2>\u516d\u3001\u9047\u5230\u7684\u95ee\u9898<\/h2>\n<h4>1.\u63d0\u793a\u4e0d\u80fd\u5199\u53ea\u8bfb\u7684 redis \u8282\u70b9<\/h4>\n<p>READONLY You can<span style=\"margin: 0px;padding: 0px\">&#8216;t write against a read only replica.;<\/span><\/p>\n<p>\u89e3\u51b3\u65b9\u6848\uff1a\u6bcf\u4e2a\u54e8\u5175\u90fd\u9700\u8981\u914d\u7f6e\u6210\u76d1\u63a7\u4e3b\u8282\u70b9 node1 \u7684 IP\u3002<\/p>\n<h3>2.\u63d0\u793a\u8fde\u63a5 Redis \u5931\u8d25<\/h3>\n<p>ERR Client sent AUTH<span style=\"margin: 0px;padding: 0px\">,<\/span> but no password <span style=\"margin: 0px;padding: 0px\">is<\/span> <span style=\"margin: 0px;padding: 0px\">set<\/span><\/p>\n<p>\u89e3\u51b3\u65b9\u6848\uff1a\u4e3b\u4ece\u8282\u70b9\u90fd\u9700\u8981\u914d\u7f6e requirepass &nbsp;\u548c masterauth\u3002<\/p>\n<h2>\u4e03\u3001\u603b\u7ed3<\/h2>\n<p>\u672c\u7bc7\u8bb2\u89e3\u4e86\u5728\u771f\u5b9e\u7684\u591a\u53f0\u670d\u52a1\u5668\u4e0a\u5982\u4f55\u90e8\u7f72 Redis \u4e3b\u4ece\u67b6\u6784\u3001\u54e8\u5175\u96c6\u7fa4\uff0c\u4ee5\u53ca\u9a8c\u8bc1\u4e3b\u4ece\u590d\u5236\u548c\u6545\u969c\u8f6c\u79fb\u3002<\/p>\n<p>\u7136\u540e\u5bf9\u9879\u76ee\u4e2d\u4f7f\u7528 Redis \u7684\u5730\u65b9\uff0c\u52a0\u5165\u4e86\u54e8\u5175\u914d\u7f6e\uff0c\u4f7f\u5176\u53ef\u4ee5\u81ea\u52a8\u611f\u77e5\u4e3b\u4ece\u5207\u6362\u540e\u7684 IP \u53d8\u5316\uff0c\u4ece\u800c\u548c\u65b0\u7684 Redis \u4e3b\u8282\u70b9\u8fdb\u884c\u8fde\u63a5\u3002<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u670d\u52a1\u5668\u3001Redis\u3001\u67b6\u6784\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6570\u636e\u5e93\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8golang\u5b66\u4e60\u7f51\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n<p>     \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1a51cto \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb \u5220\u9664  <\/p>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u9762\u8bd5\u5b98\uff1a\u4e3a\u4ec0\u4e48 Redis \u8981\u6709\u54e8\u5175\uff1f\n <\/dd>\n<\/dl>\n<dl>\n<dt>\n <\/dt>\n<dd>\n   \u6df1\u5ea6\u89e3\u6790\u5355\u7ebf\u7a0b\u7684 Redis \u5982\u4f55\u505a\u5230\u6bcf\u79d2\u6570\u4e07 QPS \u7684\u8d85\u9ad8\u5904\u7406\u80fd\u529b\uff01\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def 0\u6d4f\u89c8 \u6536\u85cf \u6765\u5230golang\u5b66\u4e60\u7f51\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6570\u636e\u5e93\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300a\u4ece\u5355\u70b9 Redis \u5230 1 \u4e3b 2 \u4ece 3 \u54e8\u5175\u7684\u67b6\u6784\u6f14\u8fdb\u4e4b\u8def\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\u670d\u52a1\u5668\u3001Redis\u3001\u67b6\u6784\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 \u200b\u4e00\u3001\u524d\u8a00 \u6211\u4eec\u6709\u4e2a\u9879\u76ee\u4e2d\u7528\u7684 MySQL\u3001Redis\u3001ES\u3001\u5fae\u670d\u52a1\u90fd\u662f\u5355\u8282\u70b9\u90e8\u7f72\u7684\uff0c\u6ca1\u6709\u505a\u96c6\u7fa4\u6a21\u5f0f\u90e8\u7f72\uff0c\u4e3a\u4e86\u63d0\u9ad8\u6574\u4f53\u7684\u53ef\u7528\u6027\uff0c\u5bf9\u9879\u76ee\u7684\u90e8\u7f72\u67b6\u6784\u8fdb\u884c\u4e86\u5347\u7ea7\uff0c\u652f\u6301\u9ad8\u53ef\u7528\u3002 \u901a\u8fc7\u672c\u7bc7\uff0c\u4f60\u53ef\u4ee5\u5b66\u5230\u4ee5\u4e0b\u5185\u5bb9\uff1a Redis\u771f\u5b9e\u7684\u591a\u670d\u52a1\u5668\u90e8\u7f72\u5b9e\u6218 Redis\u771f\u5b9e\u7684\u4e3b\u4ece\u6a21\u5f0f\u90e8\u7f72\u5b9e\u6218\u3002 Redis\u771f\u5b9e\u7684\u54e8\u5175\u96c6\u7fa4\u6a21\u5f0f\u90e8\u7f72\u5b9e\u6218\u3002 Redis \u4e3b\u8282\u70b9\u5b95\u673a\u540e\uff0cRedis \u54e8\u5175\u5982\u4f55\u8fdb\u884c\u6545\u969c\u8f6c\u79fb\u7684\u3002 Redis \u5207\u6362\u4e3b\u8282\u70b9\u540e\uff0c\u5ba2\u6237\u7aef\u5982\u4f55\u81ea\u52a8\u611f\u77e5\u5e76\u8fde\u63a5\u65b0\u7684\u4e3b\u8282\u70b9\u3002 \u4e8c\u3001\u90e8\u7f72\u62d3\u6251\u56fe \u6211\u4eec\u9879\u76ee\u7684\u6d4b\u8bd5\u73af\u5883 12 \u53f0\u670d\u52a1\u5668\u5df2\u7ecf\u90e8\u7f72\u597d\u4e86\uff0c\u5176\u4e2d\u4e09\u53f0\u7528\u6765\u90e8\u7f72 Redis \u7684 \u4e00\u4e3b + \u4e24\u4ece + \u4e09\u54e8\u5175\u7684\u670d\u52a1\u5668\u3002\u670d\u52a1\u5668\u8d44\u6e90\u6e05\u5355\u5982\u4e0b\uff1a \u53e6\u5916 Redis \u7684\u7aef\u53e3\u90fd\u662f 6379\uff0cSentinel\uff08\u54e8\u5175\uff09 \u7684\u7aef\u53e3\u90fd\u662f&nbsp;26379\u3002 \u90e8\u7f72\u7684\u62d3\u6251\u56fe\u5982\u4e0b\uff0c\u4e09\u53f0\u670d\u52a1\u5668\u4e0a\u90fd\u90e8\u7f72\u4e86\u4e00\u4e2a\u54e8\u5175\u3002 \u4e09\u3001\u642d\u5efa Redis \u4e00\u4e3b\u4e24\u4ece \u6211\u4eec\u539f\u6765\u7684\u5355\u70b9\u7684\u670d\u52a1\u5668\u4e0a\u662f\u6709\u8fd0\u884c\u7684 Redis \u5bb9\u5668\u7684\uff0c\u628a\u8fd9\u4e2a\u5bb9\u5668\u7684\u955c\u50cf\u6253\u5305\u5907\u4efd\u4e0b\uff0c\u7136\u540e\u62f7\u8d1d\u548c\u8fd8\u539f\u5230\u65b0\u7684\u670d\u52a1\u5668\u4e0a\u5c31\u597d\u4e86\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-44012","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/44012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=44012"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/44012\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=44012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=44012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=44012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}