配置master 和slave
1.master服务器信息
ip:node1 port:6379 密码:123456
2.slave配置master
ip:node2 port:6379 密码:123456
修改redis-config文件
slaveof node1 6379 指定master的ip和portmasterauth 123456 master有验证的情况下slave-read-only yes 设置slave为只读模式
确认主从配置
master:
node1:6379> INFO replication# Replicationrole:masterconnected_slaves:1slave0:ip=node1,port=6379,state=online,offset=309,lag=1
slave:
node2:6379> INFO replication# Replicationrole:slavemaster_host:node1master_port:6379master_link_status:upmaster_last_io_seconds_ago:7master_sync_in_progress:0slave_repl_offset:365slave_priority:100slave_read_only:1connected_slaves:0master_repl_offset:0repl_backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0
slave升级为master
当node1不可用时,可以将node2 从slave切换为master
node2:6379> SLAVEOF NO ONE
master 切换为slave
当node1服务器可用时,可以把node2从master再切换回slave
node2:6379> SLAVEOF node1 6379