redis集群的创建安装与配置,以及维护

一、redis集群配置

port 7000

cluster-enabled yes

cluster-config-file nodes.conf

cluster-node-timeout 5000

appendonly yes

二、安装ruby(ruby可以充当redis客户端的角色)

yum -y install ruby ruby-devel rubygems rpm-build

gem install redis

三、创建redis集群

1、依次启动node1:7000/7001, node2:7000/7001, node3:7000/7001

[root@node1 7000]# ../src/redis-server redis.conf

2、# 必须使用IP地址不能使用主机名

src/redis-trib.rb create --replicas 1 192.168.199.238:7000 192.168.199.238:7001 \

192.168.199.134:7000 192.168.199.134:7001 192.168.199.237:7000 192.168.199.237:7001

四、启动redis集群

1、 检查

[root@node1 redis]# src/redis-cli -c -h 192.168.0.31 -p 7000 cluster nodes

ebda3f1dad0da2996df119182eab46ed7abedcd9 192.168.0.35:7001 slave 490354a9f25120ee5ae10acc681dc412864ecb03 0 1522055848174 6 connected

490354a9f25120ee5ae10acc681dc412864ecb03 192.168.0.35:7000 master - 0 1522055850183 5 connected 10923-16383

d1a11bf4cc508a11f71d9a40e0aca6c7e491a3c4 192.168.0.33:7000 master - 0 1522055847170 3 connected 5461-10922

c9b21659527f7ce2f234102c4d6b6361e270e5a8 192.168.0.31:7001 slave d1a11bf4cc508a11f71d9a40e0aca6c7e491a3c4 0 1522055849178 3 connected

34604603c5b970b98f0d8351e8811f2688a9c83e 192.168.0.31:7000 myself,master - 0 0 1 connected 0-5460

22c867aa1f70b4cc0ea5c3ca011dd1a2df7da66e 192.168.0.33:7001 slave 34604603c5b970b98f0d8351e8811f2688a9c83e 0 1522055845161 4 connected

2、测试

[root@node1 redis]# src/redis-cli -c -h 192.168.0.31 -p 7000

五、集群扩容

1、增加主节点

# 新节点:192.168.0.31:7002

# 老节点:192.168.0.31:7000

src/redis-trib.rb add-node 192.168.0.31:7002 192.168.0.31:7000

2、增加从节点

# 新节点:192.168.0.31:7002

# 老节点:192.168.0.31:7000

src/redis-trib.rb add-node --slave --master-id 5da7b4b37f4e14638d9558e66166c042b752d417 192.168.0.31:7002 192.168.0.31:7000

六、redis   重新分配redis资源即重新分配槽位

# 老节点:192.168.0.31:7000

src/redis-trib.rb reshard 192.168.0.31:7000

How many slots do you want to move (from 1 to 16384)? 1000 //设置slot数1000 

What is the receiving node ID?  03ccad2ba5dd1e062464bc7590400441fafb63f2 //新节点node id 

Please enter all the source node IDs. 

 Type 'all' to use all the nodes as source nodes for the hash slots. 

 Type 'done' once you entered all the source nodes IDs.  

Source node #1:all //表示全部节点重新洗牌 

Do you want to proceed with the proposed reshard plan (yes/no)?  yes //确认重新分

七、redis集群缩容

1、删除从节点

# 老节点:192.168.0.31:7001

src/redis-trib.rb del-node 192.168.0.31:7001 '9c240333476469e8e2c8e80b089c48f389827265' 

2、删除主节点

1. 删除从节点(注意:需要将从节点转移到其他主节点)

49ed626134079dc301f586ff4edb1670a3a42a8c 被删除主节点ID

192.168.0.31:7000> cluster replicate 49ed626134079dc301f586ff4edb1670a3a42a8c

3. 取消槽位

src/redis-trib.rb reshard 192.168.0.31:7000 // 重新分配槽位

How many slots do you want to move (from 1 to 16384)? 1000 // 被删除master的所有slot数量 

What is the receiving node ID? 5d8ef5a7fbd72ac586bef04fa6de8a88c0671052 // 接收slot的master 

Please enter all the source node IDs. 

 Type 'all' to use all the nodes as source nodes for the hash slots. 

 Type 'done' once you entered all the source nodes IDs. 

Source node #1:49ed626134079dc301f586ff4edb1670a3a42a8c  //被删除master的node-id 

Source node #2:done  

Do you want to proceed with the proposed reshard plan (yes/no)? yes // 取消slot后,reshard

3. 删除主节点

src/redis-trib.rb del-node 192.168.0.31:7000 '49ed626134079dc301f586ff4edb1670a3a42a8c'

相关推荐

  1. redis创建安装配置以及维护

    2024-05-04 06:38:02       31 阅读
  2. Kafka安装配置(二)

    2024-05-04 06:38:02       53 阅读
  3. Kafka安装配置

    2024-05-04 06:38:02       42 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-04 06:38:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-04 06:38:02       101 阅读
  3. 在Django里面运行非项目文件

    2024-05-04 06:38:02       82 阅读
  4. Python语言-面向对象

    2024-05-04 06:38:02       91 阅读

热门阅读

  1. MySQL 环境Redis 环境Minio 环境XXL-JOB 环境 的区别

    2024-05-04 06:38:02       22 阅读
  2. MYSQL三个日志

    2024-05-04 06:38:02       33 阅读
  3. Python高级编程

    2024-05-04 06:38:02       30 阅读
  4. IP协议的TTL解析(定义、执行、用途)

    2024-05-04 06:38:02       26 阅读
  5. js请求封装ajax、统一响应

    2024-05-04 06:38:02       33 阅读
  6. mac 安装anaconda

    2024-05-04 06:38:02       29 阅读
  7. 嵌入式物联网系统软硬件基础知识大全(2)

    2024-05-04 06:38:02       33 阅读
  8. 【004_音频开发_基础篇_ALSA插件使用】

    2024-05-04 06:38:02       34 阅读