Redis主从集群主机下线从机成为主机且主机连接回集群将变成从机—–Redis

192.168.92.130:6383> quit
[root@localhost cluster]# redis-cli -a abc123 -p 6381 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6381> shutdown
not connected> quit
[root@localhost cluster]# redis-cli -a abc123 -p 6382 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6382> cluster nodes
a5757758fd0bdd8106e10905bbd1674c574f10c1 192.168.92.131:6386@16386 slave 1fca4878cd2a2a4fe055003f53d53c84cb589859 0 1706013398731 3 connected
ee718fe879729ec1f961b08c4342c78537997ab4 192.168.92.129:6381@16381 master,fail - 1706013346893 1706013345000 1 disconnected
69d920127eec13adc0d9fcaf0e9448a80d1a4803 192.168.92.130:6384@16384 master - 0 1706013398000 7 connected 0-5460
2eabe702c6bba38aee780477fab74bc4969d9bf3 192.168.92.129:6382@16382 myself,slave 30b1f7bfccd93049117e1dab1cd6385eaf800015 0 1706013398000 5 connected
30b1f7bfccd93049117e1dab1cd6385eaf800015 192.168.92.131:6385@16385 master - 0 1706013399538 5 connected 10923-16383
1fca4878cd2a2a4fe055003f53d53c84cb589859 192.168.92.130:6383@16383 master - 0 1706013399538 3 connected 5461-10922
127.0.0.1:6382> set k1 v11
-> Redirected to slot [12706] located at 192.168.92.131:6385
OK
192.168.92.131:6385> set k2 v2
-> Redirected to slot [449] located at 192.168.92.130:6384
OK
192.168.92.130:6384> 
192.168.92.130:6384> set k2 v22
OK
192.168.92.130:6384> set k3 v33
OK
192.168.92.130:6384> cluster nodes
30b1f7bfccd93049117e1dab1cd6385eaf800015 192.168.92.131:6385@16385 master - 0 1706013534549 5 connected 10923-16383
a5757758fd0bdd8106e10905bbd1674c574f10c1 192.168.92.131:6386@16386 slave 1fca4878cd2a2a4fe055003f53d53c84cb589859 0 1706013534041 3 connected
69d920127eec13adc0d9fcaf0e9448a80d1a4803 192.168.92.130:6384@16384 myself,master - 0 1706013535000 7 connected 0-5460
ee718fe879729ec1f961b08c4342c78537997ab4 192.168.92.129:6381@16381 master,fail - 1706013348018 1706013345453 1 disconnected
1fca4878cd2a2a4fe055003f53d53c84cb589859 192.168.92.130:6383@16383 master - 0 1706013533535 3 connected 5461-10922
2eabe702c6bba38aee780477fab74bc4969d9bf3 192.168.92.129:6382@16382 slave 30b1f7bfccd93049117e1dab1cd6385eaf800015 0 1706013535560 5 connected
192.168.92.130:6384> quit
[root@localhost cluster]# redis-server /myredis/cluster/redisCluster6381.conf 
[root@localhost cluster]# redis-cli -a abc123 -p 6381 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6381> cluster nodes
69d920127eec13adc0d9fcaf0e9448a80d1a4803 192.168.92.130:6384@16384 master - 0 1706013588124 7 connected 0-5460
a5757758fd0bdd8106e10905bbd1674c574f10c1 192.168.92.131:6386@16386 slave 1fca4878cd2a2a4fe055003f53d53c84cb589859 0 1706013588000 3 connected
2eabe702c6bba38aee780477fab74bc4969d9bf3 192.168.92.129:6382@16382 slave 30b1f7bfccd93049117e1dab1cd6385eaf800015 0 1706013586513 5 connected
1fca4878cd2a2a4fe055003f53d53c84cb589859 192.168.92.130:6383@16383 master - 0 1706013587116 3 connected 5461-10922
30b1f7bfccd93049117e1dab1cd6385eaf800015 192.168.92.131:6385@16385 master - 0 1706013587000 5 connected 10923-16383
ee718fe879729ec1f961b08c4342c78537997ab4 192.168.92.129:6381@16381 myself,slave 69d920127eec13adc0d9fcaf0e9448a80d1a4803 0 1706013587000 7 connected
127.0.0.1:6381> info replication
# Replication
role:slave
master_host:192.168.92.130
master_port:6384
master_link_status:up
master_last_io_seconds_ago:6
master_sync_in_progress:0
slave_read_repl_offset:2293
slave_repl_offset:2293
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:d2d35f3efda780fa7d82c678cb0b888439db221c
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:2293
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2252
repl_backlog_histlen:42

192.168.92.130:6383> quit
[root@localhost cluster]# redis-cli -a abc123 -p 6381 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6381> shutdown
not connected> quit
[root@localhost cluster]# redis-cli -a abc123 -p 6382 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6382> cluster nodes
a5757758fd0bdd8106e10905bbd1674c574f10c1 192.168.92.131:6386@16386 slave 1fca4878cd2a2a4fe055003f53d53c84cb589859 0 1706013398731 3 connected
ee718fe879729ec1f961b08c4342c78537997ab4 192.168.92.129:6381@16381 master,fail - 1706013346893 1706013345000 1 disconnected
69d920127eec13adc0d9fcaf0e9448a80d1a4803 192.168.92.130:6384@16384 master - 0 1706013398000 7 connected 0-5460
2eabe702c6bba38aee780477fab74bc4969d9bf3 192.168.92.129:6382@16382 myself,slave 30b1f7bfccd93049117e1dab1cd6385eaf800015 0 1706013398000 5 connected
30b1f7bfccd93049117e1dab1cd6385eaf800015 192.168.92.131:6385@16385 master - 0 1706013399538 5 connected 10923-16383
1fca4878cd2a2a4fe055003f53d53c84cb589859 192.168.92.130:6383@16383 master - 0 1706013399538 3 connected 5461-10922
127.0.0.1:6382> set k1 v11
-> Redirected to slot [12706] located at 192.168.92.131:6385
OK
192.168.92.131:6385> set k2 v2
-> Redirected to slot [449] located at 192.168.92.130:6384
OK
192.168.92.130:6384> 
192.168.92.130:6384> set k2 v22
OK
192.168.92.130:6384> set k3 v33
OK
192.168.92.130:6384> cluster nodes
30b1f7bfccd93049117e1dab1cd6385eaf800015 192.168.92.131:6385@16385 master - 0 1706013534549 5 connected 10923-16383
a5757758fd0bdd8106e10905bbd1674c574f10c1 192.168.92.131:6386@16386 slave 1fca4878cd2a2a4fe055003f53d53c84cb589859 0 1706013534041 3 connected
69d920127eec13adc0d9fcaf0e9448a80d1a4803 192.168.92.130:6384@16384 myself,master - 0 1706013535000 7 connected 0-5460
ee718fe879729ec1f961b08c4342c78537997ab4 192.168.92.129:6381@16381 master,fail - 1706013348018 1706013345453 1 disconnected
1fca4878cd2a2a4fe055003f53d53c84cb589859 192.168.92.130:6383@16383 master - 0 1706013533535 3 connected 5461-10922
2eabe702c6bba38aee780477fab74bc4969d9bf3 192.168.92.129:6382@16382 slave 30b1f7bfccd93049117e1dab1cd6385eaf800015 0 1706013535560 5 connected
192.168.92.130:6384> quit
[root@localhost cluster]# redis-server /myredis/cluster/redisCluster6381.conf 
[root@localhost cluster]# redis-cli -a abc123 -p 6381 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6381> cluster nodes
69d920127eec13adc0d9fcaf0e9448a80d1a4803 192.168.92.130:6384@16384 master - 0 1706013588124 7 connected 0-5460
a5757758fd0bdd8106e10905bbd1674c574f10c1 192.168.92.131:6386@16386 slave 1fca4878cd2a2a4fe055003f53d53c84cb589859 0 1706013588000 3 connected
2eabe702c6bba38aee780477fab74bc4969d9bf3 192.168.92.129:6382@16382 slave 30b1f7bfccd93049117e1dab1cd6385eaf800015 0 1706013586513 5 connected
1fca4878cd2a2a4fe055003f53d53c84cb589859 192.168.92.130:6383@16383 master - 0 1706013587116 3 connected 5461-10922
30b1f7bfccd93049117e1dab1cd6385eaf800015 192.168.92.131:6385@16385 master - 0 1706013587000 5 connected 10923-16383
ee718fe879729ec1f961b08c4342c78537997ab4 192.168.92.129:6381@16381 myself,slave 69d920127eec13adc0d9fcaf0e9448a80d1a4803 0 1706013587000 7 connected
127.0.0.1:6381> info replication
# Replication
role:slave
master_host:192.168.92.130
master_port:6384
master_link_status:up
master_last_io_seconds_ago:6
master_sync_in_progress:0
slave_read_repl_offset:2293
slave_repl_offset:2293
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:d2d35f3efda780fa7d82c678cb0b888439db221c
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:2293
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2252
repl_backlog_histlen:42

[root@localhost ~]# redis-server /myredis/cluster/redisCluster6383.conf 
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6384.conf 
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.92.130  netmask 255.255.255.0  broadcast 192.168.92.255
        inet6 fe80::5d0e:f975:2a1e:b6d2  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::371e:c0c:3dd4:34b4  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:a5:ad:75  txqueuelen 1000  (Ethernet)
        RX packets 355870  bytes 70598878 (67.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 264373  bytes 85328961 (81.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 3738  bytes 3291526 (3.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3738  bytes 3291526 (3.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# ps -ef|grep redis
root      10540      1  0 19:48 ?        00:00:01 redis-server 0.0.0.0:6381 [cluster]
root      10706  10461  0 20:01 pts/0    00:00:00 grep --color=auto redis
[root@localhost ~]# vim /myredis/cluster/redisCluster6383.conf 
[root@localhost ~]# vim /myredis/cluster/redisCluster6384.conf 
[root@localhost ~]# redis-cli -a abc123 -p 6381
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6381> shutdown
not connected> quit
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6383.conf 
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6384.conf 
[root@localhost ~]# ps -ef|grep redis
root      10840      1  0 20:07 ?        00:00:00 redis-server 0.0.0.0:6383 [cluster]
root      10852      1  0 20:07 ?        00:00:00 redis-server 0.0.0.0:6384 [cluster]
root      10864  10461  0 20:07 pts/0    00:00:00 grep --color=auto redis
[root@localhost ~]# redis-cli -a abc123 -p 6384 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6384> nfo replication
(error) ERR unknown command 'nfo', with args beginning with: 'replication' 
127.0.0.1:6384> nfo replication
(error) ERR unknown command 'nfo', with args beginning with: 'replication' 
127.0.0.1:6384> info replication
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:d2d35f3efda780fa7d82c678cb0b888439db221c
master_replid2:e33ee80b0ca4bd8c4030f194d3b1b262f20f42b0
master_repl_offset:2125
second_repl_offset:2126
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:2125

[root@localhost ~]# redis-server /myredis/cluster/redisCluster6383.conf 
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6384.conf 
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.92.130  netmask 255.255.255.0  broadcast 192.168.92.255
        inet6 fe80::5d0e:f975:2a1e:b6d2  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::371e:c0c:3dd4:34b4  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:a5:ad:75  txqueuelen 1000  (Ethernet)
        RX packets 355870  bytes 70598878 (67.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 264373  bytes 85328961 (81.3 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 3738  bytes 3291526 (3.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3738  bytes 3291526 (3.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# ps -ef|grep redis
root      10540      1  0 19:48 ?        00:00:01 redis-server 0.0.0.0:6381 [cluster]
root      10706  10461  0 20:01 pts/0    00:00:00 grep --color=auto redis
[root@localhost ~]# vim /myredis/cluster/redisCluster6383.conf 
[root@localhost ~]# vim /myredis/cluster/redisCluster6384.conf 
[root@localhost ~]# redis-cli -a abc123 -p 6381
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6381> shutdown
not connected> quit
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6383.conf 
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6384.conf 
[root@localhost ~]# ps -ef|grep redis
root      10840      1  0 20:07 ?        00:00:00 redis-server 0.0.0.0:6383 [cluster]
root      10852      1  0 20:07 ?        00:00:00 redis-server 0.0.0.0:6384 [cluster]
root      10864  10461  0 20:07 pts/0    00:00:00 grep --color=auto redis
[root@localhost ~]# redis-cli -a abc123 -p 6384 -c
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6384> nfo replication
(error) ERR unknown command 'nfo', with args beginning with: 'replication' 
127.0.0.1:6384> nfo replication
(error) ERR unknown command 'nfo', with args beginning with: 'replication' 
127.0.0.1:6384> info replication
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:d2d35f3efda780fa7d82c678cb0b888439db221c
master_replid2:e33ee80b0ca4bd8c4030f194d3b1b262f20f42b0
master_repl_offset:2125
second_repl_offset:2126
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:2125

[root@localhost ~]# redis-server /myredis/cluster/redisCluster6385.conf 
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6386.conf 
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.92.131  netmask 255.255.255.0  broadcast 192.168.92.255
        inet6 fe80::c264:84a9:bc4f:4bf4  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::5d0e:f975:2a1e:b6d2  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::371e:c0c:3dd4:34b4  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:73:71:a1  txqueuelen 1000  (Ethernet)
        RX packets 332356  bytes 30386511 (28.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 271765  bytes 92302137 (88.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 3712  bytes 3702854 (3.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3712  bytes 3702854 (3.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# vim /myredis/cluster
cluster/         cluster6381.pid  
[root@localhost ~]# vim /myredis/cluster/redisCluster6385.conf 
[root@localhost ~]# vim /myredis/cluster/redisCluster6386.conf 
[root@localhost ~]# ps -ef|grep redis
root      10257      1  0 19:49 ?        00:00:01 redis-server 0.0.0.0:6381 [cluster]
root      10578  10202  0 20:05 pts/0    00:00:00 grep --color=auto redis
[root@localhost ~]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> quit
[root@localhost ~]# redis-cli -a abc123 -p 6381
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6381> shutdown
not connected> quit
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6385.conf 
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6386.conf 
[root@localhost ~]# ps -ef|grep redis
root      10600      1  0 20:06 ?        00:00:00 redis-server 0.0.0.0:6385 [cluster]
root      10612      1  0 20:06 ?        00:00:00 redis-server 0.0.0.0:6386 [cluster]
root      10633  10202  0 20:06 pts/0    00:00:00 grep --color=auto redis
[root@localhost ~]# redis-cli -a abc123 -p 6385
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6385> get k1
(nil)
127.0.0.1:6385> set k1 v1
OK
127.0.0.1:6385> set k2 v2
(error) MOVED 449 192.168.92.129:6381
127.0.0.1:6385> flushall
OK
127.0.0.1:6385> keys *
(empty array)
127.0.0.1:6385> redis-cli -a abc123 -p 6385 -c
(error) ERR unknown command 'redis-cli', with args beginning with: '-a' 'abc123' '-p' '6385' '-c' 
127.0.0.1:6385> get k2
(error) MOVED 449 192.168.92.129:6381
127.0.0.1:6385> get k1
"v1"

[root@localhost ~]# redis-server /myredis/cluster/redisCluster6385.conf 
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6386.conf 
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.92.131  netmask 255.255.255.0  broadcast 192.168.92.255
        inet6 fe80::c264:84a9:bc4f:4bf4  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::5d0e:f975:2a1e:b6d2  prefixlen 64  scopeid 0x20<link>
        inet6 fe80::371e:c0c:3dd4:34b4  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:73:71:a1  txqueuelen 1000  (Ethernet)
        RX packets 332356  bytes 30386511 (28.9 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 271765  bytes 92302137 (88.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 3712  bytes 3702854 (3.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3712  bytes 3702854 (3.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# vim /myredis/cluster
cluster/         cluster6381.pid  
[root@localhost ~]# vim /myredis/cluster/redisCluster6385.conf 
[root@localhost ~]# vim /myredis/cluster/redisCluster6386.conf 
[root@localhost ~]# ps -ef|grep redis
root      10257      1  0 19:49 ?        00:00:01 redis-server 0.0.0.0:6381 [cluster]
root      10578  10202  0 20:05 pts/0    00:00:00 grep --color=auto redis
[root@localhost ~]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> quit
[root@localhost ~]# redis-cli -a abc123 -p 6381
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6381> shutdown
not connected> quit
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6385.conf 
[root@localhost ~]# redis-server /myredis/cluster/redisCluster6386.conf 
[root@localhost ~]# ps -ef|grep redis
root      10600      1  0 20:06 ?        00:00:00 redis-server 0.0.0.0:6385 [cluster]
root      10612      1  0 20:06 ?        00:00:00 redis-server 0.0.0.0:6386 [cluster]
root      10633  10202  0 20:06 pts/0    00:00:00 grep --color=auto redis
[root@localhost ~]# redis-cli -a abc123 -p 6385
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6385> get k1
(nil)
127.0.0.1:6385> set k1 v1
OK
127.0.0.1:6385> set k2 v2
(error) MOVED 449 192.168.92.129:6381
127.0.0.1:6385> flushall
OK
127.0.0.1:6385> keys *
(empty array)
127.0.0.1:6385> redis-cli -a abc123 -p 6385 -c
(error) ERR unknown command 'redis-cli', with args beginning with: '-a' 'abc123' '-p' '6385' '-c' 
127.0.0.1:6385> get k2
(error) MOVED 449 192.168.92.129:6381
127.0.0.1:6385> get k1
"v1"