Carry の Blog Carry の Blog
首页
  • Nginx
  • Prometheus
  • Iptables
  • Systemd
  • Firewalld
  • Docker
  • Sshd
  • DBA工作笔记
  • MySQL
  • Redis
  • TiDB
  • Elasticsearch
  • Python
  • Shell
  • MySQL8-SOP手册
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Carry の Blog

好记性不如烂键盘
首页
  • Nginx
  • Prometheus
  • Iptables
  • Systemd
  • Firewalld
  • Docker
  • Sshd
  • DBA工作笔记
  • MySQL
  • Redis
  • TiDB
  • Elasticsearch
  • Python
  • Shell
  • MySQL8-SOP手册
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • MySQL

  • Redis

    • 安装配置
    • Redis 集群部署
    • redis大key分析
    • Redis手动进行主从切换
      • 前言
    • Redis集群添加节点之后数据重新均匀分配
    • Redis槽位slot解读
    • redis新增节点slot迁移报错故障修复
    • Redis集群的创建、剔除节点与新增节点操作过程
    • redis抓包分析脚本
    • Redis配置文件解读
    • redis cluster压测
    • redis慢查询告警脚本
    • Redis 的可用内存过高时的自动驱逐 key 策略详解
  • Keydb

  • TiDB

  • MongoDB

  • Elasticsearch

  • Kafka

  • victoriametrics

  • BigData

  • Sqlserver

  • 数据库
  • Redis
Carry の Blog
2022-03-17
目录

Redis手动进行主从切换

# Redis手动进行主从切换

# 前言

当redis集群中的一个节点出现故障,需要将主从互换的时候会用到

[dba@redisnode0001 bin]# sudo ./redis-cli -h 127.0.0.1 -p 8001 -c -a xxxxxxxxxxx --cluster check 127.0.0
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:9001 (c1422bc2...) -> 1 keys | 5461 slots | 1 slaves.
172.31.170.16:9002 (87f4cf99...) -> 0 keys | 5462 slots | 1 slaves.
172.31.170.17:9003 (63395075...) -> 1 keys | 5461 slots | 1 slaves.
[OK] 2 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:9001)
M: c1422bc23f702c702a1de872f5a0026238268fa9 127.0.0.1:9001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: c1000a4985fd5a8c8afd9c8bdaa4d99f137e78eb 172.31.170.15:9003
   slots: (0 slots) slave
   replicates 633950751a8fc0a18b4a1ad4c5dd90095d4147b0
M: 87f4cf99d533f74532d5b586bbdeabe7dc0df499 172.31.170.16:9002
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 633950751a8fc0a18b4a1ad4c5dd90095d4147b0 172.31.170.17:9003
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 0ca6df3fb57b53700bb2d328696932d3f3fe62c9 172.31.170.15:9001
   slots: (0 slots) slave
   replicates c1422bc23f702c702a1de872f5a0026238268fa9
S: d6f6aa0a5003a25060e48032544f27044d5445ef 172.31.170.17:9002
   slots: (0 slots) slave
   replicates 87f4cf99d533f74532d5b586bbdeabe7dc0df499
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

通过check 命令找到与主节点相同ID的从节点,连接上从节点之后执行命令

[dba@redisnode0001 bin]# sudo ./redis-cli -h 172.31.170.15 -p 9001 -c -a xxxxxxxxxxxxx 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
172.31.170.15:9001> cluster failover
OK
172.31.170.15:9001> cluster nodes
87f4cf99d533f74532d5b586bbdeabe7dc0df499 172.31.170.16:9002@19002 master - 0 1638603378000 2 connected 5461-10922
633950751a8fc0a18b4a1ad4c5dd90095d4147b0 172.31.170.17:9003@19003 master - 0 1638603377000 3 connected 10923-16383
0ca6df3fb57b53700bb2d328696932d3f3fe62c9 172.31.170.15:9001@19001 myself,master - 0 1638603377000 5 connected 0-5460
c1422bc23f702c702a1de872f5a0026238268fa9 172.31.170.16:9001@19001 slave 0ca6df3fb57b53700bb2d328696932d3f3fe62c9 0 1638603378554 5 connected
d6f6aa0a5003a25060e48032544f27044d5445ef 172.31.170.17:9002@19002 slave 87f4cf99d533f74532d5b586bbdeabe7dc0df499 0 1638603378000 2 connected
c1000a4985fd5a8c8afd9c8bdaa4d99f137e78eb 172.31.170.15:9003@19003 slave 633950751a8fc0a18b4a1ad4c5dd90095d4147b0 0 1638603378752 3 connected
1
2
3
4
5
6
7
8
9
10
11

若无意在主节点上执行的话,会有以下报错

127.0.0.1:8001> cluster failover
(error) ERR You should send CLUSTER FAILOVER to a replica
1
2
上次更新: 4/24/2025

← redis大key分析 Redis集群添加节点之后数据重新均匀分配→

最近更新
01
tidb fast ddl
04-04
02
TiDB配置文件调优 原创
04-03
03
如何移除TiDB中的表分区 原创
04-03
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式