当前位置:网站首页>Redis集群搭建(Windows)
Redis集群搭建(Windows)
2022-07-25 05:03:00 【湖南最后的温柔】
Redis高可用
一般来说,对数据的修改和写入删除的操作会消耗大量的资源,而查的操作相对来说消耗的资源比较小,但是查询的操作相对于增删改的次数会很多,因此我们可以使用集群来帮助我们实现Redis的高可用,下面介绍两种非常常见的方式来实现,分别是主从复制和哨兵模式。
主从复制
首先我们对redis的配置文件进行操作, 我们需要让我们的主节点和其他的节点的端口号不同。要不然会发生redis启动秒退。 我们打开redis的目录文件夹,将其中的
下面这个是redis 启动默认的配置文件我们需要配置下面这文件。我们将6379作为主节点。
将这个文件夹进行复制。复制两份作为从节点。 我们使用主节点来进行写入和更改的操作 如果是查询的操作就会打到从节点上面。
我们将另外两个的端口号改一下 改为6380 6381 作为从节点。 然后 用服务端链接 输入
slaveof 127.0.0.1 6379 意思是认主 将这个节点视为master 另外一个也用同样的操作 。这样就完成简单的主从模式的搭建了。
我们在主节点的客户端进行输入 set a 6
在从节点里面也能get到这个a 的值 但是 我们 尝试修改一下这个值 发现从节点不能修改值 。
哨兵模式
首先我们想一下为什么需要哨兵模式?
当我们的主从复制的从节点g了的时候,我们主节点还是能完成从节点的功能,,我们可以后续再增加从节点的数量来减小这些节点的压力,但是,如果是主节点g了呢?那整个集群就挂了,因此 我们需要一个办法在主节点没了的时候能有解决办法,redis使用了哨兵模式。
哨兵模式是使用其他的几个redis服务器来监视正在运行的这个redis集群,同时也会监测这些哨兵。 当我们的主节点g了之后,哨兵会进行选举,选举出新的主节点,然后将其他的从节点依附于这个主节点,原本的主节点就变成下线的状态。
如何实现?
首先之前的redis的主从复制模式不用去管 我们只需要新建三个哨兵来监视他们就好了,我们在redis文件夹里面新建一个config
内容
# 这个是Redis6379配置内容,其他文件同理新增然后改一下端口即可,26380,和 26381。
#当前Sentinel服务运行的端口
port 26380
# 哨兵监听的主服务器
sentinel monitor mymaster 127.0.0.1 6381 2
# 3s内mymaster无响应,则认为mymaster宕机了
sentinel down-after-milliseconds mymaster 3000
#如果10秒后,mysater仍没启动过来,则启动failover
sentinel failover-timeout mymaster 10000
# 执行故障转移时, 最多有1个从服务器同时对新的主服务器进行同步
sentinel config-epoch mymaster 1
然后启动 因为我们的主节点里面有其他的从节点的信息 ,因此我们的哨兵也能监测到那些从节点,这里只需要配置主节点就好了。
这样哨兵模式算是启动了。
边栏推荐
- HMS core discovery Episode 16 live broadcast preview | play AI's new "sound" state with tiger pier
- 哪种网站适合物理服务器
- Bypass XSS filters in Web Applications
- Getting started with scratch
- Salt and ice particles cannot be distinguished
- 中创算力荣获「2022年科技型中小企业」认定
- GDT,LDT,GDTR,LDTR
- 2、 Mysql database foundation
- Zhongchuang computing power won the recognition of "2022 technology-based small and medium-sized enterprises"
- In depth understanding of service
猜你喜欢

Unity LOD

Completed project series Tutorials - smart campus management system

Paper:《Peeking Inside the Black Box: Visualizing Statistical Learning with Plots of Individual Condi

龙蜥社区发布首个 Anolis OS 安全指南 为用户业务系统保驾护航

Actual combat | record an attack and defense drill management

HMS Core Discovery第16期直播预告|与虎墩一起,玩转AI新“声”态

QT download installation tutorial

Web: compiling big refactoring from 10 to 1

If you don't know these 20 classic redis interview questions, don't go to the interview!

Summary of UPR optimization suggestions of unity
随机推荐
Harbor installation
Paper:《Peeking Inside the Black Box: Visualizing Statistical Learning with Plots of Individual Condi
Androd releases jitpack open source project (gradle7.2)
Deep understanding of pod
Web: compiling big refactoring from 10 to 1
How to publish your own NPM package
Druid connection pool - strong self-study from 0. Those who don't understand Druid can click in. If you know not to click in, you will think I'm wordy
The interviewer asked MySQL transactions, locks and mvcc at one go. I
Docker builds MySQL master-slave replication
MCU experiment record
基于云原生的私有化 PaaS 平台交付实践
Your technical leader doesn't understand this? Without it, there is no complete thinking process of design
How to get the database creation time?
four hundred and forty-four thousand one hundred and forty-one
市场是对的
2022-7-18 summary
Matter's Unified Smart Home connection standard enables local automatic interaction between smart devices
The market is right
Thinking of reading
Document collaboration tool recommendation