安裝Redis
https://github.com/MSOpenTech/redis/releases/download/win-3.0.501/Redis-x64-3.0.501.msi
安裝Ruby
http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.2.4-x64.exe
安裝了rubyinstaller之后就可以執(zhí)行g(shù)em命令
3.安裝Redis的Ruby庫
gem install redis
4.配置Redis Node
這里啟動6個Redis Node, 將用到6個conf文件
拷貝6份Redis安裝目錄下的redis.windows-service.conf
文件依次重命名為 redis.6380.conf捧书、redis.6381.conf侠讯、redis.6382.conf鹅颊、redis.6383.conf癞己、redis.6384.conf苍匆、redis.6385.conf辈毯。
并分別修改這6個配置文件 :
redis.6380.conf
port 6380
appendonly yes
appendfilename "appendonly.6380.aof"
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.6381.conf
port 6381
appendonly yes
appendfilename "appendonly.6381.aof"
cluster-enabled yes
cluster-config-file nodes-6381.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
redis.6382.conf
port 6382
appendonly yes
appendfilename "appendonly.6382.aof"
cluster-enabled yes
cluster-config-file nodes-6382.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
redis.6383.conf
port 6383
appendonly yes
appendfilename "appendonly.6383.aof"
cluster-enabled yes
cluster-config-file nodes-6383.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
redis.6384.conf
port 6384
appendonly yes
appendfilename "appendonly.6384.aof"
cluster-enabled yes
cluster-config-file nodes-6384.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
redis.6385.conf
port 6385
appendonly yes
appendfilename "appendonly.6385.aof"
cluster-enabled yes
cluster-config-file nodes-6385.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes
配置完畢抑堡。他們之間得差異就是改了下端口站玄。
注冊Redis為Windows Service
在服務(wù)中停掉Redis默認安裝時已經(jīng)注冊到端口號為6379的服務(wù)按摘。
redis-server --service-install redis.6380.conf --service-name redis6380
redis-server --service-start --service-name Redis6380
redis-server --service-install redis.6381.conf --service-name redis6381
redis-server --service-start --service-name Redis6381
redis-server --service-install redis.6382.conf --service-name redis6382
redis-server --service-start --service-name Redis6382
redis-server --service-install redis.6383.conf --service-name redis6383
redis-server --service-start --service-name Redis6383
redis-server --service-install redis.6384.conf --service-name redis6384
redis-server --service-start --service-name Redis6384
redis-server --service-install redis.6385.conf --service-name redis6385
redis-server --service-start --service-name Redis6385
創(chuàng)建Redis Cluster
下載 https://raw.githubusercontent.com/MSOpenTech/redis/3.0/src/redis-trib.rb 腳本到Redis安裝目錄讥邻,在命令行執(zhí)行如下命令:
C:\Redis>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
>>> Creating cluster
Connecting to node 127.0.0.1:6380: OK
Connecting to node 127.0.0.1:6381: OK
Connecting to node 127.0.0.1:6382: 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:6385: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:6380
127.0.0.1:6381
127.0.0.1:6382
Adding replica 127.0.0.1:6383 to 127.0.0.1:6380
Adding replica 127.0.0.1:6384 to 127.0.0.1:6381
Adding replica 127.0.0.1:6385 to 127.0.0.1:6382
M: 49060b7f06bd3839895919a06ba43d0508b1149f 127.0.0.1:6380
slots:0-5460 (5461 slots) master
M: 0bfbefc15a586f1a893ef150af43031a7ce04a9f 127.0.0.1:6381
slots:5461-10922 (5462 slots) master
M: 5fb098d997e0f0b9e723b09400604344ec65179b 127.0.0.1:6382
slots:10923-16383 (5461 slots) master
S: e2d74cfcccf88aef1dec16b1922ca2ad6dc16195 127.0.0.1:6383
replicates 49060b7f06bd3839895919a06ba43d0508b1149f
S: bcbe8bf76a5b0d37768556ed752e30dcfea069f6 127.0.0.1:6384
replicates 0bfbefc15a586f1a893ef150af43031a7ce04a9f
S: bbfc7026df6822bf3cfd8e4a3549b02ca57f7393 127.0.0.1:6385
replicates 5fb098d997e0f0b9e723b09400604344ec65179b
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join...
>>> Performing Cluster Check (using node 127.0.0.1:6380)
M: 49060b7f06bd3839895919a06ba43d0508b1149f 127.0.0.1:6380
slots:0-5460 (5461 slots) master
M: 0bfbefc15a586f1a893ef150af43031a7ce04a9f 127.0.0.1:6381
slots:5461-10922 (5462 slots) master
M: 5fb098d997e0f0b9e723b09400604344ec65179b 127.0.0.1:6382
slots:10923-16383 (5461 slots) master
M: e2d74cfcccf88aef1dec16b1922ca2ad6dc16195 127.0.0.1:6383
slots: (0 slots) master
replicates 49060b7f06bd3839895919a06ba43d0508b1149f
M: bcbe8bf76a5b0d37768556ed752e30dcfea069f6 127.0.0.1:6384
slots: (0 slots) master
replicates 0bfbefc15a586f1a893ef150af43031a7ce04a9f
M: bbfc7026df6822bf3cfd8e4a3549b02ca57f7393 127.0.0.1:6385
slots: (0 slots) master
replicates 5fb098d997e0f0b9e723b09400604344ec65179b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
C:\Redis>
到此
Redis Cluster創(chuàng)建完畢,從控制臺輸出可以看到:
127.0.0.1:6380院峡,
127.0.0.1:6381炉旷,
127.0.0.1:6382為
master節(jié)點。
127.0.0.1:6383俺叭,
127.0.0.1:6384铃拇,
127.0.0.1:6385依次為相對應(yīng)的副節(jié)點。
參考文檔
在Windows上安裝Redis Cluster
https://dotblogs.com.tw/supershowwei/2015/12/29/101928
Redis集群研究和實踐(基于redis 3.0.5)
https://www.zybuluo.com/phper/note/195558