架构师

您现在的位置是:首页 > 技术博客 > 开发环境

开发环境

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

架构师小跟班 2019-07-29开发环境
搭建master修改redis配置redis.windows.conf: 修改监听端口:port 26379 修改绑定IP:bind 127.0.0.1 添加redis日志:logfile "..\\logsdata\\redis.master.26379.log.txt" 添加R


搭建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

文章评论