redis集群搭建

参考:https://www.cnblogs.com/yaozb/p/6911395.html

1:安装redis

2: 安装ruby

3:更改源

删除源

C:Userslenovo>gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources

更改源:出现错误

C:Userslenovo>gem sources --add https://gems.ruby-china.org/
ERROR:  SSL verification error at depth 1: unable to get local issuer certificate (20)
ERROR:  You must add /O=Digital Signature Trust Co./CN=DST Root CA X3 to your local trusted store
Error fetching https://gems.ruby-china.org/:
        SSL_connect returned=1 errno=0 state=error: certificate verify failed (https://gems.ruby-china.org/specs.4.8.gz)

错误解决:https://ruby-china.org/topics/33707

为源添加验证:添加到系统环境变量

C:Userslenovo>set SSL_CERT_FILE=D:software
ubycacert.pem

提示版本错误

C:Userslenovo>gem sources --add https://gems.ruby-china.org/
Error fetching https://gems.ruby-china.org/:
        bad response Not Found 404 (https://gems.ruby-china.org/specs.4.8.gz)

 更改为,因为员现在为:https://gems.ruby-china.com/

C:Userslenovo>gem sources --add https://gems.ruby-china.com/
https://gems.ruby-china.com/ added to sources

4:使用ruby搭建集群。

D:software
edis>ruby 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
>>> 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: f2ec608e843a81a9531f3390fa336c27839f24ad 127.0.0.1:6380
   slots:0-5460 (5461 slots) master
M: dcb3491324dc14b411a6cd26b7971df7ab74c372 127.0.0.1:6381
   slots:5461-10922 (5462 slots) master
M: 50a9d32d298bc0de7b66b6a455b6a2eeef1d247b 127.0.0.1:6382
   slots:10923-16383 (5461 slots) master
S: e9744a80b2594665cb214048dedc2743ac66de7f 127.0.0.1:6383
   replicates f2ec608e843a81a9531f3390fa336c27839f24ad
S: 9dd7fcc8863080363bcc84326481f4dd7cdd0fcb 127.0.0.1:6384
   replicates dcb3491324dc14b411a6cd26b7971df7ab74c372
S: 3d6cb8dad44b0db8e419288e9f8d1ce6618a53fd 127.0.0.1:6385
   replicates 50a9d32d298bc0de7b66b6a455b6a2eeef1d247b
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: f2ec608e843a81a9531f3390fa336c27839f24ad 127.0.0.1:6380
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: e9744a80b2594665cb214048dedc2743ac66de7f 127.0.0.1:6383
   slots: (0 slots) slave
   replicates f2ec608e843a81a9531f3390fa336c27839f24ad
S: 9dd7fcc8863080363bcc84326481f4dd7cdd0fcb 127.0.0.1:6384
   slots: (0 slots) slave
   replicates dcb3491324dc14b411a6cd26b7971df7ab74c372
S: 3d6cb8dad44b0db8e419288e9f8d1ce6618a53fd 127.0.0.1:6385
   slots: (0 slots) slave
   replicates 50a9d32d298bc0de7b66b6a455b6a2eeef1d247b
M: 50a9d32d298bc0de7b66b6a455b6a2eeef1d247b 127.0.0.1:6382
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
M: dcb3491324dc14b411a6cd26b7971df7ab74c372 127.0.0.1:6381
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

redis-trib管理集群的方式已经从redis 5.0之后删除了,使用redis-cli搭建集群: https://blog.csdn.net/xiyujianxia/article/details/80679187

D:software
edis>redis-trib.rb   -- redis 5.0之后的redis-trib.rb
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 info 127.0.0.1:7000

To get help about all subcommands, type:
redis-cli --cluster help

 5:使用集群,进入redis目录下,使用redis-cli连接一个客户端,进行添加键值

D:software
edis6380>redis-cli -h 127.0.0.1 -p 6380 -c
127.0.0.1:6380> set hello world
OK
127.0.0.1:6380> get hello
"world"
127.0.0.1:6380> set k1 hello,world
-> Redirected to slot [12706] located at 127.0.0.1:6382
OK
127.0.0.1:6382>

出现的问题:需要安装ruby环境,修改源等。

原文地址:https://www.cnblogs.com/liyafei/p/9575172.html