当前位置:网站首页>Redis cluster mode
Redis cluster mode
2022-08-02 00:59:00 【It's ninety-nine, not wine】
1.为什么使用Redis集群模式
redis单机版,After a single machine failure occurs,导致redis无法使用,如果程序使用redis,Indirectly cause program errors.
2.redis的集群模式
主从复制模式
哨兵模式
clustered mode
2.1.主从复制模式
2.1.1.What is master-slave replication mode
一主多从模式.一个主节点,多个从节点,Then the master node can be responsible:读操作,写操作. 从节点只能负责读操作,Cannot be responsible for write operations. In this way, the read pressure can be distributed from the master node to the slave node,To reduce the pressure on the master node.When the master node finishes executing the write command,The data will be synchronized to the slave node.
原则:配从不配主
2.1.2.How to configure master-slave replication mode
(1)准备条件
一主二从-----3台----Open three virtual machines--To save virtual machines,Open three on one hostredis服务.让7001作为主节点,7002,7003child node,preparing a directory,将redis.cofCopy this file to your newly created directory
(2)修改配置文件
1.修改端口号为7001,7002,7003
2.修改rdb文件的名称
3.如果你的aofturned on,就要关闭
(3)Drag the modified files into your newly created directory,Better to rename it
(4)启动Redis服务
(5)Log in to the customer service
(6)查看一下主从关系,命令是:info replication You will find that both are master nodes
(6)设置从节点 命令:slaveof 主节点的ip 主节点的端口号,设置好之后,查看一下主从关系
up 存活 down 死亡 salveof on one--关闭子节点
(7)The master node can read and write.But slave nodes can only read
2.2.哨兵模式
2.2.1.Why use sentry mode
由于主从模式,After the master node is single,The slave node will not automatically ascend. Add a sentry service,The Sentinel monitors all the timemaster,如果master挂了,Sentinels will elect a master node from among the slave nodes【哨兵投票机制】默认是sentinel.cof文件.
2.2.2.How to use Sentinel Mode
(1)修改配置文件--sentinel.cof
(2)启动哨兵
redis-sentinel sentinel.conf
(3)测试,关闭主节点,See if the child node will become the master node
shutdown 关闭Redis
2.3.clustered mode
2.3.1.Why use clustered mode
Regardless of the above master-slave or sentinel mode,Neither can solve the problem of single-node write operations.If the concurrency of write operations is relatively high at this time.It is possible to experiment with clustering mode【去中心化模式】
2.3.2.The principle of clustering
redis 集群中内置了 16384 个哈希槽,当需要在 Redis 集群中放置一个 key-value时,redis 先对 key 使用 crc16 The algorithm computes an integer result,然后把结果对 16384 求余数,这样每个 key 都会对应一个编号在 0-16383 之间的哈希槽,redis 会根据节点数量大致均等的将哈希槽映射到不同的节点.
当你往Redis Cluster中加入一个Key时,会根据crc16(key) mod 16384计算这个key应该分布到哪个hash slot中,一个hash slot中会有很多key和value.你可以理解成表的分区,使用单节点时的redis时只有一个表,所有的key都放在这个表里;改用Redis Cluster以后会自动为你生成16384个分区表,你insert数据时会根据上面的简单算法来决定你的key应该存在哪个分区,每个分区里有很多key.
3.2.3.How to use clustered mode
(1)前提
Prepare three master nodes,三个从节点
6001 6002 6003 6004 6005 6006
创建一个目录,Put our configuration file into the directory
(2)设置配置文件
Redis-1 防火墙--6379
bind 0.0.0.0
port 6001
daemonize yes
dbfilename dump6001.rdb
# 打开aof 持久化
appendonly yes
appendonly appendonly6001.aof
# 开启集群
cluster-enabled yes
# 集群的配置文件,该文件自动生成
cluster-config-file nodes-6001.conf
# 集群的超时时间
cluster-node-timeout 15000
(3)Start these sixredis服务
(4)分配槽
redis-cli --cluster create --cluster-replicas 1 192.168.118.110:7000 192.168.118.110:7001 192.168.118.110:7002 192.168.118.111:7003 192.168.118.111:7004 192.168.118.111:7005
注意: Make sure that each node has no data.
(5)进入redis
redis-cli -c-h 192.168.223.155 -p 6001
加上-c Enter cluster mode 不加-cEnter single click mode
(6)添加数据
Find the added data in6003的接口,是因为输入key 的时候,进行了crc16计算,Integers will be calculated 16384 求余数,这样每个 key 都会对应一个编号在 0-16383 之间的哈希槽,redis 会根据节点数量大致均等的将哈希槽映射到不同的节点 ,Write operations can be spread across different nodes,Reduced pressure on a single master node.
4.java连接redis
4.1.redisWhich languages are supported to operate
4.2.使用jedis
边栏推荐
猜你喜欢
实现删除-一个字符串中的指定字母,如:字符串“abcd”,删除其中的”a”字母,剩余”bcd”,也可以传递多个需要删除的字符,传递”ab”也可以做到删除”ab”,剩余”cd”。
Redis - message publish and subscribe
微信支付软件架构,这也太牛逼了!
mapbox使用教程
傅立叶变换相关公式
flv.js解析与使用
好的期货公司开户让人省心省钱
BGP综合实验 建立对等体、路由反射器、联邦、路由宣告及聚合
ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘解决方法
Go 1.18 的那些事——工作区、模糊测试、泛型
随机推荐
内部类、异常简单介绍(第十天)
nodeJs--各种路径
管理基础知识16
23.卷积神经网络实战-ResNet
flyway的快速入门教程
JS中对作用域链的理解(查找变量)
Day.js 常用方法
PowerBI商学院佐罗BI真经连续剧
Pytorch seq2seq 模型架构实现英译法任务
IDEA版Postman插件Restful Fast Request,细节到位,功能好用
ECMAScript 2022 正式发布,有你了解过的吗?
扫雷小游戏
hutool工具-----JSON工具-JSONUtil
tf.keras.callbacks.EarlyStopping()
微信支付软件架构,这也太牛逼了!
Looking back at 5 recessionary times in history: How might this time be different?
Are test points the same as test cases?
期货开户交返是行内公开的秘密
期货开户手续费的秘密成了透明
期货公司开户实力经纪业务的规模