Download the source code
Source code with a quick build cluster script create-cluster.
Redis installation directory /util/create-cluster
The directory contains the following: create-cluster script.
There are no other files at first, except the one that creates the cluster script. All other files are generated in the current directory after the cluster is successfully created.
The target
Use the official script to create 3 primary and 3 secondary clusters.
This is a quick way to build a cluster that is primarily used locally for your own testing.
steps
Switch to the Redis installation directory /util/create-cluster directory
Start the process
Start the process
gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ ./create-cluster start
Starting 30001
Starting 30002
Starting 30003
Starting 30004
Starting 30005
Starting 30006
Copy the code
Start, use ps – ef | grep redis command, you can see six redis process.
Although six processes have been started, no cluster relationships between nodes have been created.
Create the cluster
Create the cluster
gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ ./create-cluster create / System/Library/Frameworks/Ruby framework Versions / 2.3 / usr/lib/Ruby / 2.3.0 / rubygems/core_ext/kernel_require rb: 55: in `require': cannot load such file -- redis (LoadError) from / System/Library/Frameworks/Ruby framework Versions / 2.3 / usr/lib/Ruby / 2.3.0 / rubygems/core_ext/kernel_require rb: 55: in `require' from .. /.. /src/redis-trib.rb:25:in `<main>' gongzhihaodeMacBook-Pro:create-cluster gongzhihao$Copy the code
An error occurred while creating the cluster. The reason? No Ruby dependencies are installed. The solution? Install Ruby dependencies.
Gongzhihaodemacbook-pro: creation-cluster gongzhihao$gem install redis Fetching: redis 4.2.5.gem (100%) ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ sudo gem install redis Password: Fetching: Gem (100%) Successfully installed Redis-4.2.5 Parsing documentation for Redis-4.2.5 Installing ri Documentation for Redis -4.2.5 Done installing documentation for Redis after 1 seconds 1 gem installed gongzhihaodeMacBook-Pro:create-cluster gongzhihao$Copy the code
Ruby dependencies installed successfully.
Then create the cluster again
gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ ./create-cluster create >>> Creating cluster >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 127.0.0.1:30001 127.0.0.1:30002 127.0.0.1:30003 Adding Replica 127.0.0.1:30004 to 127.0.0.1:30001 Adding Replica 127.0.0.1:30005 to 127.0.0.1:30002 Adding Replica 127.0.0.1:30006 to 127.0.0.1:30003 M: E2daf8ae63e645a64d14d4167c0381d46b0e0447 127.0.0.1:30001 slots: 0-5460 (5461 slots) master M: 3 e727eb07a42834b639d6f259b120ad97bf8659f 127.0.0.1:30002 slots: 5461-10922 (5462 slots) master M: 1 f87f72a47b02faaf243080801a582b958f57f5b 127.0.0.1:30003 slots: 10923-16383 (5461 slots) master S: F630102c69083eb11ee9230e89c6bbf368ded923 127.0.0.1:30004 replicates e2daf8ae63e645a64d14d4167c0381d46b0e0447 S: 0 ef557462c465b2c94c35a2f9bdc159e803313ef 127.0.0.1:30005 3 replicates e727eb07a42834b639d6f259b120ad97bf8659f S: 2 da73b14ee2e360becd4fe26f7c6af531d9cc019 127.0.0.1:30006 replicates f87f72a47b02faaf243080801a582b958f57f5b 1 Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join.. >>> Performing Cluster Check (using node 127.0.0.1:30001) M: E2daf8ae63e645a64d14d4167c0381d46b0e0447 127.0.0.1:30001 slots: 0-5460 (5461 slots) master M: 3 e727eb07a42834b639d6f259b120ad97bf8659f 127.0.0.1:30002 slots: 5461-10922 (5462 slots) master M: 1 f87f72a47b02faaf243080801a582b958f57f5b 127.0.0.1:30003 slots: 10923-16383 (5461 slots) master M: F630102c69083eb11ee9230e89c6bbf368ded923 127.0.0.1:30004 slots: (0 slots) master replicates e2daf8ae63e645a64d14d4167c0381d46b0e0447 M: 0 ef557462c465b2c94c35a2f9bdc159e803313ef 127.0.0.1:30005 slots: (0 slots) master replicates 3e727eb07a42834b639d6f259b120ad97bf8659f M: 2 da73b14ee2e360becd4fe26f7c6af531d9cc019 127.0.0.1:30006 slots: (0 slots) master replicates 1f87f72a47b02faaf243080801a582b958f57f5b [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. gongzhihaodeMacBook-Pro:create-cluster gongzhihao$Copy the code
Once the cluster is created, the master and slave nodes and slots are allocated.
Stop the process
gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ ./create-cluster stop
Stopping 30001
Stopping 30002
Stopping 30003
Stopping 30004
Stopping 30005
Stopping 30006
Copy the code
Using the ps command, you cannot see the process and the cluster cannot read or write.
Start the process again
gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ ./create-cluster start
Starting 30001
Starting 30002
Starting 30003
Starting 30004
Starting 30005
Starting 30006
Copy the code
Using the ps command, you can see the process and the cluster can read and write normally.
None Example Clear node information and slot data in a cluster
If you don’t want the cluster you just created, you can delete it completely.
./create-cluster clean
Copy the code
Complete operation log
gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ pwd / Users/gongzhihao/IdeaProjects/ll/XXX/redis - 3.0.7 / utils/create - cluster gongzhihaodeMacBook - Pro: create - cluster gongzhihao$ gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ ./create-cluster start Starting 30001 Starting 30002 Starting 30003 Starting 30004 Starting 30005 Starting 30006 gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ ./create-cluster create / System/Library/Frameworks/Ruby framework Versions / 2.3 / usr/lib/Ruby / 2.3.0 / rubygems/core_ext/kernel_require rb: 55: in `require': cannot load such file -- redis (LoadError) from / System/Library/Frameworks/Ruby framework Versions / 2.3 / usr/lib/Ruby / 2.3.0 / rubygems/core_ext/kernel_require rb: 55: in `require' from .. /.. /src/redis-trib.rb:25:in `<main>' gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ Gongzhihaodemacbook-pro: creation-cluster gongzhihao$gem install redis Fetching: redis 4.2.5.gem (100%) ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ sudo gem install redis Password: Fetching: Gem (100%) Successfully installed Redis-4.2.5 Parsing documentation for Redis-4.2.5 Installing ri Documentation for Redis -4.2.5 Done installing documentation for Redis after 1 seconds 1 gem installed gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ ./create-cluster create >>> Creating cluster >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 127.0.0.1:30001 127.0.0.1:30002 127.0.0.1:30003 Adding Replica 127.0.0.1:30004 to 127.0.0.1:30001 Adding Replica 127.0.0.1:30005 to 127.0.0.1:30002 Adding Replica 127.0.0.1:30006 to 127.0.0.1:30003 M: E2daf8ae63e645a64d14d4167c0381d46b0e0447 127.0.0.1:30001 slots: 0-5460 (5461 slots) master M: 3 e727eb07a42834b639d6f259b120ad97bf8659f 127.0.0.1:30002 slots: 5461-10922 (5462 slots) master M: 1 f87f72a47b02faaf243080801a582b958f57f5b 127.0.0.1:30003 slots: 10923-16383 (5461 slots) master S: F630102c69083eb11ee9230e89c6bbf368ded923 127.0.0.1:30004 replicates e2daf8ae63e645a64d14d4167c0381d46b0e0447 S: 0 ef557462c465b2c94c35a2f9bdc159e803313ef 127.0.0.1:30005 3 replicates e727eb07a42834b639d6f259b120ad97bf8659f S: 2 da73b14ee2e360becd4fe26f7c6af531d9cc019 127.0.0.1:30006 replicates f87f72a47b02faaf243080801a582b958f57f5b 1 Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join.. >>> Performing Cluster Check (using node 127.0.0.1:30001) M: E2daf8ae63e645a64d14d4167c0381d46b0e0447 127.0.0.1:30001 slots: 0-5460 (5461 slots) master M: 3 e727eb07a42834b639d6f259b120ad97bf8659f 127.0.0.1:30002 slots: 5461-10922 (5462 slots) master M: 1 f87f72a47b02faaf243080801a582b958f57f5b 127.0.0.1:30003 slots: 10923-16383 (5461 slots) master M: F630102c69083eb11ee9230e89c6bbf368ded923 127.0.0.1:30004 slots: (0 slots) master replicates e2daf8ae63e645a64d14d4167c0381d46b0e0447 M: 0 ef557462c465b2c94c35a2f9bdc159e803313ef 127.0.0.1:30005 slots: (0 slots) master replicates 3e727eb07a42834b639d6f259b120ad97bf8659f M: 2 da73b14ee2e360becd4fe26f7c6af531d9cc019 127.0.0.1:30006 slots: (0 slots) master replicates 1f87f72a47b02faaf243080801a582b958f57f5b [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ ./create-cluster stop Stopping 30001 Stopping 30002 Stopping 30003 Stopping 30004 Stopping 30005 Stopping 30006 gongzhihaodeMacBook-Pro:create-cluster gongzhihao$ ./create-cluster start Starting 30001 Starting 30002 Starting 30003 Starting 30004 Starting 30005 Starting 30006 gongzhihaodeMacBook-Pro:create-cluster gongzhihao$Copy the code
How it works – What does a script contain?
In fact, the installation directory/SRC /redis-server and redis-cli scripts are executed
Directory where redis-server and redis-CLI scripts reside
reference
Huang Jianhong’s book redis Manual