当前位置: 首页 > news >正文

Redis搭建集群模式

Redis搭建集群模式

  • 一、集群模式原理
  • 二、搭建三主三从高可用集群
        • master1-6379配置文件
  • 三、创建Redis集群
  • 四、集群扩容
  • 五、集群缩容

一、集群模式原理

二、搭建三主三从高可用集群

在这里插入图片描述

准备 3 台服务器,每台部署两个 Redis 实例

dnf install -y gcc tcl gcc-c++ makewget https://download.redis.io/releases/redis-8.0.2.tar.gz[root@redis ~]# tar -xzf redis-8.0.2.tar.gz -C /opt
[root@redis ~]# cd /opt
[root@redis opt]# cd redis-8.0.2/
[root@redis redis-8.0.2]# make
master1-6379配置文件
[root@redis2 redis-8.0.1]# mkdir -p /opt/redis/{6379,6380}/{conf,data,logs,pid}
[root@redis2 redis-8.0.1]# cat > /opt/redis/6379/conf/redis_6379.conf <<EOF
> bind 0.0.0.0
> protected-mode no
> port 6379
> daemonize yes
> logfile /opt/redis/6379/logs/redis_6379.log
> pidfile /opt/redis/6379/pid/redis_6379.pid
> dbfilename "redis_6379.rdb"
> dir /opt/redis/6379/data
> cluster-enabled yes
> cluster-config-file node_6379.conf
> cluster-node-timeout 15000
> EOF
[root@redis2 redis-8.0.1]# vim redis.conf 
[root@redis2 redis-8.0.1]# 
[root@redis2 redis-8.0.1]# cd /opt/redis/
[root@redis2 redis]# ls
6379  6380  conf  data
[root@redis2 redis]# cd 6379
[root@redis2 6379]# ls
conf  data  logs  pid
[root@redis2 6379]# cd conf/
[root@redis2 conf]# ls
redis_6379.conf
[root@redis2 conf]# cat redis_6379.conf 
bind 0.0.0.0
protected-mode no
port 6379
daemonize yes
logfile /opt/redis/6379/logs/redis_6379.log
pidfile /opt/redis/6379/pid/redis_6379.pid
dbfilename "redis_6379.rdb"
dir /opt/redis/6379/data
cluster-enabled yes
cluster-config-file node_6379.conf
cluster-node-timeout 15000
[root@redis2 conf]# cp redis_6379.conf /opt/redis/6380/conf/redis_6380.conf
  • vim模式下更改啊6379为6380
    %s/6379/6380/g
[root@redis2 conf]# cat /opt/redis/6380/conf/redis_6380.conf 
bind 0.0.0.0
protected-mode no
port 6380
daemonize yes
logfile /opt/redis/6380/logs/redis_6380.log
pidfile /opt/redis/6380/pid/redis_6380.pid
dbfilename "redis_6380.rdb"
dir /opt/redis/6380/data
cluster-enabled yes
cluster-config-file node_6380.conf
cluster-node-timeout 15000

三、创建Redis集群

  • 创建集群模式
[root@redis1 opt]# redis-server /opt/redis/6379/conf/redis_6379.conf
[root@redis1 opt]# redis-server /opt/redis/6380/conf/redis_6380.conf
[root@redis1 opt]# ps -ef | grep redis*
root        6932       1  0 19:44 ?        00:00:00 redis-server 0.0.0.0:6379 [cluster]
root        6941       1  0 19:45 ?        00:00:00 redis-server 0.0.0.0:6380 [cluster]
root        6950    1789  0 19:45 pts/0    00:00:00 grep --color=auto redis
[root@redis1 opt]# redis-cli --cluster create \
192.168.98.162:6379 192.168.98.161:6379 192.168.98.149:6379 \
192.168.98.162:6380 192.168.98.161:6380 192.168.98.149:6380 \
--cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.98.161:6380 to 192.168.98.162:6379
Adding replica 192.168.98.149:6380 to 192.168.98.161:6379
Adding replica 192.168.98.162:6380 to 192.168.98.149:6379
M: e104cf2177b20526ed1283a092c2801358b94260 192.168.98.162:6379slots:[0-5460] (5461 slots) master
M: d9b31a225fb87fda96c8c92c30df6c87c990e8d8 192.168.98.161:6379slots:[5461-10922] (5462 slots) master
M: 0bcee9b00b697ca0800d9596dcbd7fbd7f595281 192.168.98.149:6379slots:[10923-16383] (5461 slots) master
S: 757332977033f618caabcc5f36f7594b2760d11f 192.168.98.162:6380replicates 0bcee9b00b697ca0800d9596dcbd7fbd7f595281
S: 18dcbd8dcd138f3a5214e7db0d0f30a4a361e3da 192.168.98.161:6380replicates e104cf2177b20526ed1283a092c2801358b94260
S: ed9e5c3b58940294054b852cb3a872717d697157 192.168.98.149:6380replicates d9b31a225fb87fda96c8c92c30df6c87c990e8d8
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.98.162:6379)
M: e104cf2177b20526ed1283a092c2801358b94260 192.168.98.162:6379slots:[0-5460] (5461 slots) master1 additional replica(s)
S: ed9e5c3b58940294054b852cb3a872717d697157 192.168.98.149:6380slots: (0 slots) slavereplicates d9b31a225fb87fda96c8c92c30df6c87c990e8d8
M: d9b31a225fb87fda96c8c92c30df6c87c990e8d8 192.168.98.161:6379slots:[5461-10922] (5462 slots) master1 additional replica(s)
S: 757332977033f618caabcc5f36f7594b2760d11f 192.168.98.162:6380slots: (0 slots) slavereplicates 0bcee9b00b697ca0800d9596dcbd7fbd7f595281
M: 0bcee9b00b697ca0800d9596dcbd7fbd7f595281 192.168.98.149:6379slots:[10923-16383] (5461 slots) master1 additional replica(s)
S: 18dcbd8dcd138f3a5214e7db0d0f30a4a361e3da 192.168.98.161:6380slots: (0 slots) slavereplicates e104cf2177b20526ed1283a092c2801358b94260
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.



四、集群扩容




五、集群缩容




















http://www.lryc.cn/news/578994.html

相关文章:

  • 桥岛隧大型工程 3D 可视化监测平台
  • Objective-C 路由表原理详解
  • Git 怎么判断是否冲突?
  • 开源 Python 库---Diffusers 库的安装及运用(自留)
  • Python学习之——单例模式
  • 智慧赋能高压并网:分布式光伏监控系统在5.88MW物流园项目的实践解析
  • PHP Yii2 安装SQL Server扩展-MAC M4 Pro芯片
  • 【AI论文】SPIRAL:零和博弈中的自对弈通过多智能体多轮强化学习激励推理能力
  • 场外交易(OTC)财富管理系统开发及解决方案报告
  • 【Part 3 Unity VR眼镜端播放器开发与优化】第四节|高分辨率VR全景视频播放性能优化
  • 腾讯云认证考试报名 - TDSQL数据库交付运维专家(TCCE MySQL版)
  • 电子电气架构 --- SOVD功能简单介绍
  • 二、jenkins之idea提交项目到gitlab、jenkins获取项目
  • 【NLP第二期中文分词技术:规则、统计与混合方法全解】
  • 设计模式精讲 Day 23:访问者模式(Visitor Pattern)
  • uniapp实现图片预览,懒加载
  • React Native 安卓、苹果、鸿蒙5.0 三端适配方案:条件编译 + 平台适配层
  • 信创版nhdeep档案管理系统单机版在银河麒麟桌面系统安装和使用说明
  • UI前端与数字孪生结合探索:智慧建筑的能耗管理与优化
  • 【论文阅读39】PINN求边坡内时空变化的地震动响应(位移、速度、加速度)场分布
  • npm代理设置 + npm配置镜像源
  • Node.js、npm 与 nvm 使用全指南:安装、版本管理与开发环境配置详解
  • 在 Docker Desktop 使用 Kubernetes
  • RuoYi框架低代码特性
  • 鸿蒙自定义相机的拍照页面
  • 深入理解 LoRA:大语言模型微调的低秩魔法
  • 智能合约状态快照技术:实现 EVM 状态的快速同步与回滚
  • YOLOv8模型结构构件及问题汇总【持久更新】
  • HarmonyOS应用开发高级认证知识点梳理 (四)状态管理V2应用级状态
  • 商品中心—18.库存分桶的一致性改造文档