当前位置:网站首页>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 .

Create three directories ( Data files 、 Log files 、 The configuration file )

 Insert picture description here

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

 Insert picture description here

modify redis-common.conf Public profile

Comment out bind 127.0.0.1

 Insert picture description here

Turn off protection mode , It is amended as follows no

 Insert picture description here

Comment public configuration port

 Insert picture description here

Change to background start

 Insert picture description here

Note process number record file

 Insert picture description here

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
 Insert picture description here

Add authentication from server to master server

 Insert picture description here

Add access authentication

 Insert picture description here

Comment public configuration append file

 Insert picture description here

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
 Insert picture description here

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

 Insert picture description here

see redis Server master-slave status

redis-6379
 Insert picture description here
redis-6380
 Insert picture description here
redis-6381
 Insert picture description here

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/
 Insert picture description here
Change the name
 Insert picture description here

Modify configuration information

Note sentinel listening process port number

 Insert picture description here

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

 Insert picture description here

Set up master and slaves Password

 Insert picture description here

Turn off protection mode , It is amended as follows no

 Insert picture description here

Change to background start  Insert picture description here

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
 Insert picture description here
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
 Insert picture description here
start-up 3 A sentinel service
 Insert picture description here

See if the sentry is finished

 Insert picture description here
 Insert picture description here
 Insert picture description here

原网站

版权声明
本文为[Poetic elegance]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071515007543.html