前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Java开发环境系列:Redis进阶之集群哨兵及主从复制

Java开发环境系列:Redis进阶之集群哨兵及主从复制

作者头像
架构师小跟班
发布2019-08-07 10:08:24
4540
发布2019-08-07 10:08:24
举报
文章被收录于专栏:架构师小跟班

搭建master

修改redis配置redis.windows.conf:

  • 修改监听端口:port 26379
  • 修改绑定IP:bind 127.0.0.1
  • 添加redis日志:logfile "..\\logsdata\\redis.master.26379.log.txt"
  • 添加Redis数据库:databases 16
  • 数据库磁盘影像: dbfilename dump.master.26379.rdb
  • 数据存储的位置:dir ..\\redisdata
  • 磁盘数据持久化:appendfilename "appendonly.master.26379.aof"

搭建salve

修改redis配置redis.windows.conf:

  • 修改监听端口:port 26380
  • 修改绑定IP: bind 127.0.0.1
  • 添加redis日志:logfile "..\\logsdata\\redis.slave.26380.log.txt"
  • 添加Redis数据库:databases 16
  • 数据库磁盘影像: dbfilename dump.slave.26380.rdb
  • 数据存储的位置:..\\redisdata
  • 主从配置:slaveof 127.0.0.1  26379
  • 磁盘数据持久化:appendfilename "appendonly.slave.26380.aof"

启动Redis

master: 

..\Redis-x64-3.2.100-master\redis-server.exe redis.windows.conf

D:\DevTools\redis\Redis-x64-3.2.100-master>redis-server.exe  redis.windows.conf

                _._

           _.-``__ ''-._

      _.-``    `.  `_.  ''-._           Redis 3.2.100 (00000000/0) 64 bit

  .-`` .-```.  ```\/    _.,_ ''-._

 (    '      ,       .-`  | `,    )     Running in standalone mode

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 26379

 |    `-._   `._    /     _.-'    |     PID: 11900

  `-._    `-._  `-./  _.-'    _.-'

 |`-._`-._    `-.__.-'    _.-'_.-'|

 |    `-._`-._        _.-'_.-'    |           http://redis.io

  `-._    `-._`-.__.-'_.-'    _.-'

 |`-._`-._    `-.__.-'    _.-'_.-'|

 |    `-._`-._        _.-'_.-'    |

  `-._    `-._`-.__.-'_.-'    _.-'

      `-._    `-.__.-'    _.-'

          `-._        _.-'

              `-.__.-'

[11900] 13 Jun 10:46:54.572 # Server started, Redis version 3.2.100

[11900] 13 Jun 10:46:54.580 * DB saved on disk

[11900] 13 Jun 10:46:54.580 * DB loaded from append only file: 0.008 seconds

[11900] 13 Jun 10:46:54.581 * The server is now ready to accept connections onort 26379

slave : 

..\Redis-x64-3.2.100-slave\redis-server.exe redis.windows.conf

D:\DevTools\redis\Redis-x64-3.2.100-slave>redis-server.exe  redis.windows.conf

                _._

           _.-``__ ''-._

      _.-``    `.  `_.  ''-._           Redis 3.2.100 (00000000/0) 64 bit

  .-`` .-```.  ```\/    _.,_ ''-._

 (    '      ,       .-`  | `,    )     Running in standalone mode

 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 26380

 |    `-._   `._    /     _.-'    |     PID: 7888

  `-._    `-._  `-./  _.-'    _.-'

 |`-._`-._    `-.__.-'    _.-'_.-'|

 |    `-._`-._        _.-'_.-'    |           http://redis.io

  `-._    `-._`-.__.-'_.-'    _.-'

 |`-._`-._    `-.__.-'    _.-'_.-'|

 |    `-._`-._        _.-'_.-'    |

  `-._    `-._`-.__.-'_.-'    _.-'

      `-._    `-.__.-'    _.-'

          `-._        _.-'

              `-.__.-'

[7888] 13 Jun 10:47:17.697 # Server started, Redis version 3.2.100

[7888] 13 Jun 10:47:17.708 * DB saved on disk

[7888] 13 Jun 10:47:17.708 * DB loaded from append only file: 0.011 seconds

[7888] 13 Jun 10:47:17.708 * The server is now ready to accept connections on po

rt 26380

[7888] 13 Jun 10:47:17.709 * Connecting to MASTER 127.0.0.1:26379

[7888] 13 Jun 10:47:17.711 * MASTER <-> SLAVE sync started

[7888] 13 Jun 10:47:17.712 * Non blocking connect for SYNC fired the event.

[7888] 13 Jun 10:47:17.713 * Master replied to PING, replication can continue...

[7888] 13 Jun 10:47:17.715 * Partial resynchronization not possible (no cached m

aster)

[7888] 13 Jun 10:47:17.723 * Full resync from master: a6de45b387bcb77291afacb31c

46fe7e1e14366b:1

[7888] 13 Jun 10:47:17.860 * MASTER <-> SLAVE sync: receiving 311 bytes from mas

ter

[7888] 13 Jun 10:47:17.866 * MASTER <-> SLAVE sync: Flushing old data

[7888] 13 Jun 10:47:17.867 * MASTER <-> SLAVE sync: Loading DB in memory

[7888] 13 Jun 10:47:17.869 * MASTER <-> SLAVE sync: Finished with success

[7888] 13 Jun 10:47:17.876 * Background append only file rewriting started by pi

d 11588

[7888] 13 Jun 10:47:18.017 * AOF rewrite child asks to stop sending diffs.

[7888] 13 Jun 10:47:18.119 # fork operation complete

[7888] 13 Jun 10:47:18.121 * Background AOF rewrite terminated with success

[7888] 13 Jun 10:47:18.126 * Residual parent diff successfully flushed to the re

written AOF (0.00 MB)

[7888] 13 Jun 10:47:18.134 * Background AOF rewrite finished successfully

[7888] 13 Jun 10:48:44.466 * DB saved on disk

[7888] 13 Jun 10:53:45.097 * 10 changes in 300 seconds. Saving...

[7888] 13 Jun 10:53:45.101 * Background saving started by pid 11244

[7888] 13 Jun 10:53:45.202 # fork operation complete

[7888] 13 Jun 10:53:45.202 * Background saving terminated with success

常用命令

进入主redis:  Redis-x64-3.2.100-master\redis-cli -h 127.0.0.1 -p 26379

查看所有   keys *

查看某类   keys *session*

清空所有   flushall

测试集群效果 在master上新增set name 'wangxinagyu',在slave上可以查看到get name(主从复制)

D:\DevTools\redis\Redis-x64-3.2.100-master>redis-cli -h 127.0.0.1 -p 26379

127.0.0.1:26379> keys *

1) "yuanqin_hash"

2) "yuanqin"

3) "yuanqin_set"

4) "yuanqin_list"

5) "yuanqin_zset"

127.0.0.1:26379> set name 'wangxinagyu'

OK

D:\DevTools\redis\Redis-x64-3.2.100-slave>redis-cli -h 127.0.0.1 -p 26380

127.0.0.1:26380> get name

"wangxiangyu"

集群模式哨兵操作(Redis的setntinel操作命令):

sentinel masters 

sentinel slaves etreasury 

sentinel get-master-addr-by-name eteasury 

ping

备注

附件解压之后,上述涉及IP(127.0.0.1)的地方直接改成本机IP即可以使用。

附件下载:

https://github.com/xywhero/Devtools.git

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-07-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 Redis
腾讯云数据库 Redis(TencentDB for Redis)是腾讯云打造的兼容 Redis 协议的缓存和存储服务。丰富的数据结构能帮助您完成不同类型的业务场景开发。支持主从热备,提供自动容灾切换、数据备份、故障迁移、实例监控、在线扩容、数据回档等全套的数据库服务。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档