当前位置: 首页 > 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.xdnf.cn/news/1077805.html

相关文章:

  • 微信小程序入门实例_____打造你的专属单词速记小程序
  • MAC 多应用切换技巧,单应用切换技巧
  • 文心快码答用户问|Comate AI IDE专场
  • C#调用C++导出的dll怎么调试进入C++ DLL源码
  • 生产环境下载功能OOM问题复盘
  • 学习笔记(29):训练集与测试集划分详解:train_test_split 函数深度解析
  • 科技有温度:七彩喜智慧康养平台,为银发生活织就“数字守护网”
  • 【Vue入门学习笔记】Vue核心语法
  • 飞算 JavaAI 智控引擎:全链路开发自动化新图景
  • Active-Prompt:让AI更智能地学习推理的革命性技术
  • 纹理贴图算法研究论文综述
  • 【leetcode算法300】:哈希板块
  • Stereolabs ZED系列与ZED X立体相机系列对比:如何根据项目需求选择?
  • Kalibr解毒填坑(一):相机标定失败
  • .net审计库:EntityFrameworkCore.Audit
  • React安装使用教程
  • UniApp完全支持快应用QUICKAPP-以及如何采用 Uni 模式开发发行快应用优雅草卓伊凡
  • 业界优秀的零信任安全管理系统产品介绍
  • css函数写个loading动画 | css预编译scss使用
  • CSS 安装使用教程
  • Android 网络全栈攻略(四)—— TCPIP 协议族与 HTTPS 协议
  • WPF学习笔记(19)控件模板ControlTemplate与内容呈现ContentPresenter
  • 电源芯片之DCDC初探索ING
  • Instruct-GPT中强化学习(RL)训练部分详解
  • 数据结构:递归:组合数(Combination formula)
  • Vite 7.0 与 Vue 3.5:前端开发的性能革命与功能升级
  • 基于SpringBoot + HTML 的网上书店系统
  • HDMI 2.1 FRL协议的流控机制:切片传输(Slicing)和GAP插入
  • Windows10/11 轻度优化 纯净版,12个版本!
  • 深度学习常见的激活函数