指令:info replication
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:0
master_replid:2f3b80850b772aede7c47ca3f0f4dc357e383731
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
从库配置属于哪个主库
slaveof <ip><port>
127.0.0.1:6379> slaveof 127.0.0.1 6380
OK
127.0.0.1:6379>
主库有密码的情况下,从库要配置masterauth,连接时会进行主库验证
再次查看当前是从库,能看到主库的状态
127.0.0.1:6379> info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6380
master_link_status:down
master_last_io_seconds_ago:-1
master_sync_in_progress:0
slave_repl_offset:0
master_link_down_since_seconds:1643185848
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:2f3b80850b772aede7c47ca3f0f4dc357e383731
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
127.0.0.1:6379>
从库只能读,不能写
设置成为主库
slaveof no one
A->B->C 多层主从复制时
哨兵模式
新建sentinel.conf,名字不能错,填写内容
sentinel monitor mymaster 127.0.0.1 6379 1
其中mymaster未监控对象起的服务器名称,1 为至少有多少给哨兵同意迁移的数量
优先级再redis.conf中默认:slave-priority 100,值越小,优先级越高
启动哨兵模式
redis-sentinel sentinel.conf
网友评论