欢迎阅读!

潇湘夜雨

当前位置: 主页 > 数据库 >

redis cluster集群配置和运维(2)

时间:2017-06-09 17:17来源:潇湘夜雨 作者:华嵩阳 点击:
from /usr/local/redis/bin/redis-trib.rb:1701:in `send from /usr/local/redis/bin/redis-trib.rb:1701 错误原因:redis cluster集群的端口和nodes_config的配置文件的名称不能有相同的。
from /usr/local/redis/bin/redis-trib.rb:1701:in `send'
from /usr/local/redis/bin/redis-trib.rb:1701
 
错误原因:redis cluster集群的端口和nodes_config的配置文件的名称不能有相同的。改成如下格式
[root@localhost redis]# ls -lh|grep node
-rw-r--r-- 1 root root 746 6月   7 17:23 nodes-5379.conf
-rw-r--r-- 1 root root 746 6月   7 17:23 nodes-5380.conf
-rw-r--r-- 1 root root 746 6月   7 17:23 nodes5381.conf
 
 
[root@localhost ~]# /usr/local/redis/bin/redis-trib.rb create --replicas 1 192.168.198.128:6379 192.168.198.128:6380 192.168.198.128:6381 192.168.198.130:5379 192.168.198.130:5380 192.168.198.130:5381
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.198.130:5379
192.168.198.128:6379
192.168.198.130:5380
Adding replica 192.168.198.128:6380 to 192.168.198.130:5379
Adding replica 192.168.198.130:5381 to 192.168.198.128:6379
Adding replica 192.168.198.128:6381 to 192.168.198.130:5380
M: fa965f43ba8b1cfa07c63cf53ab6163a1cf37ad9 192.168.198.128:6379
  slots:5461-10922 (5462 slots) master
S: 4eda271e009e929e47573efdce97f60b2ae127a3 192.168.198.128:6380
  replicates 67ee6b3806309ddfa44b95d027d8421e5b7bf633
S: 64f4db57670eb12937aff6b24c7d074417f3a961 192.168.198.128:6381
  replicates 5a997b03a01a86faba17be3147ee1c5ec0fe9291
M: 67ee6b3806309ddfa44b95d027d8421e5b7bf633 192.168.198.130:5379
  slots:0-5460 (5461 slots) master
M: 5a997b03a01a86faba17be3147ee1c5ec0fe9291 192.168.198.130:5380
  slots:10923-16383 (5461 slots) master
S: aebbe9a7b8a5f25533aa6f6e58b775e093e8feb7 192.168.198.130:5381
  replicates fa965f43ba8b1cfa07c63cf53ab6163a1cf37ad9
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.198.128:6379)
M: fa965f43ba8b1cfa07c63cf53ab6163a1cf37ad9 192.168.198.128:6379
  slots:5461-5906,5908-10922 (5461 slots) master
  1 additional replica(s)
S: 64f4db57670eb12937aff6b24c7d074417f3a961 192.168.198.128:6381
  slots: (0 slots) slave
  replicates 5a997b03a01a86faba17be3147ee1c5ec0fe9291
M: 4eda271e009e929e47573efdce97f60b2ae127a3 192.168.198.128:6380
  slots:5907 (1 slots) master
  0 additional replica(s)
S: aebbe9a7b8a5f25533aa6f6e58b775e093e8feb7 192.168.198.130:5381
  slots: (0 slots) slave
  replicates fa965f43ba8b1cfa07c63cf53ab6163a1cf37ad9
M: 67ee6b3806309ddfa44b95d027d8421e5b7bf633 192.168.198.130:5379
  slots:0-5460 (5461 slots) master
  0 additional replica(s)
M: 5a997b03a01a86faba17be3147ee1c5ec0fe9291 192.168.198.130:5380
  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.
 
 
4、检查节点的状态
 
[root@localhost redis]# redis-trib.rb check 192.168.198.128:6379
>>> Performing Cluster Check (using node 192.168.198.128:6379)
M: 659b9e99cfe7cfe198d10231bc4526a34c316cdc 192.168.198.128:6379
  slots:5461-10922 (5462 slots) master
  1 additional replica(s)
M: 14cc31f74c23fa6b237334b11d984989c6d8cc4e 192.168.198.130:5380
  slots:10923-16383 (5461 slots) master
  1 additional replica(s)
S: e97d65ce427e00b4ff89014dcdb05cfdad9f8152 192.168.198.128:6380
  slots: (0 slots) slave
  replicates f4c656b100cc40650cbcbb266cb5523020fb4b38
S: 399cbff5edff7258081fd73f98a1cb2857cb9824 192.168.198.128:6381
  slots: (0 slots) slave
  replicates 14cc31f74c23fa6b237334b11d984989c6d8cc4e
S: 8e2ad457f09186549b714c2260742773de1db658 192.168.198.130:5381
  slots: (0 slots) slave
  replicates 659b9e99cfe7cfe198d10231bc4526a34c316cdc
M: f4c656b100cc40650cbcbb266cb5523020fb4b38 192.168.198.130:5379
  slots:0-5460 (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.
 
 
4、集群测试
 
用redis-cli -c -h -p命令登录 
-c是以集群方式登录; 
-h后跟主机号 ;
-p后跟端口号。
绑定了127.0.0.1则可以省略-h参数。不加-c则客户端不自动切换。
 
[root@localhost ~]# redis-cli -c #登录集群节点要加-c参数
 
127.0.0.1:6379> cluster info #查看当前集群状态
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:4
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_sent:622
cluster_stats_messages_received:628
127.0.0.1:6379> set a1 6379 #创建键值
OK
127.0.0.1:6379> KEYS *
1) "a1"
 
 
登录另一节点
[root@localhost ~]# redis-cli -h 192.168.198.130 -p 5381 -c
 
192.168.198.130:5381> KEYS *
1) "a1"
192.168.198.130:5381> get a1
-> Redirected to slot [7785] located at 192.168.198.128:6379 #会自动重定向到存放数据的节点
"6379"
192.168.198.128:6379> CLUSTER info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:4
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_sent:1098
cluster_stats_messages_received:1104
 
 
注意:6个节点的集群,一般只能允许一个主\从节点故障,如果一主一从同时故障集群将停止工作,主节点故障个数过半也会停止工作。
 
 
二、redis cluster管理
 
1、添加新master节点
 
(1)添加一个master节点:创建一个空节点(empty node),然后将某些slot移动到这个空节点上,这个过程目前需要人工干预
 
[root@localhost redis]# redis-server redis4.conf  #启动新节点
 
(2):加入空节点到集群
add-node  将一个节点添加到集群里面, 第一个是新节点ip:port, 第二个是任意一个已存在节点ip:port
 
redis-trib.rb add-node 192.168.198.128:6382 192.168.198.128:6379
 
>>> Adding node 192.168.198.128:6382 to cluster 192.168.198.128:6379
>>> Performing Cluster Check (using node 192.168.198.128:6379)
S: 659b9e99cfe7cfe198d10231bc4526a34c316cdc 192.168.198.128:6379
  slots: (0 slots) slave
  replicates 8e2ad457f09186549b714c2260742773de1db658
S: e97d65ce427e00b4ff89014dcdb05cfdad9f8152 192.168.198.128:6380
  slots: (0 slots) slave
  replicates f4c656b100cc40650cbcbb266cb5523020fb4b38
M: 8e2ad457f09186549b714c2260742773de1db658 192.168.198.130:5381
  slots:5461-10922 (5462 slots) master
  1 additional replica(s)
M: 14cc31f74c23fa6b237334b11d984989c6d8cc4e 192.168.198.130:5380
  slots:10923-16383 (5461 slots) master
  1 additional replica(s)
S: 399cbff5edff7258081fd73f98a1cb2857cb9824 192.168.198.128:6381
  slots: (0 slots) slave
  replicates 14cc31f74c23fa6b237334b11d984989c6d8cc4e
M: f4c656b100cc40650cbcbb266cb5523020fb4b38 192.168.198.130:5379
  slots:0-5460 (5461 slots) master
  1 additional replica(s) (责任编辑:liangzh)
织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
推荐内容