Last night fishing back, big crazy, wrote a summary of the programmer's life status of the article, did not expect to attract a lot of people's crucified, the trend has risen to the political level.
I may not be able to publish any more impact on the soul of the article, I hope to bring more positive energy, so that article has been deleted by me.
My intention is just to let you read the article after you can calmly think about their own program of life, whether it is right or wrong, people have the right to choose, go their own way.
I am not as pessimistic as you think, I also in unremitting efforts, even if a moment of fall, I also want to stand up again.
Life is not the pressure, let us carry the bags, take a practical step, walk!
We continue our Redis cache tour.
In the previous article we implemented a simple Redis cluster, and Redis also provided a very good tool for our convenient maintenance of the cluster.
First of all, please refer to my previous article, the cluster environment to build up.
OK, it took me a minute to build it.
[OK] All 16384 slots covered.
ZHAOGUIHUADEDIANNAO:SRC zhaogh$/redis-cli-c-P 9001
127.0.0.1:9001> Get testkey001
-Redirected to Slots [12786] located at 127.0.0.1:9003
(nil)
127.0.0.1:9003>
How to add Nodes:
First we create a directory called 9004:
Zhaoguihuadediannao:redis-cluster zhaogh$ mkdir 9004
Zhaoguihuadediannao:redis-cluster zhaogh$
Then we copy the 9001 directory of Redis-server, redis.conf two files to 9004 directories:
Zhaoguihuadediannao:redis-cluster zhaogh$ CP 9001/redis-server 9004
Zhaoguihuadediannao:redis-cluster zhaogh$ CP 9001/redis.conf 9004
Then we open the redis.conf file and modify the port configuration entry to change it to 9004.
Launch 9004 instance:
Zhaoguihuadediannao:redis-cluster zhaogh$ CD 9004
zhaoguihuadediannao:9004 zhaogh$./redis-server./redis.conf
zhaoguihuadediannao:9004 zhaogh$
To add this instance to the cluster, we only need to execute the REDIS-TRIB.RB command:
Zhaoguihuadediannao:src zhaogh$./redis-trib.rb add-node 127.0.0.1:9004 127.0.0.1:9001
The first parameter is the new instance that we just started, and the second parameter is the node already in the cluster.
Check to see if the new node has joined:
ZHAOGUIHUADEDIANNAO:SRC zhaogh$/redis-cli-c-P 9001
127.0.0.1:9001> cluster Nodes
0e8f980bfe7a682e3d71b15523a41293535b8ccd:0 myself,master-0 0 1 connected 0-5460
cbb01bdfdc265b190496956354d84aaae6e7d54d 127.0.0.1:9004 master-0 1401952316346 0 connected
708e6e14474e3a99677b05ff89bd857375884437 127.0.0.1:9002 master-0 1401952314325 2 connected 5461-10922
a7f9d3c64540cc3fc8cd3072e573bb8ab0bf1e6f 127.0.0.1:9003 master-0 1401952315334 3 connected 10923-16383
127.0.0.1:9001>
We can see that 9004 does not contain any hash slots because it does not yet have data.
We can also increase the slave node for the primary node in the cluster for read-only queries.
How to increase the slave node:
We still want to create a directory, copy those two files, modify the configuration, and then launch the instance:
Zhaoguihuadediannao:redis-cluster zhaogh$ mkdir 9005
Zhaoguihuadediannao:redis-cluster zhaogh$ CP 9001/redis-server 9005
Zhaoguihuadediannao:redis-cluster zhaogh$ CP 9001/redis.conf 9005
Modify Port to 9005
Zhaoguihuadediannao:redis-cluster zhaogh$ CD 9005
zhaoguihuadediannao:9005 zhaogh$./redis-server./redis.conf
zhaoguihuadediannao:9005 zhaogh$
Execute the following command to increase the slave node:
Zhaoguihuadediannao:src zhaogh$./redis-trib.rb add-node--slave 127.0.0.1:9005 127.0.0.1:9001
The first parameter is the slave node, and the second parameter is the primary node.
How to delete a node:
Zhaoguihuadediannao:src zhaogh$./redis-trib.rb del-node 127.0.0.1:9001 ' cbb01bdfdc265b190496956354d84aaae6e7d54d '
Note here that the first parameter is the address of any primary node in the cluster, and the second parameter is the ID of the node to be deleted, which, if you do not know it, can be viewed through the cluster nodes command.
Another point is that the node to be deleted must be empty, that is, no data can be cached, or the deletion will not succeed. For non-empty nodes, you need to re-shard the cache before deleting it, and then transfer the cached data to another node.
How to re-shard:
Let's start by making some data for a node:
ZHAOGUIHUADEDIANNAO:SRC zhaogh$/redis-cli-c-P 9001
127.0.0.1:9001> Set testkey001 testvalue001
-Redirected to Slots [12786] located at 127.0.0.1:9003
Ok
127.0.0.1:9003>
Now that we have data on the 9003, we try to delete it:
Zhaoguihuadediannao:src zhaogh$./redis-trib.rb del-node 127.0.0.1:9001 ' 78ec1fd6647b79627d7c29bb2b22d04a4a6c43b3 '
>>> removing node 78ec1fd6647b79627d7c29bb2b22d04a4a6c43b3 from cluster 127.0.0.1:9001
Connecting to Node 127.0.0.1:9001:ok
Connecting to Node 127.0.0.1:9002:ok
Connecting to Node 127.0.0.1:9003:ok
[ERR] Node 127.0.0.1:9003 is not empty! Reshard data away and try again.
ZHAOGUIHUADEDIANNAO:SRC zhaogh$
No deletion succeeds, let's re-shard and transfer the data on 9003:
Zhaoguihuadediannao:src zhaogh$./redis-trib.rb Reshard 127.0.0.1:9003
And then output a lot of information, a lot of numbers and IDs can be found from this piece of information.
How many slots does want to move (from 1 to 16384)? 5461
Will ask how many hash slots you want to move, we remove all the hash slots on 9003, 5461 this number can be seen from the terminal, perhaps your actual situation is not this number.
What is the receiving node ID? 4d2e0a8360795ce7ce8381c68746034aeba3c9b9
And then ask you where you want to move these hash slots, I've specified a node ID of 9001.
Please enter the source node IDs.
The Type ' All ' is the nodes as source nodes for the hash slots.
Type ' Done ' once your entered all the source nodes IDs.
Source node #1:78ec1fd6647b79627d7c29bb2b22d04a4a6c43b3
Source node #2:d One
After that, Redis lists the re-sharding plan and finally asks you
Do you want to proceed with the proposed Reshard plan (yes/no)? Yes
After the execution, let's see if there is a key on 9003:
Zhaoguihuadediannao:src zhaogh$./redis-cli-p 9003
127.0.0.1:9003> keys *
(empty list or set)
127.0.0.1:9003>
And see if there's this key on 9001.
ZHAOGUIHUADEDIANNAO:SRC zhaogh$./redis-cli-p 9001
127.0.0.1:9001> keys *
1) "testkey001"
127.0.0.1:9001>
Yes, it sure did move over.
Finally, let's try to delete the 9003:
Zhaoguihuadediannao:src zhaogh$./redis-trib.rb del-node 127.0.0.1:9001 ' 78ec1fd6647b79627d7c29bb2b22d04a4a6c43b3 '
>>> removing node 78ec1fd6647b79627d7c29bb2b22d04a4a6c43b3 from cluster 127.0.0.1:9001
Connecting to Node 127.0.0.1:9001:ok
Connecting to Node 127.0.0.1:9002:ok
Connecting to Node 127.0.0.1:9003:ok
>>> sending CLUSTER forget messages to the CLUSTER ...
>>> SHUTDOWN the node.
Zhaoguihuadediannao:src zhaogh$./redis-cli-p 9003
Could not connect to Redis at 127.0.0.1:9003:connection refused
Not connected>
Very good, it ' s very good.
The previous article said that the C # client is not yet well supported for Redis clusters, and next I will show you how to use proxies to implement Redis clusters.
High Performance Website Architecture Design cache Chapter (6)-Redis cluster (middle)