{"id":5062,"date":"2024-11-14T10:08:42","date_gmt":"2024-11-14T02:08:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5062\/"},"modified":"2024-11-14T10:08:42","modified_gmt":"2024-11-14T02:08:42","slug":"redis%e6%80%8e%e4%b9%88%e9%83%a8%e7%bd%b2%e9%9b%86%e7%be%a4","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5062\/","title":{"rendered":"redis\u600e\u4e48\u90e8\u7f72\u96c6\u7fa4"},"content":{"rendered":"<blockquote><p>\n  redis \u96c6\u7fa4\u90e8\u7f72\u901a\u8fc7\u5c06 redis \u5b9e\u4f8b\u7ec4\u7ec7\u6210\u5206\u5e03\u5f0f\u7cfb\u7edf\uff0c\u63d0\u5347\u6027\u80fd\u548c\u53ef\u7528\u6027\u3002\u90e8\u7f72\u6b65\u9aa4\u5305\u62ec\uff1a1. \u5b89\u88c5 redis\uff1b2. \u521b\u5efa\u914d\u7f6e\u6587\u4ef6\uff0c\u542f\u7528\u96c6\u7fa4\uff1b3. \u521b\u5efa\u96c6\u7fa4\u8282\u70b9\u914d\u7f6e\u6587\u4ef6\uff0c\u5305\u542b\u8282\u70b9\u5730\u5740\uff1b4. \u542f\u52a8\u96c6\u7fa4\uff1b5. \u6dfb\u52a0\u5176\u4ed6\u8282\u70b9\uff1b6. \u9a8c\u8bc1\u96c6\u7fa4\u8fd0\u884c\u60c5\u51b5\u3002\u96c6\u7fa4\u7ba1\u7406\u547d\u4ee4\u5305\u62ec\uff1a\u6dfb\u52a0\u65b0\u8282\u70b9\u3001\u5220\u9664\u8282\u70b9\u548c\u89e6\u53d1\u8282\u70b9\u6545\u969c\u540e\u63a5\u7ba1\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/21\/2024052113362043355.jpg\" class=\"aligncenter\" title=\"redis\u600e\u4e48\u90e8\u7f72\u96c6\u7fa4\u63d2\u56fe\" alt=\"redis\u600e\u4e48\u90e8\u7f72\u96c6\u7fa4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u90e8\u7f72 Redis \u96c6\u7fa4<\/strong><\/p>\n<p>Redis \u96c6\u7fa4\u90e8\u7f72\u662f\u4e00\u79cd\u5c06 Redis \u5b9e\u4f8b\u7ec4\u7ec7\u6210\u4e00\u4e2a\u5206\u5e03\u5f0f\u7cfb\u7edf\u7684\u8fc7\u7a0b\uff0c\u4ee5\u63d0\u9ad8\u6574\u4f53\u6027\u80fd\u548c\u53ef\u7528\u6027\u3002<\/p>\n<p><strong>\u90e8\u7f72\u6b65\u9aa4\uff1a<\/strong><\/p>\n<p><strong>1. \u5b89\u88c5 Redis<\/strong><\/p>\n<p>\u5728\u6240\u6709\u8981\u5305\u542b\u5728\u96c6\u7fa4\u4e2d\u7684\u670d\u52a1\u5668\u4e0a\u5b89\u88c5 Redis\u3002\u786e\u4fdd\u4f7f\u7528\u76f8\u540c\u7684 Redis \u7248\u672c\u3002<\/p>\n<p><strong>2. \u521b\u5efa\u914d\u7f6e\u6587\u4ef6<\/strong><\/p>\n<p>\u5728\u6bcf\u4e2a\u670d\u52a1\u5668\u4e0a\u521b\u5efa Redis \u914d\u7f6e\u6587\u4ef6\u3002\u914d\u7f6e\u6587\u4ef6\u5e94\u5305\u542b\u4ee5\u4e0b\u4fe1\u606f\uff1a<\/p>\n<ul>\n<li>cluster-enabled yes\uff1a\u542f\u7528\u96c6\u7fa4<\/li>\n<li>cluster-config-file nodes.conf\uff1a\u96c6\u7fa4\u8282\u70b9\u914d\u7f6e\u6587\u4ef6\u7684\u4f4d\u7f6e<\/li>\n<\/ul>\n<p><strong>3. \u521b\u5efa\u96c6\u7fa4\u8282\u70b9\u914d\u7f6e\u6587\u4ef6<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a nodes.conf \u7684\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u96c6\u7fa4\u4e2d\u6240\u6709\u8282\u70b9\u7684 IP \u5730\u5740\u548c\u7aef\u53e3\u3002<\/p>\n<pre>&lt;IP address 1&gt;:&lt;port 1&gt;\n&lt;IP address 2&gt;:&lt;port 2&gt;\n...\n&lt;IP address N&gt;:&lt;port N&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u542f\u52a8\u96c6\u7fa4<\/strong><\/p>\n<p>\u5728\u7b2c\u4e00\u4e2a\u8282\u70b9\u4e0a\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>redis-server --cluster-enabled yes --cluster-config-file nodes.conf<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u542f\u52a8\u96c6\u7fa4\u5e76\u521b\u5efa\u7b2c\u4e00\u4e2a\u8282\u70b9\u3002<\/p>\n<p><strong>5. \u6dfb\u52a0\u5176\u4ed6\u8282\u70b9<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06\u5176\u4ed6\u8282\u70b9\u6dfb\u52a0\u5230\u96c6\u7fa4\uff1a<\/p>\n<pre>redis-cli --cluster create --cluster-nodes &lt;IP address 1&gt;:&lt;port 1&gt; &lt;IP address 2&gt;:&lt;port 2&gt; ... &lt;IP address N&gt;:&lt;port N&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa Redis \u96c6\u7fa4\u5e76\u6dfb\u52a0\u6307\u5b9a\u8282\u70b9\u3002<\/p>\n<p><strong>6. \u9a8c\u8bc1\u96c6\u7fa4<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9a8c\u8bc1\u96c6\u7fa4\u662f\u5426\u6b63\u5e38\u8fd0\u884c\uff1a<\/p>\n<pre>redis-cli -c -h &lt;IP address 1&gt;:&lt;port 1&gt; cluster nodes<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u96c6\u7fa4\u7ba1\u7406\uff1a<\/strong><\/p>\n<p>\u90e8\u7f72\u96c6\u7fa4\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7ba1\u7406\u5b83\uff1a<\/p>\n<ul>\n<li> -cli -c -h : cluster add-node : \uff1a\u6dfb\u52a0\u65b0\u8282\u70b9 <\/li>\n<li>redis-cli -c -h : cluster del-node : \uff1a\u5220\u9664\u8282\u70b9 <\/li>\n<li>redis-cli -c -h : cluster failover\uff1a\u5728\u8282\u70b9\u6545\u969c\u540e\u89e6\u53d1\u63a5\u7ba1 <\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u90e8\u7f72\u96c6\u7fa4\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>redis \u96c6\u7fa4\u90e8\u7f72\u901a\u8fc7\u5c06 redis \u5b9e\u4f8b\u7ec4\u7ec7\u6210\u5206\u5e03\u5f0f\u7cfb\u7edf\uff0c\u63d0\u5347\u6027\u80fd\u548c\u53ef\u7528\u6027\u3002\u90e8\u7f72\u6b65\u9aa4\u5305\u62ec\uff1a1. \u5b89\u88c5 redis\uff1b2. \u521b\u5efa\u914d\u7f6e\u6587\u4ef6\uff0c\u542f\u7528\u96c6\u7fa4\uff1b3. \u521b\u5efa\u96c6\u7fa4\u8282\u70b9\u914d\u7f6e\u6587\u4ef6\uff0c\u5305\u542b\u8282\u70b9\u5730\u5740\uff1b4. \u542f\u52a8\u96c6\u7fa4\uff1b5. \u6dfb\u52a0\u5176\u4ed6\u8282\u70b9\uff1b6. \u9a8c\u8bc1\u96c6\u7fa4\u8fd0\u884c\u60c5\u51b5\u3002\u96c6\u7fa4\u7ba1\u7406\u547d\u4ee4\u5305\u62ec\uff1a\u6dfb\u52a0\u65b0\u8282\u70b9\u3001\u5220\u9664\u8282\u70b9\u548c\u89e6\u53d1\u8282\u70b9\u6545\u969c\u540e\u63a5\u7ba1\u3002 \u5982\u4f55\u90e8\u7f72 Redis \u96c6\u7fa4 Redis \u96c6\u7fa4\u90e8\u7f72\u662f\u4e00\u79cd\u5c06 Redis \u5b9e\u4f8b\u7ec4\u7ec7\u6210\u4e00\u4e2a\u5206\u5e03\u5f0f\u7cfb\u7edf\u7684\u8fc7\u7a0b\uff0c\u4ee5\u63d0\u9ad8\u6574\u4f53\u6027\u80fd\u548c\u53ef\u7528\u6027\u3002 \u90e8\u7f72\u6b65\u9aa4\uff1a 1. \u5b89\u88c5 Redis \u5728\u6240\u6709\u8981\u5305\u542b\u5728\u96c6\u7fa4\u4e2d\u7684\u670d\u52a1\u5668\u4e0a\u5b89\u88c5 Redis\u3002\u786e\u4fdd\u4f7f\u7528\u76f8\u540c\u7684 Redis \u7248\u672c\u3002 2. \u521b\u5efa\u914d\u7f6e\u6587\u4ef6 \u5728\u6bcf\u4e2a\u670d\u52a1\u5668\u4e0a\u521b\u5efa Redis \u914d\u7f6e\u6587\u4ef6\u3002\u914d\u7f6e\u6587\u4ef6\u5e94\u5305\u542b\u4ee5\u4e0b\u4fe1\u606f\uff1a cluster-enabled yes\uff1a\u542f\u7528\u96c6\u7fa4 cluster-config-file nodes.conf\uff1a\u96c6\u7fa4\u8282\u70b9\u914d\u7f6e\u6587\u4ef6\u7684\u4f4d\u7f6e 3. \u521b\u5efa\u96c6\u7fa4\u8282\u70b9\u914d\u7f6e\u6587\u4ef6 \u521b\u5efa\u4e00\u4e2a\u540d\u4e3a nodes.conf \u7684\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u96c6\u7fa4\u4e2d\u6240\u6709\u8282\u70b9\u7684 IP \u5730\u5740\u548c\u7aef\u53e3\u3002 &lt;IP address 1&gt;:&lt;port 1&gt; &lt;IP address 2&gt;:&lt;port 2&gt; &#8230; &lt;IP address N&gt;:&lt;port N&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5062","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5062","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=5062"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5062\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}