redis集群安装和使用
需要安装GCC库、LibC、LibStdC++、Rubby库(1.9.2或以上)、ZLIB库(1.2.6或以上)
两台虚拟机都是 CentOS ,一台 CentOS6.5 (IP:192.168.16.130),一台 CentOS7(IP:192.168.16.135) ,我配置了host的我用weekend110代替192.168.16.130,weekend111代替192.168.16.135
一、 下载安装包 官网https://redis.io/download
也可以用wget
wget http://download.redis.io/releases/redis-3.2.6.tar.gz
tar -zxvf redis-3.2.6.tar.gz
二、编译安装
cd redis-3.2.6
make && make install
三、进入src文件夹将 redis-trib.rb 复制到 /usr/local/bin 目录下
cd src
cp redis-trib.rb /usr/local/bin/
四、创建 Redis 节点
首先在 192.168.16.130 我改了host可以用weekend110 机器上 /home/zzq/software/redis-3.2.4 目录下创建 redis_cluster 目录;
[zzq@weekend110 src]$ cd ~/software/redis-3.2.6
[zzq@weekend110 redis-3.2.6]$ mkdir redis_cluster
在 redis_cluster 目录下,创建名为7000、7001、7002的目录,并将 redis.conf 拷贝到这三个目录中
[zzq@weekend110 redis-3.2.6]$ cd redis_cluster/
[zzq@weekend110 redis_cluster]$ mkdir 7000 7001 7002
[zzq@weekend110 redis_cluster]$ ll
total 12
drwxrwxr-x. 2 zzq zzq 4096 Jan 10 02:44 7000
drwxrwxr-x. 2 zzq zzq 4096 Jan 10 02:44 7001
drwxrwxr-x. 2 zzq zzq 4096 Jan 10 02:44 7002
分别修改这三个配置文件的主要配置,修改如下内容
port 7000 //端口7000,7002,7003
bind 本机ip //默认ip为127.0.0.1 需要改为其他节点机器可访问的ip 否则创建集群时无法访问对应的端口,无法创建集群
daemonize yes //redis后台运行
pidfile /var/run/redis_7000.pid //pidfile文件对应7000,7001,7002
cluster-enabled yes //开启集群 把注释#去掉
cluster-config-file nodes_7000.conf //集群的配置 配置文件首次启动自动生成 7000,7001,7002
cluster-node-timeout 15000 //请求超时 默认15秒,可自行设置
appendonly yes //aof日志开启 有需要就开启,它会每次写操作都记录一条日志
接着在另外一台机器上(192.168.16.135)我改了host可用weekend111,的操作重复以上三步,只是把目录改为7003、7004、7005,对应的配置文件也按照这个规则配置修改即可
远程拷贝(我配置了无密登陆)
[zzq@weekend110 software]$ scp redis-3.2.6.tar.gz weekend111:/home/zzq/software
redis-3.2.6.tar.gz 100% 1509KB 1.5MB/s 00:00
[zzq@weekend110 software]$
五、启动各个节点
weekend110机器上执行
redis-server redis_cluster/7000/redis.conf
redis-server redis_cluster/7001/redis.conf
redis-server redis_cluster/7002/redis.conf
weekend111机器上执行
redis-server redis_cluster/7003/redis.conf
redis-server redis_cluster/7004/redis.conf
redis-server redis_cluster/7005/redis.conf
可以写个shell脚本启动方便点
六、检查启动情况
[zzq@weekend110 redis-3.2.6]$ ps -ef | grep redis
zzq 5194 1 0 03:18 ? 00:00:00 redis-server weekend110:7000 [cluster]
zzq 5196 1 0 03:18 ? 00:00:00 redis-server weekend110:7001 [cluster]
zzq 5200 1 0 03:18 ? 00:00:00 redis-server weekend110:7002 [cluster]
zzq 5206 1944 0 03:18 pts/0 00:00:00 grep redis
[zzq@weekend110 redis-3.2.6]$ netstat -tnlp | grep redis
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 192.168.16.130:17000 0.0.0.0:* LISTEN 5194/redis-server w
tcp 0 0 192.168.16.130:17001 0.0.0.0:* LISTEN 5196/redis-server w
tcp 0 0 192.168.16.130:17002 0.0.0.0:* LISTEN 5200/redis-server w
tcp 0 0 192.168.16.130:7000 0.0.0.0:* LISTEN 5194/redis-server w
tcp 0 0 192.168.16.130:7001 0.0.0.0:* LISTEN 5196/redis-server w
tcp 0 0 192.168.16.130:7002 0.0.0.0:* LISTEN 5200/redis-server w
weekend111:
[root@weekend111 redis-3.2.6]# ps -ef | grep redis
root 5612 1 0 03:33 ? 00:00:00 redis-server weekend111:7003 [cluster]
root 5614 1 0 03:33 ? 00:00:00 redis-server weekend111:7004 [cluster]
root 5618 1 0 03:33 ? 00:00:00 redis-server weekend111:7005 [cluster]
root 5624 5598 0 03:33 pts/0 00:00:00 grep redis
[root@weekend111 redis-3.2.6]# netstat -tnlp | grep redis
tcp 0 0 192.168.16.135:17003 0.0.0.0:* LISTEN 5612/redis-server w
tcp 0 0 192.168.16.135:17004 0.0.0.0:* LISTEN 5614/redis-server w
tcp 0 0 192.168.16.135:17005 0.0.0.0:* LISTEN 5618/redis-server w
tcp 0 0 192.168.16.135:7003 0.0.0.0:* LISTEN 5612/redis-server w
tcp 0 0 192.168.16.135:7004 0.0.0.0:* LISTEN 5614/redis-server w
tcp 0 0 192.168.16.135:7005 0.0.0.0:* LISTEN 5618/redis-server w
Redis 官方提供了 redis-trib.rb 这个工具,就在解压目录的 src 目录中,第三步中已将它复制到 /usr/local/bin 目录中,可以直接在命令行中使用了。使用下面这个命令即可完成安装。
redis-trib.rb create --replicas 1 weekend110:7000 weekend110:7001 weekend110:7002 weekend111:7003 weekend111:7004 weekend111:7005
其中,前三个 ip:port 为第一台机器的节点,剩下三个为第二台机器。
执行可能会出错
[zzq@weekend110 software]$ redis-trib.rb create --replicas 1 192.168.16.130:7000 192.168.16.130:7001 192.168.16.130:7002 192.168.16.135:7003 192.168.16.135:7004 192.168.16.135:7005
/usr/bin/env: ruby: No such file or directory
因为这个工具是用 ruby 实现的,所以需要安装 ruby。安装命令如下:
yum -y install ruby ruby-devel rubygems rpm-build
gem sources -a https://ruby.taobao.org/(使用来的镜像不行了,改成taobao的)
gem install redis
[zzq@weekend110 software]$ gem sources -a https://ruby.taobao.org/
https://ruby.taobao.org/ added to sources
[zzq@weekend110 software]$ sudo gem install redis
[sudo] password for zzq:
Successfully installed redis-3.3.2
1 gem installed
Installing ri documentation for redis-3.3.2...
Installing RDoc documentation for redis-3.3.2...
此时再创建集群
出现如下提示:
[zzq@weekend110 software]$ redis-trib.rb create --replicas 1 192.168.16.130:7000 192.168.16.130:7001 192.168.16.130:7002 192.168.16.135:7003 192.168.16.135:7004 192.168.16.135:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
weekend111:7003
weekend110:7000
weekend111:7004
Adding replica weekend110:7001 to weekend111:7003
Adding replica weekend111:7005 to weekend110:7000
Adding replica weekend110:7002 to weekend111:7004
M: 22c830989edd71c241c75a391654e5b3be2935c3 weekend110:7000
slots:5461-10922 (5462 slots) master
S: 64f2ed6a063c66ec765fdcbc08044b832883e227 weekend110:7001
replicates 597b1640d1e44e2cea4dd9a8f39724b780511017
S: 1c013c31ff607aaee841f49637168ce721cd706b weekend110:7002
replicates d264462956c37b9c6b5a7da9734ace1635c1a04f
M: 597b1640d1e44e2cea4dd9a8f39724b780511017 weekend111:7003
slots:0-5460 (5461 slots) master
M: d264462956c37b9c6b5a7da9734ace1635c1a04f weekend111:7004
slots:10923-16383 (5461 slots) master
S: fcd57bc490898e5e1b9a91a140a237d561cf0731 weekend111:7005
replicates 22c830989edd71c241c75a391654e5b3be2935c3
Can I set the above configuration? (type 'yes' to accept):
输入 yes 即可,然后出现如下内容,说明安装成功。
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 192.168.16.130:7000)
M: a5b9550a0b5d9cbf1128aa4f4931e34e02394d5f 192.168.16.130:7000
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: ae6678a39380c6e478fa5d402a03a87b5dfa6c19 192.168.16.130:7002
slots: (0 slots) slave
replicates a96baa9461063ad84e9f96da8750003ad1da5ce5
S: 81bbe4254ba350683a42a87e903f432ed76b70c1 192.168.16.130:7001
slots: (0 slots) slave
replicates 400ab4210c660549cc28dc40df7ef5289a811c8d
M: a96baa9461063ad84e9f96da8750003ad1da5ce5 192.168.16.135:7004
slots:10923-16383 (5461 slots) master
1 additional replica(s)
M: 400ab4210c660549cc28dc40df7ef5289a811c8d 192.168.16.135:7003
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: 97217c4b01fcbe0f1f2488cf3357f0127b48a4c9 192.168.16.135:7005
slots: (0 slots) slave
replicates a5b9550a0b5d9cbf1128aa4f4931e34e02394d5f
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
这样集群搭建成功,如果这步出现很多错误,可以到最下面参考下解决办法。
八、集群验证
在第一台机器上连接集群的7002端口的节点,在另外一台连接7005节点,连接方式为 redis-cli -h 192.168.16.130 -c -p 7002 ,加参数 -C 可连接到集群,因为上面 redis.conf 将 bind 改为了ip地址,所以 -h 参数不可以省略。
[zzq@weekend110 redis-3.2.6]$ redis-cli -h 192.168.16.130 -c -p 7002
192.168.16.130:7002>
在7005节点执行命令 set hello world ,执行结果如下:
[root@weekend111 redis-3.2.6]# redis-cli -h 192.168.16.135 -c -p 7005
192.168.16.135:7005> set hello world
-> Redirected to slot [866] located at 192.168.16.135:7003
OK
然后在另外一台7002端口,查看 key 为 hello 的内容, get hello ,执行结果如下:
192.168.16.130:7002> get hello
-> Redirected to slot [866] located at 192.168.16.135:7003
"world"
说明集群运作正常。
redis关闭命令
redis-cli -h 192.168.16.130 -c -p 7000 shutdown
我的关闭节点
redis-cli -h 192.168.16.130 -c -p 7000 shutdown && redis-cli -h 192.168.16.130 -c -p 7001 shutdown && redis-cli -h 192.168.16.130 -c -p 7002 shutdown
redis-cli -h 192.168.16.135 -c -p 7003 shutdown && redis-cli -h 192.168.16.135 -c -p 7004 shutdown && redis-cli -h 192.168.16.135 -c -p 7005 shutdown
简略说一下原理
redis cluster在设计的时候,就考虑到了去中心化,去中间件,也就是说,集群中的每个节点都是平等的关系,都是对等的,每个节点都保存各自的数据和整个集群的状态。每个节点都和其他所有节点连接,而且这些连接保持活跃,这样就保证了我们只需要连接集群中的任意一个节点,就可以获取到其他节点的数据。
Redis 集群没有并使用传统的一致性哈希来分配数据,而是采用另外一种叫做哈希槽 (hash slot)的方式来分配的。redis cluster 默认分配了 16384 个slot,当我们set一个key 时,会用CRC16算法来取模得到所属的slot,然后将这个key 分到哈希槽区间的节点上,具体算法就是:CRC16(key) % 16384。所以我们在测试的时候看到set 和 get 的时候,直接跳转到了7000端口的节点。
Redis 集群会把数据存在一个 master 节点,然后在这个 master 和其对应的salve 之间进行数据同步。当读取数据时,也根据一致性哈希算法到对应的 master 节点获取数据。只有当一个master 挂掉之后,才会启动一个对应的 salve 节点,充当 master 。
需要注意的是:必须要3个或以上的主节点,否则在创建集群时会失败,并且当存活的主节点数小于总节点数的一半时,整个集群就无法提供服务了。
redis-trib.rb create的常见错误
1、
[zzq@weekend110 software]$ redis-trib.rb create --replicas 1 192.168.16.130:7000 192.168.16.130:7001 192.168.16.130:7002 192.168.16.135:7003 192.168.16.135:7004 192.168.16.135:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
weekend111:7003
weekend110:7000
weekend111:7004
Adding replica weekend110:7001 to weekend111:7003
Adding replica weekend111:7005 to weekend110:7000
Adding replica weekend110:7002 to weekend111:7004
M: 22c830989edd71c241c75a391654e5b3be2935c3 weekend110:7000
slots:5461-10922 (5462 slots) master
S: 64f2ed6a063c66ec765fdcbc08044b832883e227 weekend110:7001
replicates 597b1640d1e44e2cea4dd9a8f39724b780511017
S: 1c013c31ff607aaee841f49637168ce721cd706b weekend110:7002
replicates d264462956c37b9c6b5a7da9734ace1635c1a04f
M: 597b1640d1e44e2cea4dd9a8f39724b780511017 weekend111:7003
slots:0-5460 (5461 slots) master
M: d264462956c37b9c6b5a7da9734ace1635c1a04f weekend111:7004
slots:10923-16383 (5461 slots) master
S: fcd57bc490898e5e1b9a91a140a237d561cf0731 weekend111:7005
replicates 22c830989edd71c241c75a391654e5b3be2935c3
Can I set the above configuration? (type 'yes' to accept): yes
/usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/client.rb:121:in `call': ERR Slot 10846 is already busy (Redis::CommandError)
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis.rb:2705:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis.rb:58:in `synchronize'
from /usr/lib/ruby/1.8/monitor.rb:242:in `mon_synchronize'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis.rb:58:in `synchronize'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis.rb:2704:in `method_missing'
from /usr/local/bin/redis-trib.rb:212:in `flush_node_config'
from /usr/local/bin/redis-trib.rb:776:in `flush_nodes_config'
from /usr/local/bin/redis-trib.rb:775:in `each'
from /usr/local/bin/redis-trib.rb:775:in `flush_nodes_config'
from /usr/local/bin/redis-trib.rb:1296:in `create_cluster_cmd'
from /usr/local/bin/redis-trib.rb:1701:in `send'
from /usr/local/bin/redis-trib.rb:1701
经检查,这是由于上一次配置集群失败时留下的配置信息导致的。 只要把redis.conf中定义的 cluster-config-file 所在的文件删除,重新启动redis-server及运行redis-trib即可。 可以find下
2、
[zzq@weekend110 redis-3.2.6]$ redis-trib.rb create --replicas 1 192.168.16.130:7000 192.168.16.130:7001 192.168.16.130:7002 192.168.16.135:7003 192.168.16.135:7004 192.168.16.135:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
weekend111:7003
weekend110:7000
weekend111:7004
Adding replica weekend110:7001 to weekend111:7003
Adding replica weekend111:7005 to weekend110:7000
Adding replica weekend110:7002 to weekend111:7004
M: 532bb37455bdd503f324a92d762d85b8bc9c4054 weekend110:7000
slots:5461-10922 (5462 slots) master
S: 42dde7b783a176af6918346f3ba837467d6ab2d9 weekend110:7001
replicates aa57bb4c105d0a679a4ebf4d73ad32a18d44f90d
S: 1c013c31ff607aaee841f49637168ce721cd706b weekend110:7002
replicates 8cb6e618a0763ab4c0e497ba946d721bdc397bbb
M: aa57bb4c105d0a679a4ebf4d73ad32a18d44f90d weekend111:7003
slots:0-5460 (5461 slots) master
M: 8cb6e618a0763ab4c0e497ba946d721bdc397bbb weekend111:7004
slots:10923-16383 (5461 slots) master
S: 9f4e1ea2c42d84e6c49c60d7a9f99808e911127e weekend111:7005
replicates 532bb37455bdd503f324a92d762d85b8bc9c4054
Can I set the above configuration? (type 'yes' to accept): yes
/usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/connection/ruby.rb:111:in `_write_to_socket': Connection timed out (Redis::TimeoutError)
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/connection/ruby.rb:131:in `write'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/connection/ruby.rb:130:in `loop'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/connection/ruby.rb:130:in `write'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/connection/ruby.rb:374:in `write'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/client.rb:271:in `write'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/client.rb:250:in `io'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/client.rb:269:in `write'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/client.rb:228:in `process'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/client.rb:222:in `each'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/client.rb:222:in `process'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/client.rb:367:in `ensure_connected'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/client.rb:221:in `process'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/client.rb:306:in `logging'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/client.rb:220:in `process'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis/client.rb:120:in `call'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis.rb:2705:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis.rb:58:in `synchronize'
from /usr/lib/ruby/1.8/monitor.rb:242:in `mon_synchronize'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis.rb:58:in `synchronize'
from /usr/lib/ruby/gems/1.8/gems/redis-3.3.2/lib/redis.rb:2704:in `method_missing'
from /usr/local/bin/redis-trib.rb:212:in `flush_node_config'
from /usr/local/bin/redis-trib.rb:776:in `flush_nodes_config'
from /usr/local/bin/redis-trib.rb:775:in `each'
from /usr/local/bin/redis-trib.rb:775:in `flush_nodes_config'
from /usr/local/bin/redis-trib.rb:1296:in `create_cluster_cmd'
from /usr/local/bin/redis-trib.rb:1701:in `send'
from /usr/local/bin/redis-trib.rb:1701
gem版本问题,安装的时候redis用3.0.0的gem就好了
[zzq@weekend110 ~]$ gem list
*** LOCAL GEMS ***
redis (3.3.2)
[zzq@weekend110 ~]$ sudo gem uninstall redis --version 3.3.2
[sudo] password for zzq:
Successfully uninstalled redis-3.3.2
[zzq@weekend110 ~]$ sudo gem install redis --version 3.0.0
Successfully installed redis-3.0.0
1 gem installed
Installing ri documentation for redis-3.0.0...
Installing RDoc documentation for redis-3.0.0...
[zzq@weekend110 ~]$ gem list
*** LOCAL GEMS ***
redis (3.0.0)
3、
[zzq@weekend110 redis-3.2.6]$ redis-trib.rb create --replicas 1 weekend110:7000 weekend110:7001 weekend110:7002 weekend111:7003 weekend111:7004 weekend111:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
weekend111:7003
weekend110:7000
weekend111:7004
Adding replica weekend110:7001 to weekend111:7003
Adding replica weekend111:7005 to weekend110:7000
Adding replica weekend110:7002 to weekend111:7004
M: dddc7343b7d1e61c442450c0b37b86404966d4b5 weekend110:7000
slots:5461-10922 (5462 slots) master
S: a1eaee021a8a03bb29e34c2fbc2620073dc36e0e weekend110:7001
replicates 7b6d0b86f4d7639cfa69e3cc394a98934c9365c1
S: 402ad379b0c7bd1b72c63ecc2dd30f43a10d824d weekend110:7002
replicates 0c79c8e143f715b32a2a25539810c8beb79c0252
M: 7b6d0b86f4d7639cfa69e3cc394a98934c9365c1 weekend111:7003
slots:0-5460 (5461 slots) master
M: 0c79c8e143f715b32a2a25539810c8beb79c0252 weekend111:7004
slots:10923-16383 (5461 slots) master
S: 4fc9ad1d01615c1552b004baf728e0320adbe651 weekend111:7005
replicates dddc7343b7d1e61c442450c0b37b86404966d4b5
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
/usr/lib/ruby/gems/1.8/gems/redis-3.0.0/lib/redis/client.rb:79:in `call': ERR Invalid node address specified: weekend110:7000 (Redis::CommandError)
from /usr/lib/ruby/gems/1.8/gems/redis-3.0.0/lib/redis.rb:2190:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/redis-3.0.0/lib/redis.rb:36:in `synchronize'
from /usr/lib/ruby/1.8/monitor.rb:242:in `mon_synchronize'
from /usr/lib/ruby/gems/1.8/gems/redis-3.0.0/lib/redis.rb:36:in `synchronize'
from /usr/lib/ruby/gems/1.8/gems/redis-3.0.0/lib/redis.rb:2189:in `method_missing'
from /usr/local/bin/redis-trib.rb:811:in `join_cluster'
from /usr/local/bin/redis-trib.rb:809:in `each'
from /usr/local/bin/redis-trib.rb:809:in `join_cluster'
from /usr/local/bin/redis-trib.rb:1301:in `create_cluster_cmd'
from /usr/local/bin/redis-trib.rb:1701:in `send'
from /usr/local/bin/redis-trib.rb:1701
这里必须用ip地址:redis-trib.rb create --replicas 1 192.168.16.130:7000 192.168.16.130:7001 192.168.16.130:7002 192.168.16.135:7003 192.168.16.135:7004 192.168.16.135:7005
4、
[zzq@weekend110 redis_cluster]$ redis-trib.rb create --replicas 1 192.168.16.130:7000 192.168.16.130:7001 192.168.16.130:7002 192.168.16.135:7003 192.168.16.135:7004 192.168.16.135:7005
>>> Creating cluster
[ERR] Node 192.168.16.130:7000 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.
这是你以前就创建过集群再创建,把这三个文件删除掉appendonly.aof dump.rdb nodes.conf
1)将每个节点下aof、rdb、nodes.conf本地备份文件删除;
2)172.168.63.201:7001> flushdb #清空当前数据库(可省略)
3)之后再执行脚本,成功执行;
java api操作redis报错:
Exception in thread "main" redis.clients.jedis.exceptions.JedisMovedDataException: MOVED 866 192.168.16.135:7003
at redis.clients.jedis.Protocol.processError(Protocol.java:108)
at redis.clients.jedis.Protocol.process(Protocol.java:151)
at redis.clients.jedis.Protocol.read(Protocol.java:205)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:297)
at redis.clients.jedis.Connection.getAll(Connection.java:267)
at redis.clients.jedis.Connection.getAll(Connection.java:259)
at redis.clients.jedis.Pipeline.sync(Pipeline.java:99)
at com.zit.test.RedisJava.findByKey(RedisJava.java:43)
at com.zit.test.RedisJava.main(RedisJava.java:50)
redis集群不能用Jedis操作,用JedisCluster