准备:Redis-x64-3.2.100版本,Ruby23-x64 , rubygems-3.0.6
安装Ruby ,网上有很多教程,这里我安装过就不再安装了,大家可以去搜一下就可以了
相应的安装包到这里去下载:链接:https://pan.baidu.com/s/1sQPWIq1yyKXr_adduXUt4g
提取码:xy5n
环境搭建好了之后我们来集群的步骤及其过程
step1:
我在本地创建了这么几个目录,以端口号作为文件名,其中redis目录的端口号对应9006
每个目录下都是
start.bat 是自己写的启动脚本,不然每次都要敲cmd命令很麻烦,start.bat的内容很简单如下:
title 9000
redis-server.exe redis.windows.conf
step2:
title可以随便取,这里是cmd 的title而已
我们需要改一下redis.windows.conf配置文件(每个目录都要对应修改)
内容如下:
添加上这么一句,port需要修改成对应的端口,到此redis.windows.conf配置文件修改完毕。
step3:
安装Redis的Ruby驱动redis-xxxx.gem
例如:
切换到解压目录执行 ruby setup.rb。
然后GEM 安装 Redis :切换到我们step1 创建的redis安装目录,需要在命令行中,执行 gem install redis。
step4:安装集群脚本redis-trib
下载地址 https://raw.githubusercontent.com/antirez/redis/unstable/src/redis-trib.rb
打开该链接如果没有下载,而是打开一个页面,那么将该页面保存为redis-trib.rb,建议保存到一个Redis的目录下,例如放到Redis目录下。
集群的命令为
ruby redis-trib.rb create --replicas 1 127.0.0.1:9000 127.0.0.1:9001 127.0.0.1:9002 127.0.0.1:9003 127.0.0.1:9004 127.0.0.1:9005
--replicas 1 表示每个主数据库拥有从数据库个数为1。master节点不能少于3个,所以我们用了6个redis
如果出现类似的错误
D:\redis\6379>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:6382 127.0.0.1:6383 127.0.0.1:6384
WARNING: redis-trib.rb is not longer available!
You should use redis-cli instead.
All commands and features belonging to redis-trib.rb have been moved
to redis-cli.
In order to use them you should call redis-cli with the --cluster
option followed by the subcommand name, arguments and options.
Use the following syntax:
redis-cli --cluster SUBCOMMAND [ARGUMENTS] [OPTIONS]
Example:
redis-cli --cluster create 127.0.0.1:6379 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 --cluster-replicas 1
To get help about all subcommands, type:
redis-cli --cluster help
打开 此事redis 的源码,没有对应版本的可以到网上去下载对应版本
下载redis源码版压缩包:http://download.redis.io/releases/
使用这个
遇到 输入yes 就输入yes,
到此集群的配置就完成了,
step5:
我们来验证体验一下:
使用命令连接redis
redis-cli.exe -c -p 9000
执行set dda ds 得到如下:
表示设置的这个键值对是在9002机器上
可以看出获取的也是9002上的,、
使用redis manager也看出数据是存放在9002机器上
到此就结束了,只是学习的时候记录一下,参考大佬的地址:https://www.cnblogs.com/yangjinwang/p/8581313.html