windows下集群Redis

来源:互联网 发布:为什么ofo网络异常 编辑:程序博客网 时间:2024/05/02 01:18
1,下载Redis for windows 的最新版本,解压到 c:\Redis 目录下备用https://github.com/MSOpenTech/redis/releases当前我使用的是 3.0.501 2,下载 RubyInstallerhttp://rubyinstaller.org/downloads/安装时,勾选Install Td/Tk SupportAdd Ruby executables to your PATHAssociate .rb and .rbw files with this Ruby installation 3,下载 redis-trib.rb , 放到 c:\redis 目录下备用https://raw.githubusercontent.com/antirez/redis/unstable/src/redis-trib.rb 4,新建6个子文件夹cmdcd c:\redismkdir 7000 7001 7002 7003 7004 7005 5,将如下配置修改,分别放入上一步新建的6个子文件夹中, 保存为 redis.conf:port 7000cluster-enabled yescluster-config-file nodes-7000.confcluster-node-timeout 5000appendonly yes注意,将 port 和 cluster-config-file 改掉(每个文件都不一样) 6, 为方便启动这些 Redis 实例,新建如下 bat 文件:@echo offcd c:\Redisstart Redis-Server ./6379/redis.confstart Redis-Server ./6380/redis.confstart Redis-Server ./6381/redis.conf 7, 运行上步新建的 bat 文件,会打开6个窗口,每个窗口承载一个 Redis 实例,端口从 7000 至 7005在 c:\Redis 文件夹下会出现 nodes-7000.conf 至 nodes-7005.conf 这几个文件 8,安装 GEM,Redis 的 ruby 支持环境https://rubygems.org/ 由于 GFW的问题, GEM 的源在国内不可用,所以使用淘宝的映像: 添加:gem sources -a https://ruby.taobao.org 查看已存在的源:gem sources -l删除被墙的源:gem sources -r https://rubygems.org/这里添加GEM如果一直失败,把地址换成gem sources -a http://gems.ruby-china.org/  因为taobao Gems 源已停止维护安装 Redis 支持环境:gem install redis 9,创建群集打开 cmd , 执行以下命令:cd c:\redisredis-trib.rb create --replicas 1 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381--replicas 1 即自动分配 Slave , 如果想手动指定 Slave  , 将该值变为 0 即可, 地址列表中,只需要 3个实例即可。 由于使用的是 6个实例,自动分配 Slave ,所以前3个为 master , 后3 个为 slave, 并确定3个主节点的 slots 范围。如果确认没有问题, 输入 yes如果群集创建成功, 会输出 OK XXXXX如果出现:err slot xxx is already busy, 请删除 appendonly.aof 及 nodes-xxx.conf (cluster-config-file 所指的文件) 文件 10, 测试一下:redis-cli.exe -c -p 6380  --------------------------------------以上是同一台机器上的群集部署方案,同一台虚拟机,使用不同的实例, 创建群集时,一路顺利。 但是将实例部署到不同的机器上,我分别在6台虚拟机上安装了 Redis, 但一开始创建群集的时候,就卡在这里:>>> Nodes configuration updated>>> Assign a different config epoch to each node>>> Sending CLUSTER MEET messages to join the clusterWaiting for the cluster to join.................... 一直在这个 Waiting for the cluster to join 这里。。。用 redis-trib.rb check 192.168.18.111:6379 检查,提示[ERR] Not all 16384 slots are covered by nodes 具体的就是某台 master 上的 sloats 是 0用客户端连接到那个没有分配 sloat 的 redis 实例,发送以下命令:cluster meet 192.168.18.111 6379回头在用 Redis-trib.rb check 检查, 发现 [OK] All 16384 slots covered. 但是群集的创建还是卡在那个 waiting 上 ,继续在其它节点上发送 cluster meet 命令,回头在用 redis-trib.rb check , 神奇的 Not all 16384 slots are covered by nodes 居然又来了。将那个slots 为 0的实例做为 slave (放到参数列表的最后),在创建,顺利通过!这个问题真是神奇啊!

原创粉丝点击