windows 上建立redis集群

In this post, I will explain how to create cluster for Redis 3.2 on Windows.

  1. Create 3 master Redis Nodes on the same server, port: 7000, 7001, 7002
  2. Create 3 slave Redis Nodes on the same server, port: 7003, 7004, 7005
  3. Master Slave: 7000 – 7003; 7001-7004; 7002-7005.

Redis 3.2 on Windows Resource

  1. Redis Official Site: https://redis.io/
  2. Redis on Windows GitHub Project: https://github.com/MicrosoftArchive/redis
  3. Installing Redis: https://www.javacodegeeks.com/2015/09/redis-clustering.html#InstallingRedis

Configure Redis

There are several minimum configuration we need to do for Cluster. See https://redis.io/topics/cluster-tutorial

port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes

配置项前面不能有#号(此为注释符),也不能有空格

Create Redis Windows Services

Follow my last post to create 6 Redis Nodes with ports: 7000, 7001, 7002, 7003, 7004, 7005
Start the 6 Redis nodes.

redis-server --service-install redis.windows-service.conf --service-name Redis7000 --port 7000
redis-server --service-start --service-name Redis7000

NOTE THAT YOU SHOULD CONFIG redis.windows-service.conf FILE RATHER THAN redis.windows.conf
服务的卸载
使用sc delete redis7000
然后重启即可。(上面的命令只是将该服务标记为卸载状态,需要重启将其真正卸载)

Configure Master Nodes

此部分参考
https://blog.csdn.net/hao495430759/article/details/80540407
http://www.redis.cn/topics/cluster-tutorial.html
https://www.cnblogs.com/super-chao/p/9329018.html

  1. 下载Ruby并安装:
    下载地址:http://railsinstaller.org/en

  2. 完成后进行配置

ruby -v
gem -v
gem sources

gem install redis
  1. 下载对应版本的redis发行版源码,拷贝src文件夹下的redis-trib.rb文件至7000的平行目录

  2. 执行

redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

Test Cluster

Please use -c option, which means enabling cluster. Otherwise, you will get (ERROR) MOVED to ……

$ redis-cli -c -p 7000
redis 127.0.0.1:7000> set foo bar
-> Redirected to slot [12182] located at 127.0.0.1:7002
OK
redis 127.0.0.1:7002> set hello world
-> Redirected to slot [866] located at 127.0.0.1:7000
OK
redis 127.0.0.1:7000> get foo
-> Redirected to slot [12182] located at 127.0.0.1:7002
"bar"
redis 127.0.0.1:7000> get hello
-> Redirected to slot [866] located at 127.0.0.1:7000
"world"

https://dingyuliang.me/redis-3-2-create-cluster-windows/

常见错误:

  1. 错误一:
    WARNING: redis-trib.rb is not longer available!
    You should use redis-cli instead.
    解决方案
    原因是redis-trib.rb的链接指向官网最新的版本。从对应版本(redis3.2.0即可)的源码压缩包中src文件夹下找到对应的redis-trib.rb文件使用,即可解决问题。
    下载redis源码版压缩包:http://download.redis.io/releases/
  2. 错误二:
    (error) MOVED
    解决方案:
    这种情况一般是因为启动redis-cli时没有设置集群模式所导致。
    redis-cli -c -p 7000
  3. 错误三:
    Node is not empty
    1)通过sc delete将服务卸载并重启服务器
    2)删除结点下的aof、rdb、nodes.conf文件
    3)重新安装服务

命令相关:

  1. 查看redis版本信息
    redis-cli -p 7000
    输入info
  2. 查看集群主从情况
    redis-cli -c -p 7000 cluster nodes
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值