Redis同步配置

来源:互联网 发布:单片机定时器怎么用 编辑:程序博客网 时间:2024/06/06 10:53

Redis 同步配置

Redis的主从和MySQL的主从从架构上看很相近,都是一个主库支持多个从库,主从复制不会阻塞master,在同步数据时,master可以继续处理client请求,从库可以扩展redis读的能力

环境描述

Master

Slave

Ip:192.168.247.11 port:6379

Ip:192.168.247.12 port:6378


从库安装redis配置6378.conf文件

# scp 6379.conf 192.168.247.12:/data/redis/redis6378/6378.conf

# sed -i 's/6379/6378/g' 6378.conf


先启动master redis再启动slave redis

# /opt/redis/sbin/redis-server/data/redis/redis6378/6378.conf


slave log

[5736] 06 Feb 20:28:48.235 * The server isnow ready to accept connections on port 6378

[5736] 06 Feb 20:28:48.237 * Connecting toMASTER 192.168.247.11:6379

[5736] 06 Feb 20:28:48.237 * MASTER<-> SLAVE sync started

[5736] 06 Feb 20:28:48.238 * Non blockingconnect for SYNC fired the event.

[5736] 06 Feb 20:28:48.238 * Master repliedto PING, replication can continue...

[5736] 06 Feb 20:28:48.239 * Partialresynchronization not possible (no cached master)


同步测试

# /opt/redis/bin/redis-cli -p 6379

127.0.0.1:6379> keys *

(empty list or set)

127.0.0.1:6379> set  a  1

OK

127.0.0.1:6379> get a

"1"

 # /opt/redis/bin/redis-cli  -p 6378

127.0.0.1:6378> get a

"1"

从库是否可以写入数据

127.0.0.1:6378> set b 1

(error) READONLY You can't write against aread only slave.

# /opt/redis/bin/redis-cli -p 6379 shutdown

# netstat -nlp | grep 6379

127.0.0.1:6378> set b 1

(error) READONLY You can't write against aread only slave.

127.0.0.1:6378> slaveof no one    --断开主从关系

OK

127.0.0.1:6378> set b 1                  --可以写入数据

OK

127.0.0.1:6378> keys *

1) "a"

2) "b"


master恢复正常可以使用slaveof完成同步

127.0.0.1:6378> slaveof 192.168.247.116379

OK

127.0.0.1:6378> info replication

# Replication

role:slave

master_host:192.168.247.11

master_port:6379

master_link_status:up

master_last_io_seconds_ago:3

master_sync_in_progress:0

slave_repl_offset:15

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

master_link_status:up           --说明同步正常






0 0
原创粉丝点击