Windows环境Redis集群部署配置

标签:Redis

工具/资料

windows系统环境Release 版本
https://github.com/MSOpenTech/redis/releases
https://github.com/MicrosoftArchive/redis/releases
Redis中文文档
http://redis.cn/documentation.html
Redis命令文档
http://redis.cn/commands.html
Redis命令参考
http://www.redisfans.com/
http://doc.redisfans.com/

3.0集群搭建部署参考文档
http://www.cnblogs.com/tommy-huang/p/6240083.html
http://doc.redisfans.com/topic/cluster-tutorial.html

Ruby 语言官网(中文)
http://www.ruby-lang.org/zh_cn/
20分钟体验 Ruby
http://www.ruby-lang.org/zh_cn/documentation/quickstart/
菜鸟教程
http://www.runoob.com/ruby/ruby-installation-windows.html

Ruby windows系统运行环境
http://rubyinstaller.org/downloads/

一、准备 Redis 3.0.504 运行程序

Redis 3.0.504 下载地址
https://github.com/MSOpenTech/redis/releases
下载msi安装包文件或后缀.zip文件,建议使用.zip文件
下载后解压到文件夹 Redis-x64-3.0.504 备用。

二、修改 redis.conf 配置文件

这里配置 638063816382 端口为集群主服务,配置 6383(从6380)、6384(从6381)、6385(从6382) 端口为从服务。

集群服务模板配置

Redis-x64-3.0.504 目录下 redis.windows.conf 复制改名 redis-cluster6380.conf 备用,制作集群模板配置文件。

修改模板配置文件以下位置:

port 6380

#logfile ""
logfile "D:/work/TfsRedis/Redis-x64-3.0.504/log/redis6380.log"

dbfilename dump6380.rdb

#dir ./
dir "D:/work/TfsRedis/Redis-x64-3.0.504"

################################ REDIS CLUSTER  ###############################
cluster-enabled yes
cluster-config-file nodes-6380.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes

修改好后复制五份改名,分别为 redis-cluster6381.confredis-cluster6382.confredis-slave6383.confredis-slave6384.confredis-slave6385.conf

编写启动 Redis 服务批处理

本文档实验以命令行窗口形式运行Redis服务,在Redis目录下创建 redis-server-cluster.bat 批处理文件,右键菜单编辑打开,编写启动命令

start "Redis3.0.504-cluster6380" "D:\work\TfsRedis\Redis-x64-3.0.504\redis-server.exe" "D:\work\TfsRedis\Redis-x64-3.0.504\redis-cluster6380.conf"
start "Redis3.0.504-cluster6381" "D:\work\TfsRedis\Redis-x64-3.0.504\redis-server.exe" "D:\work\TfsRedis\Redis-x64-3.0.504\redis-cluster6381.conf"
start "Redis3.0.504-cluster6382" "D:\work\TfsRedis\Redis-x64-3.0.504\redis-server.exe" "D:\work\TfsRedis\Redis-x64-3.0.504\redis-cluster6382.conf"

start "Redis3.0.504-slave6383" "D:\work\TfsRedis\Redis-x64-3.0.504\redis-server.exe" "D:\work\TfsRedis\Redis-x64-3.0.504\redis-slave6383.conf"
start "Redis3.0.504-slave6384" "D:\work\TfsRedis\Redis-x64-3.0.504\redis-server.exe" "D:\work\TfsRedis\Redis-x64-3.0.504\redis-slave6384.conf"
start "Redis3.0.504-slave6385" "D:\work\TfsRedis\Redis-x64-3.0.504\redis-server.exe" "D:\work\TfsRedis\Redis-x64-3.0.504\redis-slave6385.conf"

保存关闭备用。

三、配置 Ruby Redis 集群管理命令工具

四、命令行设置 Redis 集群配置

建议新创建集群之前将 Redis 运行程序目录下的 nodes-638*.conf 删除

redis-trib.rb create --replicas 0 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382

–replicas 0 表示集群每个服务器有0个从服务器

redis-trib.rb create --replicas 1 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385

–replicas 1 表示集群每个服务器有1个从服务器
从服务器配置文件无需配置 slaveof <host> <port>redis-trib.rb create 命令会自动分配主从关系。

五、添加/删除节点

  • 添加节点命令
redis-trib.rb
add-node        new_host:new_port existing_host:existing_port
                --slave
                --master-id <arg>
  • 添加 master 节点
    命令示例
    redis-trib.rb add-node 127.0.0.1:6386 127.0.0.1:6380
    添加节点之后需要重新分配slot槽给新节点才能启用
    分配方式可以自定义,是平均分配还是从其他已有节点选取部分分配给新节点,都是可以自定义的

  • 添加 slave 节点
    命令示例
    redis-trib.rb add-node --slave 127.0.0.1:6387 127.0.0.1:6380
    添加从节点不需要slot槽重新分配

  • 重新分配
    从已有节点(6382)分配slot槽给新节点(6386)
    命令示例
    redis-trib.rb reshard 127.0.0.1:6386
    执行过程中有提示

PS D:\work\TfsRedis\Redis3.0cluster> .\redis-trib.rb reshard 127.0.0.1:6381
Connecting to node 127.0.0.1:6381: OK
Connecting to node 127.0.0.1:6380: OK
Connecting to node 127.0.0.1:6386: OK
Connecting to node 127.0.0.1:6385: OK
Connecting to node 127.0.0.1:6383: OK
Connecting to node 127.0.0.1:6384: OK
Connecting to node 127.0.0.1:6382: OK
>>> Performing Cluster Check (using node 127.0.0.1:6381)
M: d8ddc0ece223206991f242b8ee40e0974bba7a59 127.0.0.1:6381
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
M: b15315a9890ca334fefb446702cbb4686132f59d 127.0.0.1:6380
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 0483b953078e6decc1d948918d024f9abf342d43 127.0.0.1:6386
   slots: (0 slots) master
   0 additional replica(s)
S: c3d8aa6bfcf83666dd0c387d6efe31be883a0720 127.0.0.1:6385
   slots: (0 slots) slave
   replicates b15315a9890ca334fefb446702cbb4686132f59d
S: c4ef5b13482681b3bdce4fbf4b1ac4133fe1e0d6 127.0.0.1:6383
   slots: (0 slots) slave
   replicates d8ddc0ece223206991f242b8ee40e0974bba7a59
S: 0b4d057755f4fd6d33d5ca01c0b71a5f0dc3fa74 127.0.0.1:6384
   slots: (0 slots) slave
   replicates 78e9d9a7ed3383aec838acb9af7eefebe8af54d7
M: 78e9d9a7ed3383aec838acb9af7eefebe8af54d7 127.0.0.1:6382
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 600
What is the receiving node ID? 0483b953078e6decc1d948918d024f9abf342d43
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
Source node #1:d8ddc0ece223206991f242b8ee40e0974bba7a59
Source node #2:done
Ready to move 600 slots.
  Source nodes:
    M: d8ddc0ece223206991f242b8ee40e0974bba7a59 127.0.0.1:6381
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
  Destination node:
    M: 0483b953078e6decc1d948918d024f9abf342d43 127.0.0.1:6386
   slots: (0 slots) master
   0 additional replica(s)
  Resharding plan:
    Moving slot 5461 from d8ddc0ece223206991f242b8ee40e0974bba7a59
    ...
    Moving slot 6060 from d8ddc0ece223206991f242b8ee40e0974bba7a59
Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot 5461 from 127.0.0.1:6381 to 127.0.0.1:6386:
...
Moving slot 6060 from 127.0.0.1:6381 to 127.0.0.1:6386:
PS D:\work\TfsRedis\Redis3.0cluster>

How many slots do you want to move (from 1 to 16384)?
要重新分配多少槽(从1个到16384个),此处重新分配600个槽

What is the receiving node ID?
哪个节点接收600个槽,0483b953078e6decc1d948918d024f9abf342d43是节点的ID

Please enter all the source node IDs. Type 'all' to use all the nodes as source nodes for the hash slots. Type 'done' once you entered all the source nodes IDs. Source node #1:d8ddc0ece223206991f242b8ee40e0974bba7a59 Source node #2:done
这里意思是从哪个节点取这600个槽,两种获取方式
方式一,all表示从所有已有节点中取600个槽,是平均分配取,还是随机分配取,还需要验证。
方式二,指定从某个节点或某几个节点取600个槽,当指定的某个或某几个节点确定后输入done结束指定节点,从某几个节点取,是平均分配取还是随机分配取也需要验证。

  • 删除节点命令
    删除节点前将已分配的slot槽重新分配回收,重新分配方法参见上一节。
    命令示例
    redis-trib.rb del-node 127.0.0.1:6386 0483b953078e6decc1d948918d024f9abf342d43
    原文作者:codefly
    原文地址: https://www.jianshu.com/p/0b04c003aaa6
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞