[ERR] Sorry, can't connect to node 127.0.0.1:6379

记录下安装redis集群的问题,避免以后再瞎找解决方案

错误

创建redis集群时报错

[root@Prd- redis]#  ./redis-trib.rb create --replicas 1 10.240.47.190:7000 10.240.47.190:7001 10.240.47.190:7002 10.240.47.190:7003 10.240.47.190:7004 10.240.47.190:7005
>>> Creating cluster
[ERR] Sorry, can't connect to node 10.240.47.190:7000

原因

原因是redis-trib.rb create执行时调用ruby的执行没能连上redis服务。

仔细分析,连不上redis服务会有哪几类原因:

  • 网络原因:防火墙之类的
  • redis服务本身启动失败,服务不存在
  • redis启动成功了但还是连不上,那可能是权限问题,比如redis有个密码
  • redis启动成功,仍然连不上,连接工具的问题?比如ruby版本啥的或者驱动?
  • 。。。

解决

照着这几个思路去查吧,见鬼打鬼,见坑填坑,坚韧不拔!

防火墙问题

查看防火墙状态  /etc/init.d/iptables status

  临时关闭防火墙 /etc/init.d/iptables stop

  永久关闭防火墙 chkconfig --level 2345 iptables off 
  或者 chkconfig iptables off 

redis服务本身问题

配置:
(1)bind:bind本机ip,或者多几个ip。而不是127.0.0.1、localhost
(2)protected mode 设为no
(3)旧版本redis 把默认的redis密码注释 # requirepass xxxxxx (个人是新版本4.x无此问题也推荐用此版本)

ruby工具问题

直接尝试安装最新版就行

yum install ruby
yum install rubygems

集群创建工具问题

最后一步有需要执行个命令:

 ./redis-trib.rb create --replicas 1 10.240.47.190:7000 10.240.47.190:7001 10.240.47.190:7002 10.240.47.190:7003 10.240.47.190:7004 10.240.47.190:7005

那么可能出问题,驱动上,不知是否记得需要个gem驱动

安装redis管理工具

  • 下载ruby环境下Redis的驱动,考虑到兼容性,这里下载的是3.2.2版本:https://rubygems.org/gems/redis/versions/3.2.2

注意:下载在页面右下角相关连接一项中

  • redis-3.2.2.gem上传至服务器进行安装,这里放到redis-cluster中
  • 安装
[root@mini2 bin]# gem install redis-3.2.2.gem
Successfully installed redis-3.2.2
Parsing documentation for redis-3.2.2
Installing ri documentation for redis-3.2.2
1 gem installed

然后执行gem install redis

[root@Prd- data]# gem install redis
Successfully installed redis-4.1.3
Parsing documentation for redis-4.1.3
Done installing documentation for redis after 1 seconds
1 gem installed

安装成功

来展示下解决这个问题安装成功后的结果。(个人是因为gem install redis命令没执行。。。)

[root@Prd- redis]# cd src
[root@Prd- src]#  ./redis-trib.rb create --replicas 1 10.240.47.190:7000 10.240.47.190:7001 10.240.47.190:7002 10.240.47.190:7003 10.240.47.190:7004 10.240.47.190:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
10.240.47.190:7000
10.240.47.190:7001
10.240.47.190:7002
Adding replica 10.240.47.190:7003 to 10.240.47.190:7000
Adding replica 10.240.47.190:7004 to 10.240.47.190:7001
Adding replica 10.240.47.190:7005 to 10.240.47.190:7002
M: b017bcf537c29d97e5cbd43dda146500c5044542 10.240.47.190:7000
   slots:0-5460 (5461 slots) master
M: 64b621b6822830c18d02c4e5c6f1cc028f147f08 10.240.47.190:7001
   slots:5461-10922 (5462 slots) master
M: 462bc242c534b9b735b4f0b176a4df0b41203893 10.240.47.190:7002
   slots:10923-16383 (5461 slots) master
S: ec561eca4b1a97d53b0e64fe6bb8d6ba711e008b 10.240.47.190:7003
   replicates b017bcf537c29d97e5cbd43dda146500c5044542
S: d04fe737e348e23d9b11d94b65ec00fdd4ee01f2 10.240.47.190:7004
   replicates 64b621b6822830c18d02c4e5c6f1cc028f147f08
S: 1706c08144813aade2450ff9288e66c4164ac205 10.240.47.190:7005
   replicates 462bc242c534b9b735b4f0b176a4df0b41203893
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 10.240.47.190:7000)
M: b017bcf537c29d97e5cbd43dda146500c5044542 10.240.47.190:7000
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: ec561eca4b1a97d53b0e64fe6bb8d6ba711e008b 10.240.47.190:7003
   slots: (0 slots) slave
   replicates b017bcf537c29d97e5cbd43dda146500c5044542
S: 1706c08144813aade2450ff9288e66c4164ac205 10.240.47.190:7005
   slots: (0 slots) slave
   replicates 462bc242c534b9b735b4f0b176a4df0b41203893
S: d04fe737e348e23d9b11d94b65ec00fdd4ee01f2 10.240.47.190:7004
   slots: (0 slots) slave
   replicates 64b621b6822830c18d02c4e5c6f1cc028f147f08
M: 64b621b6822830c18d02c4e5c6f1cc028f147f08 10.240.47.190:7001
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
M: 462bc242c534b9b735b4f0b176a4df0b41203893 10.240.47.190:7002
   slots:10923-16383 (5461 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.
[root@Prd- src]# redis-cli -h 10.240.47.190 -p 7003 -c
10.240.47.190:7003> set a a
-> Redirected to slot [15495] located at 10.240.47.190:7002
OK
10.240.47.190:7002> get a
"a"
10.240.47.190:7002> 

redis集群安装参考文档

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值