当前位置:网站首页>[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();
}
}
边栏推荐
猜你喜欢
随机推荐
R 语言USArrests 数据集可视化
Numpy learning notes (6) -- sum() function
74-这类SQL优化,oracle输给了mysql,如何补救?
NBA playoff match chart
How to use feign to construct multi parameter requests
【文末送书】火遍全网的AI给老照片上色,这里有一份详细教程!
软件测试——测试用例设计&测试分类详解
Visualization of wine datasets in R language
Visualization of R language penguins dataset
已解决:一個錶中可以有多個自增列嗎
Baijia forum Wu Zetian
MYSQL 几个常用命令使用
R language usarrests dataset visualization
建立自己的网站(12)
评估指标及代码实现(NDCG)
R language universalbank CSV "data analysis
2022危险化学品经营单位主要负责人上岗证题库及模拟考试
[142. circular linked list II]
【21. 合并两个有序链表】
百家讲坛 大秦崛起(下部)






![[138. copy linked list with random pointer]](/img/87/b2f1d224cfc627b4311208ccb9e274.png)


