{"id":1091,"date":"2022-04-03T17:10:40","date_gmt":"2022-04-03T09:10:40","guid":{"rendered":"https:\/\/www.buyao007.icu\/?p=1091"},"modified":"2022-04-04T17:12:06","modified_gmt":"2022-04-04T09:12:06","slug":"5-redis-cluster","status":"publish","type":"post","link":"https:\/\/www.buyao007.icu\/?p=1091","title":{"rendered":"5.redis cluster"},"content":{"rendered":"\n<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6\u7fa4\u67b6\u6784\u4e0e\u81ea\u52a8\u5316\u8fd0\u7ef4\uff0c\u66fe\u8d1f\u8d23\u56fd\u5185\u67d0\u5927\u578b\u535a\u5ba2\u7f51\u7ad9\u8fd0\u7ef4\u5de5\u4f5c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">1.\u4ecb\u7ecd<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u9ad8\u6027\u80fd<\/strong>\r\n1\u3001\u5728\u591a\u5206\u7247\u8282\u70b9\u4e2d\uff0c\u5c0616384\u4e2a\u69fd\u4f4d\uff0c\u5747\u5300\u5206\u5e03\u5230\u591a\u4e2a\u5206\u7247\u8282\u70b9\u4e2d\r\n2\u3001\u5b58\u6570\u636e\u65f6\uff0c\u5c06key\u505acrc16(key),\u7136\u540e\u548c16384\u8fdb\u884c\u53d6\u6a21\uff0c\u5f97\u51fa\u69fd\u4f4d\u503c\uff080-16383\u4e4b\u95f4\uff09\r\n3\u3001\u6839\u636e\u8ba1\u7b97\u5f97\u51fa\u7684\u69fd\u4f4d\u503c\uff0c\u627e\u5230\u76f8\u5bf9\u5e94\u7684\u5206\u7247\u8282\u70b9\u7684\u4e3b\u8282\u70b9\uff0c\u5b58\u50a8\u5230\u76f8\u5e94\u69fd\u4f4d\u4e0a\r\n4\u3001\u5982\u679c\u5ba2\u6237\u7aef\u5f53\u65f6\u8fde\u63a5\u7684\u8282\u70b9\u4e0d\u662f\u5c06\u6765\u8981\u5b58\u50a8\u7684\u5206\u7247\u8282\u70b9\uff0c\u5206\u7247\u96c6\u7fa4\u4f1a\u5c06\u5ba2\u6237\u7aef\u8fde\u63a5\u5207\u6362\u81f3\u771f\u6b63\u5b58\u50a8\u8282\u70b9\u8fdb\u884c\u6570\u636e\u5b58\u50a8\r\n<strong>\u9ad8\u53ef\u7528<\/strong>\r\n\u5728\u642d\u5efa\u96c6\u7fa4\u65f6\uff0c\u4f1a\u4e3a\u6bcf\u4e00\u4e2a\u5206\u7247\u7684\u4e3b\u8282\u70b9\uff0c\u5bf9\u5e94\u4e00\u4e2a\u4ece\u8282\u70b9\uff0c\u5b9e\u73b0slaveof\u7684\u529f\u80fd\uff0c\u540c\u65f6\u5f53\u4e3b\u8282\u70b9down\uff0c\u5b9e\u73b0\u7c7b\u4f3c\u4e8esentinel\u7684\u81ea\u52a8failover\u7684\u529f\u80fd\u3002\r\n1\u3001redis\u4f1a\u6709\u591a\u7ec4\u5206\u7247\u6784\u6210\uff083\u7ec4\uff09\r\n2\u3001redis cluster \u4f7f\u7528\u56fa\u5b9a\u4e2a\u6570\u7684slot\u5b58\u50a8\u6570\u636e\uff08\u4e00\u517116384slot\uff09\r\n3\u3001\u6bcf\u7ec4\u5206\u7247\u5206\u5f971\/3 slot\u4e2a\u6570\uff080-5500  5501-11000  11001-16383\uff09\r\n4\u3001\u57fa\u4e8eCRC16(key) % 16384 ====\u300b\u503c \uff08\u69fd\u4f4d\u53f7\uff09\u3002\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">2.\u89c4\u5212\u3001\u642d\u5efa\u8fc7\u7a0b<\/h2>\n\n\n\n<p><strong><em>1.\u89c4\u5212<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>6\u4e2aredis\u5b9e\u4f8b\uff0c\u4e00\u822c\u4f1a\u653e\u52303\u53f0\u786c\u4ef6\u670d\u52a1\u5668\r\n\u6ce8\uff1a\u5728\u4f01\u4e1a\u89c4\u5212\u4e2d\uff0c\u4e00\u4e2a\u5206\u7247\u7684\u4e24\u4e2a\u5206\u5230\u4e0d\u540c\u7684\u7269\u7406\u673a\uff0c\u9632\u6b62\u786c\u4ef6\u4e3b\u673a\u5b95\u673a\u9020\u6210\u7684\u6574\u4e2a\u5206\u7247\u6570\u636e\u4e22\u5931\u3002\r\n\u7aef\u53e3\u53f7\uff1a7000-7005\r<\/code><\/pre>\n\n\n\n<p><strong><em>2.\u5b89\u88c5\u96c6\u7fa4\u63d2\u4ef6<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>EPEL\u6e90\u5b89\u88c5ruby\u652f\u6301\r\nyum install ruby rubygems -y\r\n\u4f7f\u7528\u56fd\u5185\u6e90\r\ngem sources -l\r\ngem sources -a http:\/\/mirrors.aliyun.com\/rubygems\/ \r\ngem sources  --remove https:\/\/rubygems.org\/\r\ngem sources -l\r\ngem install redis -v 3.3.3\r<\/code><\/pre>\n\n\n\n<p><strong><em>3.\u96c6\u7fa4\u8282\u70b9\u51c6\u5907<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir \/data\/700{0..5}\r\ncat > \/data\/7000\/redis.conf &lt;&lt;EOF\r\nport 7000\r\ndaemonize yes\r\npidfile \/data\/7000\/redis.pid\r\nloglevel notice\r\nlogfile \"\/data\/7000\/redis.log\"\r\ndbfilename dump.rdb\r\ndir \/data\/7000\r\nprotected-mode no\r\ncluster-enabled yes\r\ncluster-config-file nodes.conf\r\ncluster-node-timeout 5000\r\nappendonly yes\r\nEOF\r\n\r\ncat >> \/data\/7001\/redis.conf &lt;&lt;EOF\r\nport 7001\r\ndaemonize yes\r\npidfile \/data\/7001\/redis.pid\r\nloglevel notice\r\nlogfile \"\/data\/7001\/redis.log\"\r\ndbfilename dump.rdb\r\ndir \/data\/7001\r\nprotected-mode no\r\ncluster-enabled yes\r\ncluster-config-file nodes.conf\r\ncluster-node-timeout 5000\r\nappendonly yes\r\nEOF\r\n\r\ncat >> \/data\/7002\/redis.conf &lt;&lt;EOF\r\nport 7002\r\ndaemonize yes\r\npidfile \/data\/7002\/redis.pid\r\nloglevel notice\r\nlogfile \"\/data\/7002\/redis.log\"\r\ndbfilename dump.rdb\r\ndir \/data\/7002\r\nprotected-mode no\r\ncluster-enabled yes\r\ncluster-config-file nodes.conf\r\ncluster-node-timeout 5000\r\nappendonly yes\r\nEOF\r\n\r\n\r\ncat >>  \/data\/7003\/redis.conf &lt;&lt;EOF\r\nport 7003\r\ndaemonize yes\r\npidfile \/data\/7003\/redis.pid\r\nloglevel notice\r\nlogfile \"\/data\/7003\/redis.log\"\r\ndbfilename dump.rdb\r\ndir \/data\/7003\r\nprotected-mode no\r\ncluster-enabled yes\r\ncluster-config-file nodes.conf\r\ncluster-node-timeout 5000\r\nappendonly yes\r\nEOF\r\n\r\n\r\ncat >> \/data\/7004\/redis.conf &lt;&lt;EOF\r\nport 7004\r\ndaemonize yes\r\npidfile \/data\/7004\/redis.pid\r\nloglevel notice\r\nlogfile \"\/data\/7004\/redis.log\"\r\ndbfilename dump.rdb\r\ndir \/data\/7004\r\nprotected-mode no\r\ncluster-enabled yes\r\ncluster-config-file nodes.conf\r\ncluster-node-timeout 5000\r\nappendonly yes\r\nEOF\r\n\r\ncat >> \/data\/7005\/redis.conf &lt;&lt;EOF\r\nport 7005\r\ndaemonize yes\r\npidfile \/data\/7005\/redis.pid\r\nloglevel notice\r\nlogfile \"\/data\/7005\/redis.log\"\r\ndbfilename dump.rdb\r\ndir \/data\/7005\r\nprotected-mode no\r\ncluster-enabled yes\r\ncluster-config-file nodes.conf\r\ncluster-node-timeout 5000\r\nappendonly yes\r\nEOF\r<\/code><\/pre>\n\n\n\n<p><strong><em>4.\u542f\u52a8\u8282\u70b9<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>redis-server \/data\/7000\/redis.conf \r\nredis-server \/data\/7001\/redis.conf \r\nredis-server \/data\/7002\/redis.conf \r\nredis-server \/data\/7003\/redis.conf \r\nredis-server \/data\/7004\/redis.conf \r\nredis-server \/data\/7005\/redis.conf \r\n&#91;root@db01 ~]# ps -ef |grep redis\r<\/code><\/pre>\n\n\n\n<p><strong><em>5.\u5c06\u8282\u70b9\u52a0\u5165\u96c6\u7fa4\u7ba1\u7406<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 \\\r\n127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005\r\n\r\n--replicas 1\u526f\u672c\u6570\u91cf\u4e3a1  \uff08\u5373\u4e00\u4e3b\u4e00\u4ece\uff09\r<\/code><\/pre>\n\n\n\n<p><strong><em>6.\u96c6\u7fa4\u72b6\u6001\u67e5\u770b<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u96c6\u7fa4\u4e3b\u8282\u70b9\u72b6\u6001\r\nredis-cli -p 7000 cluster nodes | grep master\r\n\u96c6\u7fa4\u4ece\u8282\u70b9\u72b6\u6001\r\nredis-cli -p 7000 cluster nodes | grep slave\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">3.\u96c6\u7fa4\u8282\u70b9\u7ba1\u7406<\/h2>\n\n\n\n<p><strong><em>1.\u589e\u52a0\u65b0\u7684\u8282\u70b9<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir \/data\/7006\r\nmkdir \/data\/7007\r\ncat > \/data\/7006\/redis.conf &lt;&lt;EOF\r\nport 7006\r\ndaemonize yes\r\npidfile \/data\/7006\/redis.pid\r\nloglevel notice\r\nlogfile \"\/data\/7006\/redis.log\"\r\ndbfilename dump.rdb\r\ndir \/data\/7006\r\nprotected-mode no\r\ncluster-enabled yes\r\ncluster-config-file nodes.conf\r\ncluster-node-timeout 5000\r\nappendonly yes\r\nEOF\r\n\r\ncat >  \/data\/7007\/redis.conf &lt;&lt;EOF\r\nport 7007\r\ndaemonize yes\r\npidfile \/data\/7007\/redis.pid\r\nloglevel notice\r\nlogfile \"\/data\/7007\/redis.log\"\r\ndbfilename dump.rdb\r\ndir \/data\/7007\r\nprotected-mode no\r\ncluster-enabled yes\r\ncluster-config-file nodes.conf\r\ncluster-node-timeout 5000\r\nappendonly yes\r\nEOF\r\n\r\nredis-server \/data\/7006\/redis.conf \r\nredis-server \/data\/7007\/redis.conf\r<\/code><\/pre>\n\n\n\n<p><strong><em>2.\u6dfb\u52a0\u4e3b\u8282\u70b9<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>redis-trib.rb add-node 127.0.0.1:7006 127.0.0.1:7000<\/code><\/pre>\n\n\n\n<p><strong><em>3.\u8f6c\u79fbslot\uff08\u91cd\u65b0\u5206\u7247\uff09<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>redis-trib.rb reshard 127.0.0.1:7000<\/code><\/pre>\n\n\n\n<p><strong><em>4.\u6dfb\u52a0\u4e00\u4e2a\u4ece\u8282\u70b9<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>redis-trib.rb add-node --slave --master-id 8ff9ef5b78e6da62bd7b362e1fe190cba19ef5ae 127.0.0.1:7007 127.0.0.1:7000<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">4.\u5220\u9664\u8282\u70b9<\/h2>\n\n\n\n<p><strong><em>1.\u5c06\u9700\u8981\u5220\u9664\u8282\u70b9slot\u79fb\u52a8\u8d70<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>redis-trib.rb reshard 127.0.0.1:7000\r\n\u8f93\u5165slot\u6570\u91cf\r\n\u8f93\u5165\u63a5\u6536\u8282\u70b9\uff1a49257f251824dd815bc7f31e1118b670365e861a \r\n\u8f93\u5165\uff1adone\r\n\u8f93\u5165\uff1ayes\r\n0-1364 5461-6826 10923-12287\r\n1365      1366     1365\r<\/code><\/pre>\n\n\n\n<p><strong><em>2.\u5220\u9664\u4e00\u4e2a\u8282\u70b9<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5220\u9664master\u8282\u70b9\u4e4b\u524d\u9996\u5148\u8981\u4f7f\u7528reshard\u79fb\u9664master\u7684\u5168\u90e8slot,\u7136\u540e\u518d\u5220\u9664\u5f53\u524d\u8282\u70b9\r\nredis-trib.rb del-node 127.0.0.1:7006 8ff9ef5b78e6da62bd7b362e1fe190cba19ef5ae\r\n\u5220\u9664\u7684\u8282\u70b9\uff0b\u8282\u70b9id\u53f7\u7801\r\n\u8bbe\u7f6eredis\u6700\u5927\u5185\u5b58##\u4e00\u822c\u8bbe\u7f6e\u7269\u7406\u5185\u5b58\u7684\u4e00\u534a\uff0c\u5426\u5219\u6709\u591a\u5c11\u7528\u591a\u5c11\r\nconfig set maxmemory 102400000\r<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[],"_links":{"self":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1091"}],"collection":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1091"}],"version-history":[{"count":1,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1091\/revisions"}],"predecessor-version":[{"id":1092,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/1091\/revisions\/1092"}],"wp:attachment":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}