天天看点

Redis 哨兵+集群(Windows 10)

一主两从三哨兵

1、配置文件

拷贝redis.windows.conf至新建的redis6379.conf并修改

port 6379
dbfilename 6379dump.rdb
dir ./redis6379
           

拷贝redis.windows.conf至新建的redis6380.conf并修改

port 6380
dbfilename 6380dump.rdb
dir ./redis6380
slaveof 127.0.0.1 6379
           

拷贝redis.windows.conf至新建的redis6381.conf并修改

port 6381
dbfilename 6381dump.rdb
dir ./redis6381
slaveof 127.0.0.1 6379
           

新建sentinel11079.conf并配置以下属性值

port 11079
sentinel monitor mymaster 127.0.0.1 6379 2
           

新建sentinel11080.conf并配置以下属性值

port 11080
sentinel monitor mymaster 127.0.0.1 6379 2
           

新建sentinel11081.conf并配置以下属性值

port 11081
sentinel monitor mymaster 127.0.0.1 6379 2
           

文件目录如下: 

Redis 哨兵+集群(Windows 10)

2、启动服务

在命令窗口分别启动

redis-server.exe redis6379.conf
redis-server.exe redis6380.conf
redis-server.exe redis6381.conf
redis-server.exe sentinel11079.conf --sentinel
redis-server.exe sentinel11080.conf --sentinel
redis-server.exe sentinel11081.conf --sentinel
           

开启客户端查看信息

【master 】

Redis 哨兵+集群(Windows 10)

【slave 】

Redis 哨兵+集群(Windows 10)

【sentinel 】

Redis 哨兵+集群(Windows 10)

3、模拟master节点宕机

【master shutdown】

Redis 哨兵+集群(Windows 10)

【master-server】

Redis 哨兵+集群(Windows 10)

【slave-server】

更新主从信息

Redis 哨兵+集群(Windows 10)

【sentinel-server】

选举新master

Redis 哨兵+集群(Windows 10)

集群

1、准备工作

下载redis

下载ruby并安装

Redis 哨兵+集群(Windows 10)

下载Ruby环境下Redis的驱动

Redis 哨兵+集群(Windows 10)

下载Redis官方提供的创建Redis集群的ruby脚本文件redis-trib.rb(放在redis目录下)

Redis 哨兵+集群(Windows 10)

2、配置

拷贝redis.windows.conf至新建的redis63XX.conf并修改

63XX:6379、6380、6381、6389、6390、6391

# 对应修改为63XX
port 6379
dbfilename 6379dump.rdb
cluster-enabled yes
cluster-config-file nodes-6379.conf
           

3、启动redis实例

redis-server.exe redis6379.conf
redis-server.exe redis6380.conf
redis-server.exe redis6381.conf
redis-server.exe redis6389.conf
redis-server.exe redis6390.conf
redis-server.exe redis6391.conf
           
Redis 哨兵+集群(Windows 10)

4、创建集群

redis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6389 127.0.0.1:6390 127.0.0.1:6391
           
Redis 哨兵+集群(Windows 10)

5、结果展示 

集群节点信息 

Redis 哨兵+集群(Windows 10)

单个节点信息

Redis 哨兵+集群(Windows 10)

简单操作

Redis 哨兵+集群(Windows 10)

继续阅读