Redis主从集群一主二从并使用slaveof IP 端口号的方式实现单次主从关系确立-----Redis

[root@localhost myredis]# redis-server /myredis/redis6379.conf 
[root@localhost myredis]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> keys *
 1) "count"
 2) "list"
 3) "k100"
 4) "key"
 5) "k10000"
 6) "k300"
 7) "k200"
 8) "user:001"
 9) "k2"
10) "balance"
11) "k1"
12) "email"
13) "k3"
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.92.130,port=6380,state=online,offset=308,lag=1
slave1:ip=192.168.92.131,port=6381,state=online,offset=322,lag=0
master_failover_state:no-failover
master_replid:a5075df9f030230dd8e30b2fb6c917650647850f
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:322
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:322
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> set k4 v4
OK
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.92.130,port=6380,state=online,offset=1495,lag=0
slave1:ip=192.168.92.131,port=6381,state=online,offset=1495,lag=1
master_failover_state:no-failover
master_replid:a5075df9f030230dd8e30b2fb6c917650647850f
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:1495
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:1495
127.0.0.1:6379> shutdown
not connected> quit
[root@localhost myredis]# redis-server /myredis/redis6379.conf 
[root@localhost myredis]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.92.131,port=6381,state=online,offset=1523,lag=1
slave1:ip=192.168.92.130,port=6380,state=online,offset=1523,lag=0
master_failover_state:no-failover
master_replid:abedbfd0778fa64d6d865a1fef6f3af9a74e04e0
master_replid2:a5075df9f030230dd8e30b2fb6c917650647850f
master_repl_offset:1523
second_repl_offset:1510
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1510
repl_backlog_histlen:14
127.0.0.1:6379> keys *
 1) "user:001"
 2) "k4"
 3) "list"
 4) "count"
 5) "k3"
 6) "k10000"
 7) "balance"
 8) "k200"
 9) "k2"
10) "k300"
11) "key"
12) "k1"
13) "k100"
14) "email"
127.0.0.1:6379> set k5 v5
OK
127.0.0.1:6379> set ksas ks
OK
127.0.0.1:6379> shutdown
not connected> quit
[root@localhost myredis]# redis-server /myredis/redis6379.conf 
[root@localhost myredis]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:7513fad147a6f946a72271ad8c74f19878c9a166
master_replid2:abedbfd0778fa64d6d865a1fef6f3af9a74e04e0
master_repl_offset:2124
second_repl_offset:2125
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2125
repl_backlog_histlen:0
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.92.130,port=6380,state=online,offset=2166,lag=0
slave1:ip=192.168.92.131,port=6381,state=online,offset=2166,lag=0
master_failover_state:no-failover
master_replid:7513fad147a6f946a72271ad8c74f19878c9a166
master_replid2:abedbfd0778fa64d6d865a1fef6f3af9a74e04e0
master_repl_offset:2166
second_repl_offset:2125
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2125
repl_backlog_histlen:42
127.0.0.1:6379> lpush list 1 2 3 4 5 6 8 9 0
(integer) 14

[root@localhost myredis]# redis-server /myredis/redis6379.conf 
[root@localhost myredis]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> keys *
 1) "count"
 2) "list"
 3) "k100"
 4) "key"
 5) "k10000"
 6) "k300"
 7) "k200"
 8) "user:001"
 9) "k2"
10) "balance"
11) "k1"
12) "email"
13) "k3"
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.92.130,port=6380,state=online,offset=308,lag=1
slave1:ip=192.168.92.131,port=6381,state=online,offset=322,lag=0
master_failover_state:no-failover
master_replid:a5075df9f030230dd8e30b2fb6c917650647850f
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:322
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:322
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> set k4 v4
OK
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.92.130,port=6380,state=online,offset=1495,lag=0
slave1:ip=192.168.92.131,port=6381,state=online,offset=1495,lag=1
master_failover_state:no-failover
master_replid:a5075df9f030230dd8e30b2fb6c917650647850f
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:1495
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:1495
127.0.0.1:6379> shutdown
not connected> quit
[root@localhost myredis]# redis-server /myredis/redis6379.conf 
[root@localhost myredis]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.92.131,port=6381,state=online,offset=1523,lag=1
slave1:ip=192.168.92.130,port=6380,state=online,offset=1523,lag=0
master_failover_state:no-failover
master_replid:abedbfd0778fa64d6d865a1fef6f3af9a74e04e0
master_replid2:a5075df9f030230dd8e30b2fb6c917650647850f
master_repl_offset:1523
second_repl_offset:1510
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1510
repl_backlog_histlen:14
127.0.0.1:6379> keys *
 1) "user:001"
 2) "k4"
 3) "list"
 4) "count"
 5) "k3"
 6) "k10000"
 7) "balance"
 8) "k200"
 9) "k2"
10) "k300"
11) "key"
12) "k1"
13) "k100"
14) "email"
127.0.0.1:6379> set k5 v5
OK
127.0.0.1:6379> set ksas ks
OK
127.0.0.1:6379> shutdown
not connected> quit
[root@localhost myredis]# redis-server /myredis/redis6379.conf 
[root@localhost myredis]# redis-cli -a abc123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:7513fad147a6f946a72271ad8c74f19878c9a166
master_replid2:abedbfd0778fa64d6d865a1fef6f3af9a74e04e0
master_repl_offset:2124
second_repl_offset:2125
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2125
repl_backlog_histlen:0
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.92.130,port=6380,state=online,offset=2166,lag=0
slave1:ip=192.168.92.131,port=6381,state=online,offset=2166,lag=0
master_failover_state:no-failover
master_replid:7513fad147a6f946a72271ad8c74f19878c9a166
master_replid2:abedbfd0778fa64d6d865a1fef6f3af9a74e04e0
master_repl_offset:2166
second_repl_offset:2125
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2125
repl_backlog_histlen:42
127.0.0.1:6379> lpush list 1 2 3 4 5 6 8 9 0
(integer) 14
 

127.0.0.1:6380> shutdown
not connected> quit
[root@localhost myredis]# vim /myredis/redis6380.conf 
[root@localhost myredis]# redis-server /myredis/redis6380.conf 
[root@localhost myredis]# redis-cli -a abc123 -p 6380
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
AUTH failed: ERR AUTH  called without any password configured for the default user. Are you sure your configuration is correct?
127.0.0.1:6380> info replication
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:1e05f29df11443cc3885afdae89c17fbae83710b
master_replid2:abedbfd0778fa64d6d865a1fef6f3af9a74e04e0
master_repl_offset:2124
second_repl_offset:2125
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2125
repl_backlog_histlen:0
127.0.0.1:6380> slaveof 192.168.92.129 6379
OK
127.0.0.1:6380> info replication
# Replication
role:slave
master_host:192.168.92.129
master_port:6379
master_link_status:up
master_last_io_seconds_ago:2
master_sync_in_progress:0
slave_read_repl_offset:2124
slave_repl_offset:2124
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:7513fad147a6f946a72271ad8c74f19878c9a166
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:2124
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2125
repl_backlog_histlen:0
127.0.0.1:6380> keys *
 1) "balance"
 2) "k100"
 3) "k4"
 4) "count"
 5) "k10000"
 6) "k5"
 7) "k1"
 8) "k2"
 9) "list"
10) "user:001"
11) "k300"
12) "k200"
13) "email"
14) "key"
15) "k3"
16) "ksas"
127.0.0.1:6380> lrange list
(error) ERR wrong number of arguments for 'lrange' command
127.0.0.1:6380> lrange list 0 -1
1) "5"
2) "4"
3) "3"
4) "2"
5) "1"
127.0.0.1:6380> lrange list 0 -1
 1) "0"
 2) "9"
 3) "8"
 4) "6"
 5) "5"
 6) "4"
 7) "3"
 8) "2"
 9) "1"
10) "5"
11) "4"
12) "3"
13) "2"
14) "1"
127.0.0.1:6380> shutdown
not connected> quit
[root@localhost myredis]# redis-server /myredis/redis6380.conf 
[root@localhost myredis]# redis-cli -a abc123 -p 6380
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
AUTH failed: ERR AUTH  called without any password configured for the default user. Are you sure your configuration is correct?
127.0.0.1:6380> info replication
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:3264938fa33437cdbfed37d1af03b6a28e796e14
master_replid2:7513fad147a6f946a72271ad8c74f19878c9a166
master_repl_offset:2474
second_repl_offset:2475
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2475
repl_backlog_histlen:0

 127.0.0.1:6380> shutdown
not connected> quit
[root@localhost myredis]# vim /myredis/redis6380.conf 
[root@localhost myredis]# redis-server /myredis/redis6380.conf 
[root@localhost myredis]# redis-cli -a abc123 -p 6380
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
AUTH failed: ERR AUTH called without any password configured for the default user. Are you sure your configuration is correct?
127.0.0.1:6380> info replication
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:1e05f29df11443cc3885afdae89c17fbae83710b
master_replid2:abedbfd0778fa64d6d865a1fef6f3af9a74e04e0
master_repl_offset:2124
second_repl_offset:2125
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2125
repl_backlog_histlen:0
127.0.0.1:6380> slaveof 192.168.92.129 6379
OK
127.0.0.1:6380> info replication
# Replication
role:slave
master_host:192.168.92.129
master_port:6379
master_link_status:up
master_last_io_seconds_ago:2
master_sync_in_progress:0
slave_read_repl_offset:2124
slave_repl_offset:2124
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:7513fad147a6f946a72271ad8c74f19878c9a166
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:2124
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2125
repl_backlog_histlen:0
127.0.0.1:6380> keys *
 1) "balance"
 2) "k100"
 3) "k4"
 4) "count"
 5) "k10000"
 6) "k5"
 7) "k1"
 8) "k2"
 9) "list"
10) "user:001"
11) "k300"
12) "k200"
13) "email"
14) "key"
15) "k3"
16) "ksas"
127.0.0.1:6380> lrange list
(error) ERR wrong number of arguments for 'lrange' command
127.0.0.1:6380> lrange list 0 -1
1) "5"
2) "4"
3) "3"
4) "2"
5) "1"
127.0.0.1:6380> lrange list 0 -1
 1) "0"
 2) "9"
 3) "8"
 4) "6"
 5) "5"
 6) "4"
 7) "3"
 8) "2"
 9) "1"
10) "5"
11) "4"
12) "3"
13) "2"
14) "1"
127.0.0.1:6380> shutdown
not connected> quit
[root@localhost myredis]# redis-server /myredis/redis6380.conf 
[root@localhost myredis]# redis-cli -a abc123 -p 6380
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
AUTH failed: ERR AUTH called without any password configured for the default user. Are you sure your configuration is correct?
127.0.0.1:6380> info replication
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:3264938fa33437cdbfed37d1af03b6a28e796e14
master_replid2:7513fad147a6f946a72271ad8c74f19878c9a166
master_repl_offset:2474
second_repl_offset:2475
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2475
repl_backlog_histlen:0

127.0.0.1:6381> shutdown
not connected> quit
[root@localhost myredis]# vim /myredis/redis6381.conf
[root@localhost myredis]# redis-server /myredis/redis6381.conf 
[root@localhost myredis]# redis-cli -a abc123 -p 6381
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
AUTH failed: ERR AUTH  called without any password configured for the default user. Are you sure your configuration is correct?
127.0.0.1:6381> info replication
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:6c1d90ea2c305c0bc94d59cf880776628a37cd48
master_replid2:abedbfd0778fa64d6d865a1fef6f3af9a74e04e0
master_repl_offset:2124
second_repl_offset:2125
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2125
repl_backlog_histlen:0
127.0.0.1:6381> slaveof 192.168.92.129 6379
OK
127.0.0.1:6381> info replication
# Replication
role:slave
master_host:192.168.92.129
master_port:6379
master_link_status:down
master_last_io_seconds_ago:-1
master_sync_in_progress:0
slave_read_repl_offset:2124
slave_repl_offset:2124
master_link_down_since_seconds:-1
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:6c1d90ea2c305c0bc94d59cf880776628a37cd48
master_replid2:abedbfd0778fa64d6d865a1fef6f3af9a74e04e0
master_repl_offset:2124
second_repl_offset:2125
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2125
repl_backlog_histlen:0
127.0.0.1:6381> lrange list 0 -1
 1) "0"
 2) "9"
 3) "8"
 4) "6"
 5) "5"
 6) "4"
 7) "3"
 8) "2"
 9) "1"
10) "5"
11) "4"
12) "3"
13) "2"
14) "1"
127.0.0.1:6381> shutdown
not connected> quit
[root@localhost myredis]# redis-server /myredis/redis6381.cfg
4314:C 20 Jan 2024 16:48:25.353 # Fatal error, can't open config file '/myredis/redis6381.cfg': No such file or directory
[root@localhost myredis]# redis-server /myredis/redis6381.conf
[root@localhost myredis]# redis-cli -a abc123 -p 6381
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
AUTH failed: ERR AUTH  called without any password configured for the default user. Are you sure your configuration is correct?
127.0.0.1:6381> info replication
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:f0cb4a8bc6c80cd62a55a9c199aefe871f41820a
master_replid2:7513fad147a6f946a72271ad8c74f19878c9a166
master_repl_offset:2488
second_repl_offset:2489
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2489
repl_backlog_histlen:0

 127.0.0.1:6381> shutdown
not connected> quit
[root@localhost myredis]# vim /myredis/redis6381.conf
[root@localhost myredis]# redis-server /myredis/redis6381.conf 
[root@localhost myredis]# redis-cli -a abc123 -p 6381
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
AUTH failed: ERR AUTH called without any password configured for the default user. Are you sure your configuration is correct?
127.0.0.1:6381> info replication
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:6c1d90ea2c305c0bc94d59cf880776628a37cd48
master_replid2:abedbfd0778fa64d6d865a1fef6f3af9a74e04e0
master_repl_offset:2124
second_repl_offset:2125
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2125
repl_backlog_histlen:0
127.0.0.1:6381> slaveof 192.168.92.129 6379
OK
127.0.0.1:6381> info replication
# Replication
role:slave
master_host:192.168.92.129
master_port:6379
master_link_status:down
master_last_io_seconds_ago:-1
master_sync_in_progress:0
slave_read_repl_offset:2124
slave_repl_offset:2124
master_link_down_since_seconds:-1
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:6c1d90ea2c305c0bc94d59cf880776628a37cd48
master_replid2:abedbfd0778fa64d6d865a1fef6f3af9a74e04e0
master_repl_offset:2124
second_repl_offset:2125
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2125
repl_backlog_histlen:0
127.0.0.1:6381> lrange list 0 -1
 1) "0"
 2) "9"
 3) "8"
 4) "6"
 5) "5"
 6) "4"
 7) "3"
 8) "2"
 9) "1"
10) "5"
11) "4"
12) "3"
13) "2"
14) "1"
127.0.0.1:6381> shutdown
not connected> quit
[root@localhost myredis]# redis-server /myredis/redis6381.cfg
4314:C 20 Jan 2024 16:48:25.353 # Fatal error, can't open config file '/myredis/redis6381.cfg': No such file or directory
[root@localhost myredis]# redis-server /myredis/redis6381.conf
[root@localhost myredis]# redis-cli -a abc123 -p 6381
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
AUTH failed: ERR AUTH called without any password configured for the default user. Are you sure your configuration is correct?
127.0.0.1:6381> info replication
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:f0cb4a8bc6c80cd62a55a9c199aefe871f41820a
master_replid2:7513fad147a6f946a72271ad8c74f19878c9a166
master_repl_offset:2488
second_repl_offset:2489
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2489
repl_backlog_histlen:0

你可能感兴趣的:(Redis,数据库,数据库,redis,sql,nosql,后端,linux,database)