redis 读写分离
配置master 和slave
1.master服务器信息
ip:node1 port:6379 密码:123456
2.slave配置master
ip:node2 port:6379 密码:123456
修改redis-config文件
slaveof node1 6379 指定master的ip和port masterauth 123456 master有验证的情况下 slave-read-only yes 设置slave为只读模式
确认主从配置
master:
node1:6379> INFO replication # Replication role:master connected_slaves:1 slave0:ip=node1,port=6379,state=online,offset=309,lag=1
slave:
node2:6379> INFO replication # Replication role:slave master_host:node1 master_port:6379 master_link_status:up master_last_io_seconds_ago:7 master_sync_in_progress:0 slave_repl_offset:365 slave_priority:100 slave_read_only:1 connected_slaves:0 master_repl_offset:0 repl_backlog_active:0 repl_backlog_size:1048576 repl_backlog_first_byte_offset:0 repl_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