In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Set up Redis cluster
Prepare 6 redis servers with the following specific requirements:
Ip address port etho log file name
192.168.4.51 6051 can receive connection request redis51.log
192.168.4.52 6052 can receive connection request redis52.log
192.168.4.53 6053 can receive connection request redis53.log
192.168.4.54 6054 can receive connection request redis54.log
192.168.4.55 6055 can receive connection request redis55.log
192.168.4.56 6056 can receive connection request redis56.log
Environmental preparation
1 run the service on 6 redis servers. After modifying the configuration file according to the following requirements, restart the redis service and clear.
Generate key and transfer key
[root@51 ~] # ssh-keygen
[root@51] # for i in 192.168.4. {51.. 56}
Do
Ssh-copy-id $I
Done
Create a redis on each host
[root@51] # tar-xf redis/redis-4.0.8.tar.gz-C.
[root@51 ~] # cd redis-4.0.8/
[root@51 redis-4.0.8] # yum-y install gcc gcc-c++
[root@51 redis-4.0.8] # make & & make install
[root@51 redis-4.0.8] #. / utils/install_server.sh
[root@51 redis-4.0.8] # ln-s / etc/init.d/redis_6379 / bin/
Here you can also write a script to install redis in bulk.
1.1 clear data (do the same on 51-56)
[root@51 phpredis-2.2.4] # redis-cli-h 192.168.4.51-p 6051
192.168.4.51 purl 6051 > FLUSHALL
OK
192.168.4.51 > keys *
(empty list or set)
192.168.4.51purl 6051 >
[root@51 phpredis-2.2.4] # vim / etc/redis/6379.conf
70 bind 192.168.4.51 / / physical interface ip address
93 port 6051 / / Port
Daemonize yes / / runs in daemon mode
815 cluster-enabled yes / / start the cluster
Do not use the default name for the configuration file of cluster-config-file nodes-6051.conf / / cluster
829 cluster-node-timeout 15000 / / request timed out 5 seconds
[root@51 phpredis-2.2.4] # redis_6379 stop
[root@51 phpredis-2.2.4] # redis_6379 start
[root@51 ~] # ss-antulp | grep redis
Tcp LISTEN 0 128 192.168.4.51 tcp LISTEN: users: ("redis-server", pid=24771,fd=6)
Tcp LISTEN 0 128 192.168.4.51 tcp LISTEN: users: ("redis-server", pid=24771,fd=8)
Package: install the ruby package on the host where the create cluster command is executed
Install the software package that interprets the ruby code (installed on 51)
[root@51 redis] # yum-y install ruby ruygems
[root@51 redis] # rpm-q rubygems ruby
Rubygems-2.0.14.1-30.el7.noarch
Ruby-2.0.0.648-30.el7.x86_64
[root@51 redis-cluster] # rpm-ivh-- nodeps ruby-devel-2.0.0.648-30.el7.x86_64.rpm
Install the ruby connection redis interface program gem
[root@51 redis-cluster] # gem install redis-3.2.1.gem
Generate the script redis-trib.rb to create the cluster
[root@51 redis] # tar-xf redis-4.0.8.tar.gz
[root@51 redis] # cd redis-4.0.8/
[root@51 redis-4.0.8] # ln-s / root/redis/redis-4.0.8/src/redis-trib.rb / sbin/
Create a cluster:
[root@51 redis-4.0.8] # redis-trib.rb create-- replicas 1\
192.168.4.51 purl 6051\
192.168.4.52 purl 6052\
192.168.4.53 purl 6053\
192.168.4.54 purl 6054\
192.168.4.55 purl 6055\
192.168.4.56:6056
Creating cluster
Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.4.51:6051
192.168.4.52:6052
192.168.4.53:6053
Adding replica 192.168.4.55:6055 to 192.168.4.51:6051
Adding replica 192.168.4.56:6056 to 192.168.4.52:6052
Adding replica 192.168.4.54:6054 to 192.168.4.53:6053
M: c5f725669ad74fbf48b907b06c3b0ff6ca5eeb01 192.168.4.51:6051
Slots:0-5560 (5561 slots) master
M: 2c9ee556add7e5187621efd64e4a9fc54bc99489 192.168.4.52:6052
Slots:5561-10922 (5562 slots) master
M: bcb32a6d6b9e988789e654c32856c8c478ef253e 192.168.4.53:6053
Slots:10923-16383 (5561 slots) master
S: 799f99bc22d8c4a9e0fcdc98166f6e6f5e348df0 192.168.4.54:6054
Replicates bcb32a6d6b9e988789e654c32856c8c478ef253e
S: 18b86bca8fa9c9d36f3cad927a1c75c825bee9a4 192.168.4.55:6055
Replicates c5f725669ad74fbf48b907b06c3b0ff6ca5eeb01
S: 6a7196a77555cdf14f1a665386ff493928b31d94 192.168.4.56:6056
Replicates 2c9ee556add7e5187621efd64e4a9fc54bc99489
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 192.168.4.51)
M: c5f725669ad74fbf48b907b06c3b0ff6ca5eeb01 192.168.4.51:6051
Slots:0-5560 (5561 slots) master
1 additional replica (s)
S: 6a7196a77555cdf14f1a665386ff493928b31d94 192.168.4.56:6056
Slots: (0 slots) slave
Replicates 2c9ee556add7e5187621efd64e4a9fc54bc99489
....
.
Replicates bcb32a6d6b9e988789e654c32856c8c478ef253e
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
[root@51 redis-4.0.8] # cat / var/lib/redis/6379/nodes-6051.conf # Cluster configuration file
6a7196a77555cdf14f1a665386ff493928b31d94 192.168.4.56 connected 6056 slave 2c9ee556add7e5187621efd64e4a9fc54bc99489 01530777397000 6
. .
.
Each redis service logs in locally to view cluster information
[root@51 redis-4.0.8] # redis-cli-c-h 192.168.4.51-p 6051
192.168.4.51 6051 > CLUSTER INFO # View cluster information
Cluster_state:ok
Cluster_slots_assigned:16384
Cluster_slots_ok:16384
Cluster_slots_pfail:0
Cluster_slots_fail:0
Cluster_known_nodes:6
Cluster_size:3
Cluster_current_epoch:6
Cluster_my_epoch:1
Cluster_stats_messages_ping_sent:934
Cluster_stats_messages_pong_sent:1137
Cluster_stats_messages_sent:2071
Cluster_stats_messages_ping_received:1132
Cluster_stats_messages_pong_received:934
Cluster_stats_messages_meet_received:5
Cluster_stats_messages_received:2071
192.168.4.51 6051 > CLUSTER NODES # View local information
6a7196a77555cdf14f1a665386ff493928b31d94 192.168.4.56 connected 6056 slave 2c9ee556add7e5187621efd64e4a9fc54bc99489 01530778521000 6
Bcb32a6d6b9e988789e654c32856c8c478ef253e 192.168.4.53 bcb32a6d6b9e988789e654c32856c8c478ef253e 6053 master-01530778520185 3 connected 10923-16383
18b86bca8fa9c9d36f3cad927a1c75c825bee9a4 192.168.4.55 connected 6055 connected 16055 slave c5f725669ad74fbf48b907b06c3b0ff6ca5eeb01 0 1530778521000
2c9ee556add7e5187621efd64e4a9fc54bc99489 192.168.4.52 master-0 1530778521187 2 connected 5561-10922
799f99bc22d8c4a9e0fcdc98166f6e6f5e348df0 192.168.4.54 connected 6054 connected 16054 slave bcb32a6d6b9e988789e654c32856c8c478ef253e 0 1530778520000 4
C5f725669ad74fbf48b907b06c3b0ff6ca5eeb01 192.168.4.51 myself,master-0 1530778519000 1 connected 0-5560
Test cluster:
Connect to the master library to store data, and the corresponding slave library will automatically synchronize the data
[root@51 ~] # redis-cli-c-h master library ip address-p corresponding port number
Master::
[root@51 redis-4.0.8] # redis-cli-c-h 192.168.4.51-p 6051
192.168.4.51 6051 > set age 10
192.168.4.51 purl 6051 > set name aa
192.168.4.52 > keys *
1) "name"
Slave:
[root@52 phpredis-2.2.4] # redis-cli-c-h 192.168.4.52-p 6052
192.168.4.52 > keys *
1) "name"
Option parameter
-add-node add new node (default master)
-check checks the node host
-reshard re-shards the node host
-add-node-- slave add slave node host
-del-node delete node host
Cluster election test: the slave that stops the redis service of a master library will automatically upgrade the master library
[root@51 redis-4.0.8] # redis-trib.rb check 192.168.4.51:6051
M: bcb32a6d6b9e988789e654c32856c8c478ef253e 192.168.4.53:6053
Slots:10923-16383 (5561 slots) master
1 additional replica (s)
S: 18b86bca8fa9c9d36f3cad927a1c75c825bee9a4 192.168.4.54:6054
Slots: (0 slots) slave
Replicates c5f725669ad74fbf48b907b06c3b0ff6ca5eeb01
..
So we can see that 4.53 is master, 4.55 is slave, now let's stop 53.
[root@53] # redis-cli-c-h 192.168.4.53-p 6053 shutdown
[root@51 redis-4.0.8] # redis-trib.rb check 192.168.4.51:6051
M: 799f99bc22d8c4a9e0fcdc98166f6e6f5e348df0 192.168.4.54:6054
Slots:10923-16383 (5561 slots) master
Re-fragment the node host
[root@51 ~] # redis-trib.rb reshard 192.168.4.51 purl 6051
How many slots do you want to move (from 1 to 16384)? 5196
What is the receiving node ID? C5f725669ad74fbf48b907b06c3b0ff6ca5eeb01
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
Type 'done' once you entered all the source nodes IDs.
Source node # 1:799f99bc22d8c4a9e0fcdc98166f6e6f5e348df0
Add a primary node host:
Node added by redis-trib.rb add-node: Port number cluster master node: Port number
[root@51 ~] # redis-trib.rb add-node 192.168.4.48 6048 192.168.4.51
Add slave node
Redis-trib.rb add-node-- slave slave node ip: Port 192.168.4.51VR 6351
* if the id of the master node is not specified, the new node will be randomly added as the master slave with the least number of slave nodes
[root@51] # redis-trib.rb add-node-- slave 192.168.4.51 slave 6051 192.168.4.51
Delete node host
Delete slave library
[root@51 ~] # redis-trib.rb del-node 192.168.4.51 676c81e55e491ea7d4f9eb9f53d5c72abc1b8513
Removing node 676c81e55e491ea7d4f9eb9f53d5c72abc1b8513 from cluster 192.168.4.51:6051
Sending CLUSTER FORGET messages to the cluster...
SHUTDOWN the node.
If you want to rejoin the deleted data nodes into the cluster, you need to restore the database.
[root@51] # redis-cli-h 192.168.4.51-p 6051
192.168.4.51 purl 6051 > CLUSTER INFO
Cluster_state:ok
Cluster_slots_assigned:16384
Cluster_slots_ok:16384
Cluster_slots_pfail:0
Cluster_slots_fail:0
Cluster_known_nodes:9
Cluster_size:3
.
192.168.4.51 purl 6051 > CLUSTER RESET
OK
192.168.4.51 purl 6051 > CLUSTER INFO
Cluster_state:fail
Cluster_slots_assigned:0
Cluster_slots_ok:0
Cluster_slots_pfail:0
Only in this way can we add it again.
Delete host master
[root@51 ~] # redis-trib.rb reshard 192.168.4.51 purl 6051
How many slots do you want to move (from 1 to 16384)? 2000 # increased number of slots
Which node is What is the receiving node ID? 18ad59ca4d756e61a5076ea2f6a93d567e521a5c # added to
Source node # 1:6e8a84fdd95193fd53a9386f8b24c24c4e5122ff # which node is moved up and down?
Do you want to proceed with the proposed reshard plan (yes/no)? yes
[root@51 ~] # redis-trib.rb del-node 192.168.4.48 6e8a84fdd95193fd53a9386f8b24c24c4e5122ff
Removing node 6e8a84fdd95193fd53a9386f8b24c24c4e5122ff from cluster 192.168.4.48
Invalid IP or Port (given as 192.168.4.48)-use IP:Port format
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
You can see that each time it increases to 1, the specific operation plan:
© 2024 shulou.com SLNews company. All rights reserved.