linux卸载redis集群,Redis 集群节点操作

当前Redis Cluster状态:

$ pwd

/home/zxm/BD/redis-cluster

$ ls -l

总用量 32

drwxrwxr-x. 2 zxm zxm 4096 8月 24 20:15 7000

drwxrwxr-x. 2 zxm zxm 4096 8月 24 20:22 7001

drwxrwxr-x. 2 zxm zxm 4096 8月 24 17:32 7002

drwxrwxr-x. 2 zxm zxm 4096 8月 24 20:36 7003

drwxrwxr-x. 2 zxm zxm 4096 8月 24 17:32 7004

drwxrwxr-x. 2 zxm zxm 4096 8月 24 20:23 7005

集群中各个节点状态:

$ ./redis-trib.rb check 192.168.174.3:7000

>>> Performing Cluster Check (using node 192.168.174.3:7000)

M: 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c 192.168.174.3:7000

slots:0-5460 (5461 slots) master

1 additional replica(s)

M: ca33b3d7a60f8df7b74473f86c11f84df609fa45 192.168.174.3:7002

slots:10923-16383 (5461 slots) master

1 additional replica(s)

S: 8f26d8a386853e338e7176c33e66166b5f835175 192.168.174.3:7003

slots: (0 slots) slave

replicates 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c

S: 46f81794cfcf6fbf10fcf18c44f137f446f28be9 192.168.174.3:7005

slots: (0 slots) slave

replicates ca33b3d7a60f8df7b74473f86c11f84df609fa45

M: a2e08eda093f5b962881f309b8a3b9d5961e6aa8 192.168.174.3:7001

slots:5461-10922 (5462 slots) master

1 additional replica(s)

S: 43d98665d41381c89d45c6f69bf8a2622b7b9dc3 192.168.174.3:7004

slots: (0 slots) slave

replicates a2e08eda093f5b962881f309b8a3b9d5961e6aa8

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

Redis集群 Resharding

resharding步骤:

1) 使用命令开启reshard命令

./redis-trib.rb reshard host:port

2) 指定需要重新reshard的slots个数

How many slots do you want to move (from 1 to 16384)? 1000

3) 指定需要接收的节点ID

What is the receiving node ID? 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c

4) 指定需要重新shard的节点,输入done开始reshard

Source node #1:ca33b3d7a60f8df7b74473f86c11f84df609fa45

Source node #2:done

具体操作流程如下:

$ ./redis-trib.rb reshard 192.168.174.3:7000

>>> Performing Cluster Check (using node 192.168.174.3:7000)

M: 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c 192.168.174.3:7000

slots:0-5460 (5461 slots) master

1 additional replica(s)

M: ca33b3d7a60f8df7b74473f86c11f84df609fa45 192.168.174.3:7002

slots:10923-16383 (5461 slots) master

1 additional replica(s)

S: 8f26d8a386853e338e7176c33e66166b5f835175 192.168.174.3:7003

slots: (0 slots) slave

replicates 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c

S: 46f81794cfcf6fbf10fcf18c44f137f446f28be9 192.168.174.3:7005

slots: (0 slots) slave

replicates ca33b3d7a60f8df7b74473f86c11f84df609fa45

M: a2e08eda093f5b962881f309b8a3b9d5961e6aa8 192.168.174.3:7001

slots:5461-10922 (5462 slots) master

1 additional replica(s)

S: 43d98665d41381c89d45c6f69bf8a2622b7b9dc3 192.168.174.3:7004

slots: (0 slots) slave

replicates a2e08eda093f5b962881f309b8a3b9d5961e6aa8

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

How many slots do you want to move (from 1 to 16384)? 1000

What is the receiving node ID? 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c

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:ca33b3d7a60f8df7b74473f86c11f84df609fa45

Source node #2:done

Ready to move 1000 slots.

Source nodes:

M: ca33b3d7a60f8df7b74473f86c11f84df609fa45 192.168.174.3:7002

slots:10923-16383 (5461 slots) master

1 additional replica(s)

Destination node:

M: 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c 192.168.174.3:7000

slots:0-5460 (5461 slots) master

1 additional replica(s)

Resharding plan:

Moving slot 10923 from ca33b3d7a60f8df7b74473f86c11f84df609fa45

... ...

Moving slot 11921 from ca33b3d7a60f8df7b74473f86c11f84df609fa45

Moving slot 11922 from ca33b3d7a60f8df7b74473f86c11f84df609fa45

Do you want to proceed with the proposed reshard plan (yes/no)?yes

Moving slot 10923 from 192.168.174.3:7002 to 192.168.174.3:7000:

Moving slot 10924 from 192.168.174.3:7002 to 192.168.174.3:7000:

... ...

Moving slot 11921 from 192.168.174.3:7002 to 192.168.174.3:7000:

Moving slot 11922 from 192.168.174.3:7002 to 192.168.174.3:7000:

重新sharding后集群中各个节点状态:

$ ./redis-trib.rb check 192.168.174.3:7000

>>> Performing Cluster Check (using node 192.168.174.3:7000)

M: 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c 192.168.174.3:7000

slots:0-5460,10923-11922 (6461 slots) master

1 additional replica(s)

M: ca33b3d7a60f8df7b74473f86c11f84df609fa45 192.168.174.3:7002

slots:11923-16383 (4461 slots) master

1 additional replica(s)

S: 8f26d8a386853e338e7176c33e66166b5f835175 192.168.174.3:7003

slots: (0 slots) slave

replicates 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c

S: 46f81794cfcf6fbf10fcf18c44f137f446f28be9 192.168.174.3:7005

slots: (0 slots) slave

replicates ca33b3d7a60f8df7b74473f86c11f84df609fa45

M: a2e08eda093f5b962881f309b8a3b9d5961e6aa8 192.168.174.3:7001

slots:5461-10922 (5462 slots) master

1 additional replica(s)

S: 43d98665d41381c89d45c6f69bf8a2622b7b9dc3 192.168.174.3:7004

slots: (0 slots) slave

replicates a2e08eda093f5b962881f309b8a3b9d5961e6aa8

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

新增节点

1) 添加节点

添加redis实例,端口为7006

$ cp -r 7005 7006

修改7006目录中redis-cluster.conf文件中的参数:

$ cat 7006/redis-cluster.conf

bind 192.168.174.3

port 7006

daemonize yes

logfile "/home/zxm/BD/redis-cluster/7006/redis.log"

cluster-enabled yes

cluster-config-file nodes.conf

cluster-node-timeout 5000

appendonly yes

启动redis实例节点

$cd 7006

$redis-server redis-cluster.conf

添加Salve节点

方式一:

1)将新的节点添加到集群中

$ ./redis-trib.rb add-node 192.168.174.3:7006 192.168.174.3:7000

>>> Adding node 192.168.174.3:7006 to cluster 192.168.174.3:7000

>>> Performing Cluster Check (using node 192.168.174.3:7000)

... ...

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

>>> Send CLUSTER MEET to node 192.168.174.3:7006 to make it join the cluster.

[OK] New node added correctly.

2) 进入redis命令行,并查看集群状态

$ redis-cli -c -h 192.168.174.3 -p 7006

192.168.174.3:7006> cluster nodes

... ...

fca935760ac28db5cbdc5396b5a326a85e4f8760 192.168.174.3:7006 myself,master - 0 0 0 connected

7f12512f46ce8e0bac2fffcb7ca05c9941d2864c 192.168.174.3:7000 master - 0 1472046744344 7 connected 0-5460 10923-11922

... ...

可以看到默认将新添加的节点作为master

3) 将新节点修改为7000节点的slave,并查看修改后的集群状态

192.168.174.3:7006> cluster replicate 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c

OK

192.168.174.3:7006> cluster nodes

... ...

fca935760ac28db5cbdc5396b5a326a85e4f8760 192.168.174.3:7006 myself,slave 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c 0 0 0 connected

7f12512f46ce8e0bac2fffcb7ca05c9941d2864c 192.168.174.3:7000 master - 0 1472047082185 7 connected 0-5460 10923-11922

... ...

方式二:

1) 将新节点直接作为7000节点的slave添加到集群中

$ ./redis-trib.rb add-node --slave --master-id 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c 192.168.174.3:7006 192.168.174.3:7000

>>> Adding node 192.168.174.3:7006 to cluster 192.168.174.3:7000

>>> Performing Cluster Check (using node 192.168.174.3:7000)

... ...

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

>>> Send CLUSTER MEET to node 192.168.174.3:7006 to make it join the cluster.

Waiting for the cluster to join.

>>> Configure node as replica of 192.168.174.3:7000.

[OK] New node added correctly.

2) 查看集群状态

$ ./redis-trib.rb check 192.168.174.3:7001

>>> Performing Cluster Check (using node 192.168.174.3:7001)

... ...

M: 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c 192.168.174.3:7000

slots:0-5460,10923-11922 (6461 slots) master

2 additional replica(s)

S: 1a0d5c686108182ab2ea7ca136c8e726d077171e 192.168.174.3:7006

slots: (0 slots) slave

replicates 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c

... ...

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

删除节点

删除7000节点,并将7000端口节点上的slots分配到7006上

1) 将7006节点作为master节点添加到集群中,并察看集群状态:

[zxm@node1 src]$ ./redis-trib.rb check 192.168.174.3:7001

>>> Performing Cluster Check (using node 192.168.174.3:7001)

... ...

M: d7a7e6e57827d94803a139f6f36425276c9e1019 192.168.174.3:7006

slots: (0 slots) master

0 additional replica(s)

M: 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c 192.168.174.3:7000

slots:0-5460,10923-11922 (6461 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.

2) 对集群进行reshard操作,将7000节点上的所有slots转移到7006节点上

[zxm@node1 src]$ ./redis-trib.rb reshard 192.168.174.3:7000

>>> Performing Cluster Check (using node 192.168.174.3:7000)

M: 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c 192.168.174.3:7000

slots:0-5460,10923-11922 (6461 slots) master

1 additional replica(s)

... ...

M: d7a7e6e57827d94803a139f6f36425276c9e1019 192.168.174.3:7006

slots: (0 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.

How many slots do you want to move (from 1 to 16384)? 6461

What is the receiving node ID? d7a7e6e57827d94803a139f6f36425276c9e1019

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:7f12512f46ce8e0bac2fffcb7ca05c9941d2864c

Source node #2:done

3) 查看集群状态

$ ./redis-trib.rb check 192.168.174.3:7001

>>> Performing Cluster Check (using node 192.168.174.3:7001)

... ...

M: d7a7e6e57827d94803a139f6f36425276c9e1019 192.168.174.3:7006

slots:0-5460,10923-11922 (6461 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) 删除7000节点

$ ./redis-trib.rb del-node 192.168.174.3:7000 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c

>>>Removing node 7f12512f46ce8e0bac2fffcb7ca05c9941d2864c from cluster 192.168.174.3:7000

>>>Sending CLUSTER FORGET messages to the cluster...

>>>SHUTDOWN the node.

⚠️删除master节点时,该节点上slots必须为零

下面关于Redis的文章您也可能喜欢,不妨参考下:

Redis 的详细介绍:请点这里

Redis 的下载地址:请点这里

0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我来回答你关于在 Linux 上部署 Redis 集群的问题。 Redis 是一个高性能的键值存储系统,常用于缓存、消息队列和会话存储等领域。部署 Redis 集群可以提高系统的可用性和性能。 以下是在 Linux 上部署 Redis 集群的一般步骤: 1. 下载和安装 Redis 可以从 Redis 的官方网站(https://redis.io/download)下载最新的 Redis 版本。下载完成后,解压缩文件并将 Redis 安装到你的系统中。 2. 配置 Redis 集群 在部署 Redis 集群之前,需要对 Redis 进行一些配置。首先,在每个节点上创建一个配置文件,其中包含节点的 IP 地址和端口号。然后,通过将这些配置文件复制到所有节点上并对它们进行编辑,来确保所有节点的配置都是相同的。还需要在每个节点上设置密码验证等安全措施。 3. 启动 Redis 集群 在配置完成后,可以启动 Redis 集群。首先,启动每个节点Redis 服务器。然后,在一个节点上运行 Redis 集群管理工具 Redis-trib,以创建 Redis 集群。在 Redis-trib 中,指定集群节点数和 IP 地址以及端口号。 4. 测试 Redis 集群 最后,可以使用 Redis 命令行工具或其他客户端工具来测试 Redis 集群是否正常工作。可以在集群中的任何一个节点上执行 Redis 命令,并观察命令在集群中的分布情况。 以上是在 Linux 上部署 Redis 集群的一般步骤。当然,实际的部署可能会因为环境和需求的不同而有所变化。希望这些信息能对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值