当前位置:网站首页>redis 主从架构(sizeof函数怎么计算)
redis 主从架构(sizeof函数怎么计算)
2022-07-28 17:41:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
一.绪论
Redis的复制功能是基于内存快照的持久化策略基础上的,也就是说无论你的持久化策略选择的是什么,只要用到了Redis的复制功能,就一定会有内存快照发生。 当Slave启动并连接到Master之后,它将主动发送一个SYNC命令( 首先Master会启动一个后台进程,将数据快照保存到文件中[rdb文件] Master 会给Slave 发送一个Ping命令来判断Slave的存活状态 当存活时 Master会将数据文件发送给Slave 并将所有写命令发送到Slave )。Slave首先会将数据文件保存到本地 之后再将 数据 加载到内存中。当第一次链接 或者是 故障后 重新连接 都会先判断Slave的存活状态 在做全部数据的同步 , 之后只会同步Master的写操作(将命令发送给Slave)
二.优点
1.在一个Redis集群中,master负责写请求,slave负责读请求,这么做一方面通过将读请求分散到其他机器从而大大减少了master服务器的压力,另一方面slave专注于提供读服务从而提高了响应和读取速度。 2.在一个Redis集群中,如果master宕机,slave可以介入并取代master的位置,因此对于整个Redis服务来说不至于提供不了服务,这样使得整个Redis服务足够安全。 3.水平增加Slave机器可以提高性能,Slave 默认是只读的更改,Master 可以 读写(Write and Read) 而 Slave只可以读(read only默认情况)也可以更改 {但是开启后Slave数据不会向上同步}
三.实践
1.下载安装
wget http://download.redis.io/releases/redis-4.0.11.tar.gz2.解压缩
tar -zxvf redis-4.0.11.tar.gz3.安装编译,进入到解压缩目录下,执行以下两个命令即可
make
make install4.通过cp复制成如下几个master,slave1,slave2目录
5.修改主节点配置文件redis.conf
protected-mode yes
slave-serve-stale-data yes
port 使用默认的6379 6.修改从节点配置文件
1).从节点一
protected-mode yes
slave-serve-stale-data yes
port 6380
slaveof 127.0.0.1 6379 主节点的ip和端口2).从节点二
protected-mode yes
slave-serve-stale-data yes
port 6381
slaveof 127.0.0.1 6379 主节点的ip和端口四.启动测试
1.首先启动主节点,然后启动从节点,命令一样的,进入到src下通过以下命令进行启动
./redis-server ../redis.conf2.测试
在主节点上通过info replication查看节点信息,连接主节点的客户端,通过以下命令
redis-cli -p 6379然后输入info replication
3.在主节点上添加一条数据,在从节点上进行查看是否数据进行同步了.
1).添加数据
2).从节点获取数据
以上就完成了redis的主从架构的搭建和数据的同步
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/128488.html原文链接:https://javaforall.cn
边栏推荐
- Cvpr21 unsupervised anomaly detection cutpaste:self supervised learning for anomaly detection and localization
- Application of time series database in bridge monitoring field
- How to use Qianqian listening sound effect plug-in (fierce Classic)
- Libgdx learning road 02: draw game map with tiled
- Smart contract security - overflow vulnerability
- Mid 2022 summary
- Convertible bond concept table x notation gives you a convenient and fast experience!
- 业务可视化-让你的流程图“Run“起来(4.实际业务场景测试)
- Avoidance Adjusted Climbrate
- App自动化测试是怎么实现H5测试的
猜你喜欢

Nips18 (AD) - unsupervised anomaly detection using geometric transformations using geometric augmentation

Image processing web application development tutorial

Asp net MVC web development tutorial

BLDC 6步换相 simulink

Method of win7 system anti ARP attack

Streamlit machine learning application development tutorial

彻底理解位运算——左移、右移

文章翻译软件-批量免费翻译软件支持各大翻译接口

Fantasy 5 (ue5) game engine complete course 2022

可转债概念表 x Notion 给你方便快捷的体验!
随机推荐
Rust Getting Started Guide (modules and engineering structures)
JS 批量添加事件监听onclick this 事件委托 target currentTarget onmouseenter onmouseover
Nips18 (AD) - unsupervised anomaly detection using geometric transformations using geometric augmentation
[深入研究4G/5G/6G专题-44]: URLLC-15-《3GPP URLLC相关协议、规范、技术原理深度解读》-9-低延时技术-3-非时隙调度Mini slot
Sudo rosdep init error: cannot download default
[notes] Apocalypse: list of practical experience and reflection of product managers
峰值速率超2Gbps!高通在中国首发通过5G毫米波MIMO OTA测试
BLDC 6-step commutation simulink
NDK series (5): from introduction to practice, JNI explodes the liver and explains everything in detail!
Using CPLEX to solve small-scale energy-efficient FJSP
andorid系统layout、values、drawable适配
ICLR21(classification) - 未来经典“ViT” 《AN IMAGE IS WORTH 16X16 WORDS》(含代码分析)
[notes] Networking: Internet product managers change the world
NDK 系列(5):JNI 从入门到实践,爆肝万字详解!
英语文章翻译-英语文章翻译软件-免费批量翻译
串口接收应用——环形缓冲buffer
After reading the thesis for three years, I learned to read the abstract today
Cvpr21 unsupervised anomaly detection cutpaste:self supervised learning for anomaly detection and localization
Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 2)
Sword finger offer II 109. unlock the password lock