当前位置:网站首页>[redis]redis6 master-slave replication
[redis]redis6 master-slave replication
2022-06-22 21:10:00 【fate _ zore】
Redis6 Master-slave replication of
brief introduction
After the host data is updated, according to the configuration and Policy , Automatic synchronization to the standby machine master/slaver Mechanism ,Master Write first ,Slave Mainly reading
effect
- Read / write separation , Performance expansion
- Rapid disaster recovery

Specific operation
- Copy multiple redis.conf file include( Write absolute path )
- Turn on daemonize yes
- Pid File name pidfile
- Designated port port
- Log File name
- dump.rdb name dbfilename
- Appendonly Turn it off or change the name
newly build redis****.conf
include /myRedis/redis.conf
pidfile /var/run/redis_6379.pid
port 6379
dbfilename dump6379.rdb
Start three services

perform slaveof host ip Port number

Commonly used 3 recruit
One master and two servants
- When you hang up from the service , Start again , It will not inherit the previous master-slave state , At this time, the service is master, It needs to be reset , And after resetting , The data of the main service will be copied
- When the main service hangs up , The state of the slave service does not change , When the main service is started again , It will automatically continue the previous master-slave status , The data will also be copied to the main service , Everything remains the same.
It's passed down from generation to generation
the previous Slave It could be the next slave Of Master,Slave Can also receive other slaves Connection and synchronization requests for , Then the slave As the next in the chain master, Can effectively reduce master The pressure of writing , Decentralization reduces risk .
- use slaveof
- Change direction in the middle : Will clear the previous data , Recreate the copy of the latest
- The risk is that once something slave Downtime , hinder slave No backup
- The mainframe is down , Slave or slave , Unable to write data

Going to
When one master After downtime , hinder slave Can be promoted to master, Behind it slave You don't have to make any changes .
use slaveof no one From slave to host .
Master slave replication principle
- After the server is linked to the primary server , Send a data synchronization message to the primary server
- The primary server receives a message , Pass the data through rdb Way to persist , take rdb File transfer to the slave server , From the server through rdb File read
- Whenever the primary server performs a write operation , Will notify the server to synchronize data
- The slave server only actively requests data synchronization during the first link , In other cases, the master server is responsible for data synchronization

Sentinel mode
brief introduction
The automatic version of anti guest oriented , Be able to monitor the failure of the host in the background , If it fails, it will automatically convert from the library to the main library according to the number of votes

Implementation steps
One servant and two masters
Self defined /myRedis New under the directory sentinel.conf file
Deploy sentinels , Fill in the content
sentinel monitor mymaster 127.0.0.1 6379 1
among mymaster Server name for the monitored object , 1 For at least how many sentinels agree to move the number .
Activate the sentry
/usr/local/bin
redis For pressure measurement, you can use your own re dis-benchmark Tools
perform redis-sentinel /myredis/sentinel.conf
When the host goes down , A new host is generated from the election of the slave computer
( Probably 10 You can see the sentry window log in seconds , Switched to a new host )
Which is elected as the host from the opportunity ? According to priority :slave-priority
After the original host is restarted, it will become a slave .
Replication delay
Because all the writing operations are first in Master On the operation , Then sync update to Slave On , So from Master Synchronize to Slave The machine has a certain delay , When the system is busy , The delay problem will be more serious ,Slave The increase in the number of machines will make the problem more serious .
Fault recovery

The priority is redis.conf The default :slave-priority 100, The lower the value, the higher the priority
Offset refers to the most complete data of the original host
Every redis After the instance is started, it will generate one randomly 40 Bit runid
java Set up
private static JedisSentinelPool jedisSentinelPool=null;
public static Jedis getJedisFromSentinel(){
if(jedisSentinelPool==null){
Set<String> sentinelSet=new HashSet<>();
sentinelSet.add("192.168.11.103:26379");
JedisPoolConfig jedisPoolConfig =new JedisPoolConfig();
jedisPoolConfig.setMaxTotal(10); // Maximum number of connections available
jedisPoolConfig.setMaxIdle(5); // Maximum number of idle connections
jedisPoolConfig.setMinIdle(5); // Minimum number of idle connections
jedisPoolConfig.setBlockWhenExhausted(true); // Whether the connection is exhausted and wait
jedisPoolConfig.setMaxWaitMillis(2000); // Waiting time
jedisPoolConfig.setTestOnBorrow(true); // Test the connection ping pong
jedisSentinelPool=new JedisSentinelPool("mymaster",sentinelSet,jedisPoolConfig);
return jedisSentinelPool.getResource();
}else{
return jedisSentinelPool.getResource();
}
}
边栏推荐
- Set up your own website (12)
- Agricultural futures account opening
- 78-生产系统不改代码解决SQL性能问题的几种方法
- R 语言USArrests 数据集可视化
- Overview of common loss functions for in-depth learning: basic forms, principles and characteristics
- 让知识付费系统视频支持M3U8格式播放的方法
- [redis]Redis6的事务操作
- Three ways of extending ribbon to support Nacos weight
- View Apple product warranty status
- 89-oracle SQL写法与优化器缺陷一例
猜你喜欢
随机推荐
[142. circular linked list II]
View Apple product warranty status
[redis]发布与订阅
一行代码为特定状态绑定SwiftUI视图动画
查看苹果产品保修状态
The real king of cache
如何计算 R 中的基尼系数(附示例)
Feign常见问题总结
扩展Ribbon支持基于元数据的版本管理
R 语言USArrests 数据集可视化
R 语言 wine 数据集可视化
84-我对网传&lt;52 条 SQL 语句性能优化策略&gt;的一些看法
性能测试(一)
[redis]redis的持久化操作
Baijia forum Huangdi Neijing (Part I)
Scheduling with Testing
Japanese anime writers and some of their works
79-不要看到有order by xxx desc就创建desc降序索引-文末有赠书福利
A Dynamic Near-Optimal Algorithm for Online Linear Programming
Objective-C byte size occupied by different data types
![[876. intermediate node of linked list]](/img/c8/463d150bc6c88cfb57e94795957b0e.png)







