当前位置:网站首页>Redis master-slave and sentinel master-slave switchover are built step by step
Redis master-slave and sentinel master-slave switchover are built step by step
2022-07-07 19:20:00 【Poetic elegance】
- Redis Support master-slave reuse . Data can be synchronized from the master server to any number of slaves , Synchronization uses Publishing / Subscribe mechanism .Mater Slave The pattern of , from Slave towards Master launch SYNC command .
- It can be 1 Master many Slave, It can be layered ,Slave You can connect to Slave, It can be expanded into a tree structure .
- Because there are no two computers , So you can only build two on one machine Redis Server side .
- Here we use a single machine to simulate redis Master slave server , Realize read-write separation configuration .
List of articles
- Create three directories ( Data files 、 Log files 、 The configuration file )
- Copy redis.conf to /opt/redis/conf Under the table of contents
- modify redis-common.conf Public profile
- Comment out bind 127.0.0.1
- Turn off protection mode , It is amended as follows no
- Comment public configuration port
- Change to background start
- Note process number record file
- Comment on the public configuration data file 、 Modify data file path
- Add authentication from server to master server
- Add access authentication
- Comment public configuration append file
- add to 3 A private profile of a service
- function 3 individual redis process
- see redis Server master-slave status
- Sentinel configuration
- modify sentinel-common.conf Sentinel public profile
- Modify configuration information
- Note sentinel listening process port number
- Local area network IP, Otherwise, remote connection will not be possible
- Set up master and slaves Password
- Turn off protection mode , It is amended as follows no
- Change to background start 
- add to 3 A private configuration file for sentinels
- Start the test
- See if the sentry is finished
Create three directories ( Data files 、 Log files 、 The configuration file )

Copy redis.conf to /opt/redis/conf Under the table of contents

modify redis-common.conf Public profile
Comment out bind 127.0.0.1

Turn off protection mode , It is amended as follows no

Comment public configuration port

Change to background start

Note process number record file

Comment on the public configuration data file 、 Modify data file path
By default ,Redis Save the database snapshot in a file named dump.rdb In the binary file of . Of course , This can be modified redis.conf Configuration file to define data storage conditions , It is stipulated in “ N At least... In seconds M A change ” When this condition is met , Save the data set automatically once . You can also call save or bgsave , Let go by hand Redis Save the dataset dbfilename and dir Use a combination of ,dbfilename look for dir Path generation data file 
Add authentication from server to master server

Add access authentication

Comment public configuration append file

add to 3 A private profile of a service
touch perhaps vi Can create a blank file
touch Create a blank file directly , vi Create and enter edit mode , :wq Create success , Otherwise, do not create 
redis-6379.conf
# Reference public configuration
include /opt/redis/conf/redis-common.conf
# Process number record file
pidfile /var/run/redis-6379.pid
# Process port number
port 6379
# Log files
logfile "/opt/redis/log/redis-6379.log"
# Data record file
dbfilename dump-6379.rdb
# Add file name
appendfilename "appendonly-6379.aof"
# The following configuration does not need to be in 6379 Internal configuration
# The backup server is subordinate to 6379 Recommended configuration with lan IP
slaveof 192.168.10.100 6379
redis-6380.conf
# Reference public configuration
include /opt/redis/conf/redis-common.conf
# Process number record file
pidfile /var/run/redis-6380.pid
# Process port number
port 6380
# Log files
logfile "/opt/redis/log/redis-6380.log"
# Data record file
dbfilename dump-6380.rdb
# Add file name
appendfilename "appendonly-6380.aof"
# The following configuration does not need to be in 6379 Internal configuration
# The backup server is subordinate to 6379 Recommended configuration with lan IP
slaveof 192.168.32.200 6379
redis-6381.conf
include /opt/redis/conf/redis-common.conf
# Process number record file
pidfile /var/run/redis-6381.pid
# Process port number
port 6381
# Log files
logfile "/opt/redis/log/redis-6381.log"
# Data record file
dbfilename dump-6381.rdb
# Add file name
appendfilename "appendonly-6381.aof"
# The following configuration does not need to be in 6379 Internal configuration
# The backup server is subordinate to 6379 Recommended configuration with lan IP
slaveof 192.168.32.200 6379
function 3 individual redis process

see redis Server master-slave status
redis-6379
redis-6380
redis-6381
Sentinel configuration
Master slave node redis.conf To configure
reference Read / write separation The corresponding configuration of
modify sentinel-common.conf Sentinel public profile
from redis Unzip the directory to copy sentinel.conf to /opt/redis/conf/
Change the name 
Modify configuration information
Note sentinel listening process port number

Local area network IP, Otherwise, remote connection will not be possible

Set up master and slaves Password

Turn off protection mode , It is amended as follows no

Change to background start 
add to 3 A private configuration file for sentinels
touch perhaps vi Can create a blank file
touch Create a blank file directly , vi Create and enter edit mode , :wq Create success , Otherwise, do not create 
sentinel-26379.conf
# Reference public configuration
include /opt/redis/conf/sentinel-common.conf
# Process port number
port 26379
# Process number record file
pidfile /var/run/sentinel-26379.pid
# Log files ( For the convenience of viewing the log , Comment out first , After setting up the environment, open it again )
logfile "/opt/redis/log/sentinel-26379.log"
Copy sentinel-26379.conf From the content of sentinel-26380.conf , sentinel-26381.conf And modify its content , take 26379
Replace it .
Start the test
start-up 3 individual redis service 
start-up 3 A sentinel service 
See if the sentry is finished



边栏推荐
猜你喜欢

2022上半年朋友圈都在传的10本书,找到了
![[information security laws and regulations] review](/img/da/c9318ea8999c3ee629b0e48ab78581.png)
[information security laws and regulations] review

杰理之手动配对方式【篇】

Zhong Xuegao wants to remain innocent in the world

Multimodal point cloud fusion and visual location based on image and laser

Desci: is decentralized science the new trend of Web3.0?

微服务远程Debug,Nocalhost + Rainbond微服务开发第二弹

超分辨率技术在实时音视频领域的研究与实践

Responsibility chain model - unity

数据验证框架 Apache BVal 再使用
随机推荐
解决rosdep的报错问题
2022.07.02
前首富,沉迷种田
Do you know all four common cache modes?
[tpm2.0 principle and Application guide] Chapter 16, 17 and 18
Teach your sister to write the message queue hand in hand
Is AI more fair than people in the distribution of wealth? Research on multiplayer game from deepmind
3.关于cookie
Antisamy: a solution against XSS attack tutorial
For friends who are not fat at all, nature tells you the reason: it is a genetic mutation
LeetCode 515(C#)
Responsibility chain model - unity
Desci: is decentralized science the new trend of Web3.0?
如何给“不卖笔”的晨光估值?
Tips and tricks of image segmentation summarized from 39 Kabul competitions
Complete e-commerce system
DeSci:去中心化科学是Web3.0的新趋势?
How to implement safety practice in software development stage
How many times is PTA 1101 B than a
POJ 2392 Space Elevator