{"id":225355,"date":"2021-09-13T09:00:27","date_gmt":"2021-09-13T01:00:27","guid":{"rendered":"https:\/\/gulass.cn\/?p=225355"},"modified":"2021-08-26T09:01:22","modified_gmt":"2021-08-26T01:01:22","slug":"redis-cluster-construction","status":"publish","type":"post","link":"https:\/\/gulass.cn\/redis-cluster-construction.html","title":{"rendered":"Redis\u96c6\u7fa4\u642d\u5efa"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nredis\u6700\u5f00\u59cb\u4f7f\u7528\u4e3b\u4ece\u6a21\u5f0f\u505a\u96c6\u7fa4\uff0c\u82e5master\u5b95\u673a\u9700\u8981\u624b\u52a8\u914d\u7f6eslave\u8f6c\u4e3amaster\uff1b\u540e\u6765\u4e3a\u4e86\u9ad8\u53ef\u7528\u63d0\u51fa\u6765\u54e8\u5175\u6a21\u5f0f\uff0c\u8be5\u6a21\u5f0f\u4e0b\u6709\u4e00\u4e2a\u54e8\u5175\u76d1\u89c6master\u548cslave\uff0c\u82e5master\u5b95\u673a\u53ef\u81ea\u52a8\u5c06slave\u8f6c\u4e3amaster\uff0c\u4f46\u5b83\u4e5f\u6709\u4e00\u4e2a\u95ee\u9898\uff0c\u5c31\u662f\u4e0d\u80fd\u52a8\u6001\u6269\u5145\uff1b\u6240\u4ee5\u57283.x\u63d0\u51facluster\u96c6\u7fa4\u6a21\u5f0f\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u5b89\u88c5Redis\u96c6\u7fa4\u51c6\u5907<\/strong><\/div>\n

\u91c7\u7528\u539f\u751f\u642d\u5efa\u7684\u65b9\u5f0f\u642d\u5efa3\u4e3b3\u4ece\u7684Redis Cluster\uff0c\u5206\u522b\u7ed93\u4e2amaster\u8282\u70b9\u914d\u7f6e\u4e00\u4e2aslave\u8282\u70b9\uff0c\u603b\u8ba16\u4e2aRedis\u8282\u70b9\u3002
\n\u4f46\u7531\u4e8e\u6211\u4eec\u53ea\u67094\u53f0\u673a\u5668\uff0c\u6240\u4ee5\u9009\u62e9\u5728\u5176\u4e2d\u7684\u4e24\u53f0\u673a\u5668\u4e0a\u5b89\u88c5\u4e24\u4e2aredis\u3002<\/p>\n

\u4fee\u6539\u914d\u7f6e\u6587\u4ef6<\/strong><\/div>\n
\r\nport 6380 # server\u7aef\u53e3\uff0c4\u53f0server\u7528\u9ed8\u8ba4\u76846379\uff0c\u6240\u4ee5\u65e0\u9700\u4fee\u6539\uff0c\u53e6\u5916\u4e24\u53f0\u5219\u6539\u62106380\u3002\r\n# bind 127.0.0.1 \/\/\u8fd9\u4e00\u884c\u8981\u6ce8\u91ca\uff0c\u5426\u5219\u65e0\u6cd5\u8fdc\u7a0b\u8fde\u63a5\r\ncluster-enabled yes\r\ncluster-config-file nodes.conf \/\/node.conf\u6587\u4ef6\u4e0d\u7528\u7ba1\u3002\r\ncluster-node-timeout 5000\r\nappendonly yes \/\/aof\r\ndaemonize yes \r\nprotected-mode no\r\n<\/pre>\n
\u542f\u52a8\u670d\u52a1<\/strong><\/div>\n
\r\n[root@localhost]# redis-server redis.conf\r\n<\/pre>\n

\u5230\u8fd9\u91cc\u6211\u4eec\u5c31\u6709\u4ee5\u96c6\u7fa4\u6a21\u5f0f\u542f\u52a8\u76846\u53f0redis server\uff0c\u4f46\u662f\u6bcf\u53f0\u670d\u52a1\u5668\u8fd8\u6ca1\u6709\u8fdb\u884cslot\u6307\u6d3e,\u6b64\u65f6\u662f\u4e0d\u80fd\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\u7684\u3002<\/p>\n

\u5f00\u653e\u9632\u706b\u5899\u7aef\u53e3<\/strong><\/div>\n
\r\n[root@test-3]# firewall-cmd --zone=public --add-port={6379\/tcp,16379\/tcp} --permanent\r\n[root@test-3]# firewall-cmd --reload\r\n<\/pre>\n
\u642d\u5efa\u96c6\u7fa4\uff08slot\u6307\u6d3e\uff09<\/strong><\/div>\n

\u7528redis\u5b98\u65b9\u63d0\u4f9b\u7684redis-cli \u547d\u4ee4\u7684--cluster\u9009\u9879\u3002
\n\u4e0b\u9762\u7684\u547d\u4ee4\u5c06\u516d\u53f0\u670d\u52a1\u5668\u7ec4\u6210\u4e00\u4e2a\u96c6\u7fa4
\n\u5176\u4e2d\u590d\u5236\u56e0\u5b50\u4e3a1\u6240,\u4ee5\u4f1a\u67093\u53f0master,\u53e6\u59163\u53f0\u4e3aslave\u3002
\n16384\u4e2aslot\u4f1a\u5c3d\u53ef\u80fd\u5747\u5300\u7684\u6307\u6d3e\u7ed93\u53f0master, \u800c3\u53f0slave\u5f02\u6b65\u7684\u4ece\u5176master\u8fdb\u884c\u590d\u5236\u3002
\n\u4efb\u9009\u4e00\u53f0\u673a\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4<\/p>\n

\r\n[root@test-3 redis-6.2.5]# src\/redis-cli --cluster create 192.168.0.129:6379 192.168.0.250:6379 test-3:6379 test-3:6380 test-4:6379 test-4:6380 --cluster-replicas 1\r\n>>> Performing hash slots allocation on 6 nodes...\r\nMaster[0] -> Slots 0 - 5460\r\nMaster[1] -> Slots 5461 - 10922\r\nMaster[2] -> Slots 10923 - 16383\r\nAdding replica test-3:6380 to 192.168.0.129:6379\r\nAdding replica test-4:6380 to 192.168.0.250:6379\r\nAdding replica test-4:6379 to sz-cms-3:6379\r\nM: ae80cca550b15585b20b4ac7511f7751437f6ee 192.168.0.129:6379\r\n   slots:[0-5460] (5461 slots) master\r\nM: d7ca9360b74b777e7739e05d2265b6c4d5f5ca0 192.168.0.250:6379\r\n   slots:[5461-10922] (5462 slots) master\r\nM: 68569ee4c6bb4b60981ea34ee1b7c61b2ce285 test-3:6379\r\n   slots:[10923-16383] (5461 slots) master\r\nS: 3532972c73ce3b785d538983f725486e7a0fc9 test-3:6380\r\n   replicates ae80cca550b558b20b4acc7511f7751437f6ee\r\nS: b648cc92b55d07ec638c7d41a9ca24fc5d9160 test-4:6379\r\n   replicates 68569ee4cbb4b609881e7a34ee1b7c61b2ce285\r\nS: 25e9b9a3de4ac4c3e47eb3fdb9f8e80c98e728f test-4:6380\r\n   replicates d7ca9360b74b777e773905d2265b6c4d5f5ca0\r\nCan I set the above configuration? (type 'yes' to accept): yes\r\n>>> Nodes configuration updated\r\n>>> Assign a different config epoch to each node\r\n>>> Sending CLUSTER MEET messages to join the cluster\r\nWaiting for the cluster to join\r\n\r\n>>> Performing Cluster Check (using node 192.168.0.129:6379)\r\nM: ae80cca550b185b20b4acc7511f7751437f6ee 192.168.0.129:6379\r\n   slots:[0-5460] (5461 slots) master\r\n   1 additional replica(s)\r\nM: d7ca9360b74b777e77397e05d25b6c4d5f5ca0 192.168.0.250:6379\r\n   slots:[5461-10922] (5462 slots) master\r\n   1 additional replica(s)\r\nS: 25e9b9a3de4c4c3e47b3fdb9f8e80c98e728f 192.168.0.141:6380\r\n   slots: (0 slots) slave\r\n   replicates d7ca9360b74b77e7739705d2265b6c4d5f5ca0\r\nM: 68569ee4c6bb4609881e7a34ee1b7c1b2ce285 192.168.0.228:6379\r\n   slots:[10923-16383] (5461 slots) master\r\n   1 additional replica(s)\r\nS: b648cc92b55d17ec638c7d41ca9a24fc5d9160 192.168.0.141:6379\r\n   slots: (0 slots) slave\r\n   replicates 68569ee4c6bbb609881e7a4ee1b7c612ce285\r\nS: 3532972c3ce3b785d5389783f72546e7a0fc9 192.168.0.228:6380\r\n   slots: (0 slots) slave\r\n   replicates ae8ca550b5585b20b4cc7511f7751437f6ee\r\n[OK] All nodes agree about slots configuration.\r\n>>> Check for open slots...\r\n>>> Check slots coverage...\r\n[OK] All 16384 slots covered.\r\n<\/pre>\n
\u67e5\u770b\u96c6\u7fa4\u60c5\u51b5<\/strong><\/div>\n
\r\n[root@sz-cms-3 redis-6.2.5]# src\/redis-cli \r\n127.0.0.1:6379> cluster nodes\r\n3532972c7ce3b7885d38783f725486e7a0fc9 192.168.0.228:6380@16380 slave ae80cc550b1558b20b4acc7511f77514376ee 0 1629874202654 1 connected\r\n25eb9ade4ac4c3478eb3fdb98e80c9e728f 192.168.0.141:6380@16380 slave d7ca930b74b77777397e0d2265b6cd5f5ca0 0 1629874204664 2 connected\r\nd7ca9360b7b777e7797e05d265b64d5f5ca0 192.168.0.250:6379@16379 master - 0 1629874205000 2 connected 5461-10922\r\nae8cca550b15585b0b4acc751f7751437f6ee 192.168.0.129:6379@16379 master - 0 1629874206673 1 connected 0-5460\r\n68569ee4c6b4b609881e7a3ee1b761b2ce285 192.168.0.228:6379@16379 myself,master - 0 1629874206000 3 connected 10923-16383\r\nb648c92b55d017ec68c7d41ca9c24fc5d9160 192.168.0.141:6379@16379 slave 6856ee4c6b4b609881e734ee17c61b2ce285 0 1629874206000 3 connected\r\n<\/pre>\n
\u6dfb\u52a0\u5bc6\u7801<\/strong><\/div>\n

\u6bcf\u4e2a\u8282\u70b9\u90fd\u9700\u8981\u81ea\u5df1\u4e0a\u53bb\u8bbe\u7f6e\u3002\u7136\u540e\u56e0\u4e3a\u6709\u4e24\u4e2a\u8282\u70b9\u4f7f\u7528\u4e866380\u7aef\u53e3\uff0c\u6240\u4ee5\u547d\u4ee4\u91cc\u9700\u8981\u52a0\u5165-p 6380\uff0c\u5176\u4ed6\u8282\u70b9\u7528\u9ed8\u8ba4\u7684\u5373\u53ef\u3002<\/p>\n

\r\n[root@test-3 redis-replica]# src\/redis-cli -p 6380\r\n127.0.0.1:6380> config set masterauth 123456\r\nOK\r\n127.0.0.1:6380> config set requirepass 123456\r\nOK\r\n127.0.0.1:6380> config rewrite\r\nOK\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u91c7\u7528\u539f\u751f\u642d\u5efa\u7684\u65b9\u5f0f\u642d\u5efa3\u4e3b3\u4ece\u7684Redis Cluster\uff0c\u5206\u522b\u7ed93\u4e2amaster\u8282\u70b9\u914d\u7f6e\u4e00\u4e2aslave\u8282\u70b9\uff0c […]<\/p>\n","protected":false},"author":1903,"featured_media":225361,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-225355","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/225355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1903"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=225355"}],"version-history":[{"count":3,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/225355\/revisions"}],"predecessor-version":[{"id":225395,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/225355\/revisions\/225395"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/225361"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=225355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=225355"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=225355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}