One 、 Environmental planning

# Prepare six hosts , The address is as follows 
10.0.0.8 ---> master1
10.0.0.18 ---> master2
10.0.0.28 ---> master3
10.0.0.38 ---> slave1
10.0.0.48 ---> slave2
10.0.0.58 ---> slave3

Two 、 To configure redis cluster

2.1 Deploy redis

## install redis
# dnf -y install redis
# redis-server --version
Redis server v=5.0.3 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=9529b692c0384fb7 ## Modify the configuration file
# sed -i.bak -e 's/bind 127.0.0.1/bind 0.0.0.0/' \
-e '/# masterauth/c masterauth 123456' \
-e '/# requirepass/c requirepass 123456' \
-e '/# cluster-enabled yes/c cluster-enabled yes' \
-e '/# cluster-config-file nodes-6379.conf/c cluster-config-file nodes-6379.conf' \
-e '/# cluster-require-full-coverage/c cluster-require-full-coverage no' \
/etc/redis.conf ## verification Redis Service status
# ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:6379 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 100 127.0.0.1:25 0.0.0.0:*
LISTEN 0 128 0.0.0.0:16379 0.0.0.0:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*

2.2 To configure reis cluster

##redis-cli --cluster-replicas 1  Represent each master Corresponding to one slave node 
# redis-cli -a 123456 --cluster create 10.0.0.8:6379 10.0.0.18:6379 10.0.0.28:6379 10.0.0.38:6379 10.0.0.48:6379 10.0.0.58:6379 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 10.0.0.38:6379 to 10.0.0.8:6379
Adding replica 10.0.0.48:6379 to 10.0.0.18:6379
Adding replica 10.0.0.58:6379 to 10.0.0.28:6379
M: 7a4443e815ca6009d8e25e5f84d2f5feee3c007a 10.0.0.8:6379 ## belt M For the master
slots:[0-5460] (5461 slots) master ## At present master Start and end bits of the slot
M: 2f41d6b0a3b8957755b67b2dccfb764dee57f123 10.0.0.18:6379
slots:[5461-10922] (5462 slots) master
M: 4e0eb42d503974e00962fa1d0214593720327d4a 10.0.0.28:6379
slots:[10923-16383] (5461 slots) master
S: 5308ffa51d731096d8c9e86d2f3976cb94fa7fa8 10.0.0.38:6379 ## belt S Of slave
replicates 7a4443e815ca6009d8e25e5f84d2f5feee3c007a
S: 67eb5b5226f01b6dde9145fe4063b1f4849fe921 10.0.0.48:6379
replicates 2f41d6b0a3b8957755b67b2dccfb764dee57f123
S: 128518070585eb054210b322b8a6f910cc2849f8 10.0.0.58:6379
replicates 4e0eb42d503974e00962fa1d0214593720327d4a
Can I set the above configuration? (type 'yes' to accept): yes ## Input yes Automatically create clusters
>>> 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 10.0.0.8:6379)
M: 7a4443e815ca6009d8e25e5f84d2f5feee3c007a 10.0.0.8:6379
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 67eb5b5226f01b6dde9145fe4063b1f4849fe921 10.0.0.48:6379
slots: (0 slots) slave
replicates 2f41d6b0a3b8957755b67b2dccfb764dee57f123
M: 2f41d6b0a3b8957755b67b2dccfb764dee57f123 10.0.0.18:6379
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 128518070585eb054210b322b8a6f910cc2849f8 10.0.0.58:6379
slots: (0 slots) slave
replicates 4e0eb42d503974e00962fa1d0214593720327d4a
S: 5308ffa51d731096d8c9e86d2f3976cb94fa7fa8 10.0.0.38:6379
slots: (0 slots) slave
replicates 7a4443e815ca6009d8e25e5f84d2f5feee3c007a
M: 4e0eb42d503974e00962fa1d0214593720327d4a 10.0.0.28:6379
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration. ## All node slot allocation is completed
>>> Check for open slots... ## Check the open slot
>>> Check slots coverage... ## Check slot coverage
[OK] All 16384 slots covered. # All slots (16384 individual ) Distribution complete ### Observe the above results , You can see 3 Group master/slave
master:10.0.0.8---slave:10.0.0.38
master:10.0.0.18---slave:10.0.0.48
master:10.0.0.28---slave:10.0.0.58

2.3 Check the master-slave status 、 State of the cluster

# redis-cli -a 123456 -h 10.0.0.18 --no-auth-warning cluster nodes

2.4 Analog fault

## simulation master1(IP:10.0.0.8) Node failure 
# redis-cli -a 123456 shutdown ## close master1
# tail -f /var/log/redis/redis.log
2300:C 23 Jan 2022 12:11:41.952 * DB saved on disk
2300:C 23 Jan 2022 12:11:41.952 * RDB: 4 MB of memory used by copy-on-write
2296:M 23 Jan 2022 12:11:42.027 * Background saving terminated with success
2296:M 23 Jan 2022 12:11:42.028 * Synchronization with replica 10.0.0.38:6379 succeeded
2296:M 23 Jan 2022 12:11:43.081 # Cluster state changed: ok
2296:M 23 Jan 2022 12:14:45.924 # User requested shutdown...
2296:M 23 Jan 2022 12:14:45.924 * Saving the final RDB snapshot before exiting.
2296:M 23 Jan 2022 12:14:45.927 * DB saved on disk
2296:M 23 Jan 2022 12:14:45.927 * Removing the pid file.
2296:M 23 Jan 2022 12:14:45.927 # Redis is now ready to exit, bye bye... ## View role changes
# redis-cli -a 123456 -h 10.0.0.38 --no-auth-warning cluster nodes
4e0eb42d503974e00962fa1d0214593720327d4a 10.0.0.28:[email protected] master - 0 1636914427274 3 connected 10923-16383
2f41d6b0a3b8957755b67b2dccfb764dee57f123 10.0.0.18:[email protected] master - 0 1636914429452 2 connected 5461-10922
128518070585eb054210b322b8a6f910cc2849f8 10.0.0.58:[email protected] slave 4e0eb42d503974e00962fa1d0214593720327d4a 0 1636914423993 6 connected
67eb5b5226f01b6dde9145fe4063b1f4849fe921 10.0.0.48:[email protected] slave 2f41d6b0a3b8957755b67b2dccfb764dee57f123 0 1636914430542 5 connected
7a4443e815ca6009d8e25e5f84d2f5feee3c007a 10.0.0.8:[email protected] master,fail - 1636913491097 1636913490340 1 disconnected
5308ffa51d731096d8c9e86d2f3976cb94fa7fa8 10.0.0.38:[email protected] myself,master - 0 0 8 connected 0-5460 ## see slave1 Log
# tail -f /var/log/redis/redis.log
2050:S 15 Nov 2021 02:11:47.767 * FAIL message received from 2f41d6b0a3b8957755b67b2dccfb764dee57f123 about 7a4443e815ca6009d8e25e5f84d2f5feee3c007a
2050:S 15 Nov 2021 02:11:47.867 # Start of election delayed for 795 milliseconds (rank #0, offset 238).
2050:S 15 Nov 2021 02:11:48.733 * Connecting to MASTER 10.0.0.8:6379
2050:S 15 Nov 2021 02:11:48.734 * MASTER <-> REPLICA sync started
2050:S 15 Nov 2021 02:11:48.734 # Starting a failover election for epoch 8.
2050:S 15 Nov 2021 02:11:48.736 # Error condition on socket for SYNC: Connection refused
2050:S 15 Nov 2021 02:11:48.738 # Failover election won: I'm the new master. ## Has become a new master
2050:S 15 Nov 2021 02:11:48.738 # configEpoch set to 8 after successful failover
2050:M 15 Nov 2021 02:11:48.738 # Setting secondary replication ID to 68e9f4f70b4fec8086c0717b8981d5adca478be0, valid up to offset: 239. New replication ID is 22f817fbe0ef49a3c0ef26e5a34ccd1f38743bde
2050:M 15 Nov 2021 02:11:48.738 * Discarding previously cached master state.

2.5 Recovery failure

# systemctl start redis

# redis-cli  -a 123456 -h 10.0.38 info replication
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:master
connected_slaves:1
slave0:ip=10.0.0.8,port=6379,state=online,offset=644,lag=1
master_replid:22f817fbe0ef49a3c0ef26e5a34ccd1f38743bde
master_replid2:68e9f4f70b4fec8086c0717b8981d5adca478be0
master_repl_offset:658
second_repl_offset:239
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:658 # redis-cli -a 123456 -h 10.0.8 info replication
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:10.0.0.38
master_port:6379
master_link_status:up
master_last_io_seconds_ago:5
master_sync_in_progress:0
slave_repl_offset:826
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:22f817fbe0ef49a3c0ef26e5a34ccd1f38743bde
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:826
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:239
repl_backlog_histlen:588 ## View final master/slave Relationship
# redis-cli -a 123456 -h 10.0.0.8 --no-auth-warning cluster nodes
[[email protected] ~]#redis-cli -a 123456 -h 10.0.0.8 --no-auth-warning cluster nodes
4e0eb42d503974e00962fa1d0214593720327d4a 10.0.0.28:[email protected] master - 0 1642914346272 3 connected 10923-16383
67eb5b5226f01b6dde9145fe4063b1f4849fe921 10.0.0.48:[email protected] slave 2f41d6b0a3b8957755b67b2dccfb764dee57f123 0 1642914339763 5 connected
2f41d6b0a3b8957755b67b2dccfb764dee57f123 10.0.0.18:[email protected] master - 0 1642914344105 2 connected 5461-10922
7a4443e815ca6009d8e25e5f84d2f5feee3c007a 10.0.0.8:[email protected] myself,slave 5308ffa51d731096d8c9e86d2f3976cb94fa7fa8 0 1642913710880 1 connected
128518070585eb054210b322b8a6f910cc2849f8 10.0.0.58:[email protected] slave 4e0eb42d503974e00962fa1d0214593720327d4a 0 1642914345195 6 connected
5308ffa51d731096d8c9e86d2f3976cb94fa7fa8 10.0.0.38:[email protected] master - 0 1642914341929 8 connected 0-5460

It can be seen that ,master1 Recovery failure did not re acquire master role , But rather slave Role exists

be based on redis5 Of redis cluster More articles on deployment

  1. window Next use Redis Cluster Deploy Redis colony

    Cache is often used in daily projects .redis It's a better choice . Generally speaking, being a master-slave can meet the needs of some relatively small projects . In some projects with large concurrency, clusters may be needed ,redis stay Windows The next cluster can ...

  2. Redis Cluster Deploy 、 Management and testing

    background : Redis 3.0 And then supported Cluster, Greatly enhanced Redis The ability to expand horizontally .Redis Cluster yes Redis The implementation of official cluster , Before that, there was a third party Redis Clustering solutions , Such as Twen ...

  3. redis cluster Deployment process

    One , characteristic High performance : 1. In a multi slice node , take 16384 Slots , Evenly distributed to multiple patch nodes 2. Save data , take key do crc16(key), And then 16384 Take the mold , Get the slot value (0-16383 Between ) 3. root ...

  4. 【 original 】 It's based on .NET Of Redis Cluster Cluster access components

    Hello Hello everyone , I am a TANZAME, We meet again . Today we're going to talk about how to make one  Redis Cluster Cluster clients , There are dry goods by hand , Your fine products . As the business grows , Online environment QPS bulge , Naturally, the current single ...

  5. 【docker】【redis】2.docker Set up redis colony ---Redis Cluster Deploy 【 The cluster service 】【 The solution is docker in redis After starting , Status as Restarting, Log error :Configured to not listen anywhere, exiting. problem 】【Waiting for the cluster to join... problem 】

    Reference address :https://www.cnblogs.com/zhoujinyi/p/6477133.html https://www.cnblogs.com/cxbhakim/p/9151720.htm ...

  6. stay K8S Rapid deployment in Redis Cluster &amp; Redisinsight

    Redis Cluster Deploy Use Bitnami helm chart stay K8S redis One click deployment in namespace Redis cluster . helm repo add bitnami h ...

  7. Redis Cluster Principle related explanation

    background Previously written  Redis Cluster Deploy . Management and testing   and  Redis 5.0 redis-cli --cluster help explain   How to install and maintain has been introduced in detail Cluster. But about Clu ...

  8. be based on redis5 Of session share :【redis 5.x Research on cluster application 】

    be based on springsession Construct a session Shared modules . here , be based on redis The cluster of (Redis-5.0.3 edition ), In order to solve the problem of sharing among subsystems of the whole IOT platform session demand , And convenient for all subsystems ...

  9. How to use docker Deploy redis cluster

    Preface Because I am a docker control , I don't like installing in various environments , And installation redis-trib It's a little cumbersome , Simply use docker To do it redis cluster. This paper uses pseudo cluster , Real clusters can be put on different machines . The port is ...

  10. Redis Cluster The construction and deployment of , Realization redis The distributed solution

    Preface Part 1 Redis Sentinel Installation and deployment , Realization redis The high availability of redis High availability , The main target is master An outage , We found that the data of all nodes is the same , So once the amount of data is too large ,redi It will be ...

Random recommendation

  1. Adobe Flash Builder 4.6 Cracking method

    http://hi.baidu.com/cm186man/blog/item/148658ce557c0323b700c853.html 1. To Adobe Download from the official website FlashBuilder 4.6, Yes, Jane ...

  2. mybatis How to find a field in the table , And then return their result set list ?

    <select id="findArgByParams" resultType="string" parameterType="map" ...

  3. 11 Kind of dialogBox Style packaging is open source , Explain one by one

    long-awaited ,APICloud The official finally encapsulated all kinds of prompt styles , You don't have to force yourself to encapsulate all kinds of abused custom styles anymore . This share I put dialogBox Modular 11 Each style achieves a simple effect , Among them, the alert ...

  4. linux Under the configuration environment variable 【 original 】

    User directory .profile, You just need to be in the user directory , establish bin Catalog , Put the executable you want to execute in it , You can use it on the command line # ~/.profile: executed by the com ...

  5. DevExpress GridView.CustomSummaryCalculate Implement customization Group Summary

    -- First in blog Park ,  Reprint please keep the link    The original blog DevExpress Documentation Official address :GridView.CustomSummaryCalculate Event 1. Summary On the interface ...

  6. Control Algorithm related

    Control Algorithm related Add new control Official tutorial of Algorithm . Create a controller : In the file control_config Add the configuration information of the new controller : Register a new controller . How to add new CAN card . Apollo in ...

  7. 【 turn 】Java Basics :System.out.println And System.err.println The difference between

    At the same time System.out.println And System.err.println() Print the input , The result is different from what we expected , The order is not the same as expected err and out The difference between , But because they are two ...

  8. install logstash and logstash-input-jdbc

    One . install logstash 1.mac Go straight brew install logstash Two . install logstash-input-jdbc Directly in logstash Installation directory bin Run under ./logsta ...

  9. 【Unix Network programming 】chapter8 basic UDP Socket programming

    chapter8 basic UDP Socket programming 8.1 summary Typical UDP client / Server side function call 8.2 recvfrom and sendto function #include <sys/socket.h> ssi ...

  10. IOS In the system ,Web Application's cookie Reading and writing

    When testing project compatibility , Found in iphone In the browser of ,cookie Abnormal reading and writing of , Data consistency is wrong Finally found cookie Medium value Need to carry out encode  = =!...... write in cookie when , Use Ht ...