ITPub博客

首页 > 数据库 > NoSQL > Redis日常运维-02主从复制

Redis日常运维-02主从复制

原创 NoSQL 作者:chenoracle 时间:2020-03-23 22:15:53 0 删除 编辑

Redis日常运维-02主从复制

一 Redis安装

二 Redis主从复制 

三 Redis哨兵模式高可用架构 

四 Redis-cluster群集高可用架构

五 常见问题


架构

主 192.168.2.222

从 192.168.2.187

从 192.168.2.188

从库配置文件添加:

从 192.168.2.187

从 192.168.2.188

[root@rac1 config]# pwd

/usr/local/redis/config

[root@rac1 config]# vim redis.conf 

#添加 

slaveof 192.168.2.222 6379

重启数据库 

[root@rac1 config]# redis-cli -p 6379 shutdown 

[root@rac1 config]# redis-server redis.conf 

验证数据同步

主库2.222

[root@cjcos src]# redis-cli 

127.0.0.1:6379> set station dba

OK

127.0.0.1:6379> get station

"dba"

从库2.187

[root@rac1 config]# redis-cli 

127.0.0.1:6379> get station

"dba"

从库2.188

[root@rac2 config]# redis-cli 

127.0.0.1:6379> get station

"dba"

主库2.222查看同步信息

127.0.0.1:6379> info replication

# Replication

role:master

connected_slaves:2

slave0:ip=192.168.2.187,port=6379,state=online,offset=11208,lag=1

slave1:ip=192.168.2.188,port=6379,state=online,offset=11208,lag=1

master_replid:231ff9d15411b50038a43bb0726580f4dd788f80

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:11208

second_repl_offset:-1

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:1

repl_backlog_histlen:11208

同步日志

主库2.222

----redis.log

8511:M 23 Mar 2020 14:53:51.841 * Background saving terminated with success

8511:M 23 Mar 2020 14:53:51.842 * Synchronization with replica 192.168.2.187:6379 succeeded

8511:M 23 Mar 2020 14:53:57.272 * Replica 192.168.2.188:6379 asks for synchronization

8511:M 23 Mar 2020 14:53:57.272 * Full resync requested by replica 192.168.2.188:6379

8511:M 23 Mar 2020 14:53:57.272 * Starting BGSAVE for SYNC with target: disk

8511:M 23 Mar 2020 14:53:57.272 * Background saving started by pid 8528

8528:C 23 Mar 2020 14:53:57.326 * DB saved on disk

8528:C 23 Mar 2020 14:53:57.327 * RDB: 0 MB of memory used by copy-on-write

常见问题:

同步失败,日志如下: 

----redis.log

29884:S 23 Mar 2020 14:50:29.152 * Connecting to MASTER 192.168.2.222:6379

29884:S 23 Mar 2020 14:50:29.152 * MASTER <-> REPLICA sync started

29884:S 23 Mar 2020 14:50:29.152 * Non blocking connect for SYNC fired the event.

29884:S 23 Mar 2020 14:50:29.153 # Error reply to PING from master: '-DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect '

解决方案:

---配置文件 redis.conf添加:

bind 0.0.0.0

欢迎关注我的微信公众号"IT小Chen",共同学习,共同成长!!!

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29785807/viewspace-2682150/,如需转载,请注明出处,否则将追究法律责任。

全部评论
Oracle 11g OCP、Oracle 11g OCM、OCMU 用户组成员,微信公众号"IT小Chen"

注册时间:2014-08-05

  • 博文量
    537
  • 访问量
    983755