redis集群搭建及问题的决方法(一)

一、集群搭建主要配置如下:

P61 bind 127.0.0.1//默认ip为127.0.0.1改为其他节点机器可访问 的ip
注释掉bind;可以监听连接当前服务的所有-h 后的ip;例如;绑定了 127.0.0.1,但是登录时使用-h 10.9.17.153
P80 protected-mode no //yes修改为no
P84 port 8000 //端口8000-8005
P128 daemonize yes //后台运行
P150 pidfile /var/run/redis_8000.pid
P163 logfile 8000/redis.log
P237 dump dump8000.rdb
P593 appendonly yes
P597 appendfilename “appendonly.aof”
P721 cluster-enabled yes
P729 cluster-config-file nodes_8000.conf
P735 cluster-node-timeout 15000 //请求超时 默认15秒,可 自行设置

二、搭建完成后依次启动各个实例

redis-server 8000/redis.conf
redis-server 8001/redis.conf
redis-server 8002/redis.conf
redis-server 8003/redis.conf
redis-server 8004/redis.conf
redis-server 8005/redis.conf

三、检查启动结果:

[root@cenos01 redis-3.2.11]# ps -ef|grep 800
root 19360 1 0 23:19 ? 00:00:01 redis-server *:8001 [cluster]
root 19364 1 0 23:19 ? 00:00:01 redis-server *:8002 [cluster]
root 19368 1 0 23:19 ? 00:00:01 redis-server *:8003 [cluster]
root 19372 1 0 23:19 ? 00:00:01 redis-server *:8004 [cluster]
root 19378 1 0 23:19 ? 00:00:01 redis-server *:8005 [cluster]
root 19433 1 0 23:30 ? 00:00:01 redis-server *:8000 [cluster]

四、以上启动后并不是一个真正的集群,以下开始创建集群

在redis的根目录下的src目录下执行***/redis-3.2.11/src,报错信息如下
[root@cenos01 src]# ./redis-trib.rb create 10.211.55.5:8000 10.211.55.5:8001 10.211.55.5:8002

Creating cluster
Performing hash slots allocation on 3 nodes…
Using 3 masters:
10.211.55.5:8000
10.211.55.5:8001
10.211.55.5:8002
M: 8ce851252f32fcab268e77d3b3ed976d57d2f498 10.211.55.5:8000
slots:0-5460 (5461 slots) master
M: 6f4a31fc322725fc4ed453a588f344fed4f261bf 10.211.55.5:8001
slots:5461-10922 (5462 slots) master
M: da7d09090520a0e6287ea12fe7f48225d6665f68 10.211.55.5:8002
slots:10923-16383 (5461 slots) master
Can I set the above configuration? (type ‘yes’ to accept): yes
/usr/local/lib/ruby/gems/2.3.0/gems/redis-4.0.2/lib/redis/client.rb:119:in call': ERR Slot 1180 is already busy (Redis::CommandError) from /usr/local/lib/ruby/gems/2.3.0/gems/redis-4.0.2/lib/redis.rb:2854:inblock in method_missing’
from /usr/local/lib/ruby/gems/2.3.0/gems/redis-4.0.2/lib/redis.rb:45:in block in synchronize' from /usr/local/lib/ruby/2.3.0/monitor.rb:214:inmon_synchronize’
from /usr/local/lib/ruby/gems/2.3.0/gems/redis-4.0.2/lib/redis.rb:45:in synchronize' from /usr/local/lib/ruby/gems/2.3.0/gems/redis-4.0.2/lib/redis.rb:2853:inmethod_missing’
from ./redis-trib.rb:212:in flush_node_config' from ./redis-trib.rb:776:inblock in flush_nodes_config’
from ./redis-trib.rb:775:in each' from ./redis-trib.rb:775:inflush_nodes_config’
from ./redis-trib.rb:1296:in create_cluster_cmd' from ./redis-trib.rb:1701:in

五、针对以上问题的解决方法:

所有redis服务器都执行以下命令:

$redis-cli -p 端口号
$flushall
$cluster reset soft
$exit

六、解决后再次创建,就成功了

[root@cenos01 src]# ./redis-trib.rb create 10.211.55.5:8000 10.211.55.5:8001 10.211.55.5:8002

Creating cluster
Performing hash slots allocation on 3 nodes…
Using 3 masters:
10.211.55.5:8000
10.211.55.5:8001
10.211.55.5:8002
M: 8ce851252f32fcab268e77d3b3ed976d57d2f498 10.211.55.5:8000
slots:0-5460 (5461 slots) master
M: 6f4a31fc322725fc4ed453a588f344fed4f261bf 10.211.55.5:8001
slots:5461-10922 (5462 slots) master
M: da7d09090520a0e6287ea12fe7f48225d6665f68 10.211.55.5:8002
slots:10923-16383 (5461 slots) master
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.211.55.5:8000)
M: 8ce851252f32fcab268e77d3b3ed976d57d2f498 10.211.55.5:8000
slots:0-5460 (5461 slots) master
0 additional replica(s)
M: 6f4a31fc322725fc4ed453a588f344fed4f261bf 10.211.55.5:8001
slots:5461-10922 (5462 slots) master
0 additional replica(s)
M: da7d09090520a0e6287ea12fe7f48225d6665f68 10.211.55.5:8002
slots:10923-16383 (5461 slots) master
0 additional replica(s)
[OK] All nodes agree about slots configuration.

Check for open slots…
Check slots coverage…
[OK] All 16384 slots covered.

**

七、查看集群状态

**
[root@cenos01 src]# redis-cli -c -p 8000
127.0.0.1:8000> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:3
cluster_size:3
cluster_current_epoch:3
cluster_my_epoch:1
cluster_stats_messages_sent:2059
cluster_stats_messages_received:2059

cluster_current_epoch:6 代表当前集群的最新逻辑计算时间,数字 越大,表示操作或者配置越新,整个集群的这个值是保持一致的
cluster_my_epoch:1代表当前节点的逻辑计算时间

八、查看槽道分配情况和集群节点信息

127.0.0.1:8000> cluster nodes
8ce851252f32fcab268e77d3b3ed976d57d2f498 10.211.55.5:8000 myself,master - 0 0 1 connected 0-5460
6f4a31fc322725fc4ed453a588f344fed4f261bf 10.211.55.5:8001 master - 0 1538582282356 2 connected 5461-10922
da7d09090520a0e6287ea12fe7f48225d6665f68 10.211.55.5:8002 master - 0 1538582283359 3 connected 10923-16383

以上只挂载了主节点,关于从节点的挂载步骤和方法见本人的下一篇博客文章。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值