redis windows集群搭建

1.把 redis 解压后,再复制出 5 份,配置 三主三从集群。 端口可以为7000,7001,7002,7003,7004,7005。 并且把目录使用端口号命名

2.修改其他配置支持集群
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000
appendonly yes

3.安装ruby
https://rubyinstaller.org/downloads/ 下载 rubyinstaller-2.4.4-1-x64.exe



4.安装ruby的redis驱动
https://rubygems.org/gems/redis/versions/3.3.3

C:\Users\stager7.000>gem install --local C:\Ruby24-x64\redis-3.3.3.gem
Successfully installed redis-3.3.3
Parsing documentation for redis-3.3.3
Installing ri documentation for redis-3.3.3
Done installing documentation for redis after 1 seconds
1 gem installed

5. 下载Redis官方提供的创建Redis集群的ruby脚本文件redis-trib.rb
   打开该链接如果没有下载,而是打开一个页面,那么将该页面保存为redis-trib.rb
https://raw.githubusercontent.com/MSOpenTech/redis/3.0/src/redis-trib.rb


打开该链接如果没有下载,而是打开一个页面,那么将该页面保存为redis-trib.rb,建议保存到一个Redis的目录下,例如放到6379目录下。

集群的命令为
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

--replicas 1 表示每个主数据库拥有从数据库个数为1。master节点不能少于3个,所以我们用了6个redis




D:\soft\redis-cluster\Redis7000>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
>>> Creating cluster
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7005: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:7000
127.0.0.1:7001
127.0.0.1:7002
Adding replica 127.0.0.1:7003 to 127.0.0.1:7000
Adding replica 127.0.0.1:7004 to 127.0.0.1:7001
Adding replica 127.0.0.1:7005 to 127.0.0.1:7002
M: 2bf9576d9f31cfda6072d3801260d6f2e734ed3b 127.0.0.1:7000
   slots:0-5460 (5461 slots) master
M: 5e935a190feebc4f29fc96135ca2601c5c748405 127.0.0.1:7001
   slots:5461-10922 (5462 slots) master
M: 3fdbbaf3916d266ceb41bfa4fe25ee0f9cd08527 127.0.0.1:7002
   slots:10923-16383 (5461 slots) master
S: 6ccfef96a13539feca226ae3d4b3c9e6b77de645 127.0.0.1:7003
   replicates 2bf9576d9f31cfda6072d3801260d6f2e734ed3b
S: 7d50ed2b349b44de68dd9d28658f1d58d2c6061a 127.0.0.1:7004
   replicates 5e935a190feebc4f29fc96135ca2601c5c748405
S: e94d6560e73ec6ebe38f70517f3b6eadf1f9fcbb 127.0.0.1:7005
   replicates 3fdbbaf3916d266ceb41bfa4fe25ee0f9cd08527
Can I set the above configuration? (type 'yes' to accept): yes


6 测试

使用Redis客户端Redis-cli.exe来查看数据记录数,以及集群相关信息

命令 redis-cli –c –h ”地址” –p "端口号" ;  c 表示集群

D:\soft\redis-cluster\Redis7000>redis-cli -c -h 127.0.0.1 -p 7000
127.0.0.1:7000> dbsize
(integer) 0
127.0.0.1:7000>
输入cluster info可以从客户端的查看集群的信息

127.0.0.1:7000> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_sent:651
cluster_stats_messages_received:651
127.0.0.1:7000>


java 集群操作
https://blog.csdn.net/liubenlong007/article/details/53766734 jedisCluster

https://www.cnblogs.com/lxcy/p/8120301.html

猜你喜欢

转载自pengfeifei26.iteye.com/blog/2418395