{"id":7700,"date":"2016-05-12T15:51:11","date_gmt":"2016-05-12T07:51:11","guid":{"rendered":"http:\/\/jpuyy.com\/?p=7700"},"modified":"2016-05-13T14:33:25","modified_gmt":"2016-05-13T06:33:25","slug":"rediscluster%e7%bc%a9%e5%ae%b9%e5%92%8c%e6%89%a9%e5%ae%b9","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=7700","title":{"rendered":"rediscluster\u7f29\u5bb9\u548c\u6269\u5bb9"},"content":{"rendered":"<p>rediscluster \u914d\u7f6e\u7684\u8fc7\u91cf\uff0c\u6d6a\u8d39\u4e86\u8d44\u6e90\u3002\u4e0d\u591f\u65f6\u53c8\u52a0\u52a0\u8d44\u6e90<\/p>\n<p>\u67e5\u770b\u5f53\u524d rediscluster \u7684\u4e3b\u4ece\u5173\u7cfb\uff0c\u5e76\u8bb0\u4e0b\u6765 hash \u503c\u3002<\/p>\n<pre>redis-cli -c cluster nodes<\/pre>\n<p>\u73b0\u5728\u5148\u8fdb\u884c\u6269\u5bb9\uff0c192.168.11.3:6379 \u662f\u5f53\u524d cluster \u7684\u4e00\u4e2a master \u8282\u70b9\u3002<\/p>\n<p>\u6dfb\u52a0 192.168.22.3:6379\uff0c\u4ece\u8282\u70b9 192.168.22.4:6379<\/p>\n<p>\u67e5\u770b cluster \u72b6\u6001<\/p>\n<pre>redis-trib.rb info 192.168.11.3:6379<\/pre>\n<p>\u6dfb\u52a0\uff0c\u9ed8\u8ba4\u4e3a master<\/p>\n<pre>redis-trib.rb add-node 192.168.22.3:6379 192.168.11.3:6379<\/pre>\n<p>\u6dfb\u52a0 &#8211;slave, \u4e3b\u52a8\u627e\u6ca1\u6709 slave \u7684 master \u8282\u70b9<\/p>\n<pre>redis-trib.rb add-node --slave 192.168.22.4:6379 192.168.11.3:6379<\/pre>\n<p>\u67e5\u770b cluster nodes<\/p>\n<pre>redis-cli -c cluster nodes<\/pre>\n<p>\u63a5\u4e0b\u6765\u786e\u5b9a\u54ea\u4e9b master \u7684 slots \u8fc1\u5230\u65b0\u52a0\u7684\u5b9e\u4f8b\uff0c\u627e\u5230\u65b0\u52a0\u7684 master hash \u503c\u4e3a e0d88661607192a4ffac1b74412c6cd6d0932067<\/p>\n<p>\u4ece\u5df2\u6709 slot \u91cc\u5206\u914d 100 \u4e2a slots \u5230 e0d88661607192a4ffac1b74412c6cd6d0932067<\/p>\n<pre>redis-trib.rb reshard --from 32f38c9e5e42f6a66e67abdd540cce72e4bf399c --to e0d88661607192a4ffac1b74412c6cd6d0932067 --slots 100 --yes 192.168.11.3:6379<\/pre>\n<p>\u5982\u679c\u9047\u5230\u5931\u8d25\uff0c\u8fdb\u884c fix<\/p>\n<pre>redis-trib.rb fix 192.168.11.3:6379<\/pre>\n<p>\u53cd\u590d\u51e0\u6b21\uff0c\u5e76\u67e5\u770b\u53ef\u4ee5\u8fbe\u5230\u8fc1\u79fb\u76ee\u7684\u3002<\/p>\n<p>\u603b\u662f fix \u7279\u522b\u70e6\uff0c\u5199\u4e2a\u6709\u9650\u5faa\u73af\u641e\u5b9a\u3002<\/p>\n<pre>for i in $(seq 20); do redis-trib.rb reshard --from 32f38c9e5e42f6a66e67abdd540cce72e4bf399c --to e0d88661607192a4ffac1b74412c6cd6d0932067 --slots 100 --yes 192.168.11.3:6379 || redis-trib.rb fix 192.168.11.3:6379; done\r\n<\/pre>\n<p>\u000e<span style=\"line-height: 1.625;\">\u7f29\u5bb9\u5373\u662f\u628a\u91cc\u9762\u7684 slots \u79fb\u5230\u5176\u4ed6\u5b9e\u4f8b\u91cc\uff0c\u7136\u540e\u5220\u9664 node \u5bf9\u5e94\u7684 hash<\/span><\/p>\n<pre>redis-trib.rb del-node 192.168.11.3:6379 e0d88661607192a4ffac1b74412c6cd6d0932067<\/pre>\n<p>\u67e5\u770b\u5f53\u524d\u5b9e\u4f8b\u662f\u5426\u8fd8\u5728\u63d0\u4f9b\u670d\u52a1<\/p>\n<pre>redis-cli monitor<\/pre>\n<p>\u5f53\u7f29\u5bb9\u6216\u6269\u5bb9\u5b8c\u4e4b\u540e\uff0c\u5982\u679c slots \u7684\u6570\u91cf\u5dee\u7684\u591a\u7684\u8bdd\uff0c \u53ef\u4ee5\u5bf9\u6574\u4e2a\u96c6\u7fa4 rebalance<\/p>\n<pre>redis-trib.rb rebalance 192.168.11.3:6379<\/pre>\n<p>\u540c\u6837\u7684\u5982\u679c\u4e2d\u95f4\u4e2d\u65ad\uff0c\u5c31 fix<\/p>\n<pre>redis-trib.rb fix 192.168.11.3:6379<\/pre>\n<p>\u5230\u6700\u540e\u4f1a\u63d0\u793a<\/p>\n<pre>*** No rebalancing needed! All nodes are within the 2.0% threshold.<\/pre>\n<p>\u67e5\u770b\u6574\u4e2a\u96c6\u7fa4\u7684\u60c5\u51b5<\/p>\n<pre>\r\n#redis-cli -c cluster info\r\n\r\ncluster_state:ok\r\ncluster_slots_assigned:16384\r\ncluster_slots_ok:16384\r\ncluster_slots_pfail:0\r\ncluster_slots_fail:0\r\ncluster_known_nodes:12\r\ncluster_size:6\r\ncluster_current_epoch:46\r\ncluster_my_epoch:40\r\ncluster_stats_messages_sent:912305\r\ncluster_stats_messages_received:912227\r\n\r\n<\/pre>\n<p>ok\uff0c\u5230\u8fd9\u91cc\u7ed3\u675f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>rediscluster \u914d\u7f6e\u7684\u8fc7\u91cf\uff0c\u6d6a\u8d39\u4e86\u8d44\u6e90\u3002\u4e0d\u591f\u65f6\u53c8\u52a0\u52a0\u8d44\u6e90 \u67e5\u770b\u5f53\u524d rediscluster \u7684\u4e3b\u4ece\u5173\u7cfb\uff0c\u5e76\u8bb0\u4e0b\u6765 hash \u503c\u3002 redis-cli -c cluster nodes \u73b0\u5728\u5148\u8fdb\u884c\u6269\u5bb9\uff0c192.168.11.3:6379 \u662f\u5f53\u524d cluster \u7684\u4e00\u4e2a master \u8282\u70b9\u3002 \u6dfb\u52a0 192.168.22.3:6379\uff0c\u4ece\u8282\u70b9 192.168.22.4:6379 \u67e5\u770b cluster \u72b6\u6001 redis-trib.rb info 192.168.11.3:6379 \u6dfb\u52a0\uff0c\u9ed8\u8ba4\u4e3a master redis-trib.rb add-node 192.168.22.3:6379 192.168.11.3:6379 \u6dfb\u52a0 &#8211;slave, \u4e3b\u52a8\u627e\u6ca1\u6709 slave \u7684 master \u8282\u70b9 redis-trib.rb add-node &#8211;slave 192.168.22.4:6379 192.168.11.3:6379 \u67e5\u770b cluster nodes redis-cli -c cluster nodes \u63a5\u4e0b\u6765\u786e\u5b9a\u54ea\u4e9b master \u7684 slots [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-7700","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7700","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7700"}],"version-history":[{"count":13,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7700\/revisions"}],"predecessor-version":[{"id":7730,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/7700\/revisions\/7730"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7700"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7700"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7700"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}