High availability implementation of sessionstate ~ redissessionstateprovider

Time:2021-4-18

As early as a few years ago, there was a way of sharing session with session state. Today, let’s summarize the way of sharing session with highly available redis

Construction of sentinel cluster

1

Working process diagram

2

to configure

Redis data service configuration

First, configure the master-slave server of redis and modify it redis.conf The document is as follows
Main service configuration

bind 192.168.xx.xx 192.168.xx.xx192.168.xx.xx
requirepass "123456"

From service configuration

bind 192.168.xx.xx 192.168.xx.xx192.168.xx.xx
requirepass "123456"
slaveof 192.168.xx.xx6379
masterauth 123456

Redis sentinel service configuration

There are three sentries, and the configuration of each Sentry is the same. There is one in the redis installation directory sentinel.conf A copy of the document shall be modified.

#Forbidden protection mode
protected-mode no
#Configure the master server for monitoring. Here, sentinel monitor represents monitoring, mymaster represents the name of the server, which can be customized. 192.168.11.128 represents the master server for monitoring, 6379 represents the port, and 2 represents that only two or more sentinels think that the master server is not available before the fail operation.
sentinel monitor mymaster 192.168.xx.xx 6379 2
#Sentinel author pass defines the password of the service. Mymaster is the name of the service and 123456 is the password of the redis server
sentinel auth-pass mymaster 123456

start-up

From master to slave to sentry

./redis-server ./redis.conf &
./redis-sentinel ./sentinel.conf &

Sentry group operation command

redis-cli -h 192.168.60.104 -p 26379 info sentinel
redis-cli -h 192.168.60.104 -p 26379 SENTINEL master mymaster
redis-cli -h 192.168.60.104 -p 26379 SENTINEL slaves mymaster
redis-cli -h 192.168.60.104 -p 26379 SENTINEL get-master-addr-by-name mymaster

Configuration of. Net application

Just write the address of the redis data server directly

When the main redis goes down, there will be a pause of a few seconds, and then a new master will be automatically elected

Recommended Today

Rust Study RoadMap

background In recent months, I began to learn rust, and began to write some code with rust. Now, I don’t have a deep understanding of rust, but it’s OK to write some code everyday, and I can learn the next step as needed. In the process of learning, the author also read a lot of […]