Home > Database > Redis > How to implement Nginx proxy Redis sentinel master-slave configuration

How to implement Nginx proxy Redis sentinel master-slave configuration

王林
Release: 2023-05-27 14:03:38
forward
1915 people have browsed it

1. Environment

Nginx version: 1.21.6
Center7.5 and above or Mas OS
Build Redis Sentinel master-slave mode
Springboot integrates Redis Sentinel master-slave mode

Tips: Nginx must install the upstream module

2. Configuration

There are three options for Nginx configuration (see subsequent content for details), among which: option 1 will use one port for all sentinel nodes to connect to the outside world. Mapping; Option 2 is to configure a corresponding mapped port for each sentinel port, and there is no difference between the normal sentinel configuration method; Option 3 is actually a combination of Option 1 and Option 2. Personally, I don’t think it makes much sense, and interested friends can try it on their own.

2.1. Option 1 (recommended)

# stream模块配置和http模块在相同级别
stream {
    upstream redis {
        server 127.0.0.1:26379 max_fails=3 fail_timeout=10s;
        server 127.0.0.1:26380 max_fails=3 fail_timeout=10s;
        server 127.0.0.1:26381 max_fails=3 fail_timeout=10s;
    }
    server {
        listen 5432;
        proxy_connect_timeout 30s;
        proxy_timeout 60s;
        proxy_pass redis;
    }
}
Copy after login

2.2. Option 2

# stream模块配置和http模块在相同级别
stream {
    upstream redis {
        server 127.0.0.1:26379 max_fails=3 fail_timeout=10s;
    }
    upstream redis1 {
        server 127.0.0.1:26380 max_fails=3 fail_timeout=10s;
    }
    upstream redis2 {
        server 127.0.0.1:26381 max_fails=3 fail_timeout=10s;
    }
    server {
        listen 5432;
        proxy_connect_timeout 30s;
        proxy_timeout 60s;
        proxy_pass redis;
    }
    server {
        listen 5433;
        proxy_connect_timeout 30s;
        proxy_timeout 60s;
        proxy_pass redis1;
    }
    server {
        listen 5434;
        proxy_connect_timeout 30s;
        proxy_timeout 60s;
        proxy_pass redis2;
    }
}
Copy after login

2.3. Option 3

# stream模块配置和http模块在相同级别
stream {
    upstream redis {
        server 127.0.0.1:26379 max_fails=3 fail_timeout=10s;
        server 127.0.0.1:26380 max_fails=3 fail_timeout=10s;
        server 127.0.0.1:26381 max_fails=3 fail_timeout=10s;
    }
    upstream redis1 {
        server 127.0.0.1:26380 max_fails=3 fail_timeout=10s;
        server 127.0.0.1:26379 max_fails=3 fail_timeout=10s;
        server 127.0.0.1:26381 max_fails=3 fail_timeout=10s;
    }
    upstream redis2 {
        server 127.0.0.1:26381 max_fails=3 fail_timeout=10s;
        server 127.0.0.1:26380 max_fails=3 fail_timeout=10s;
        server 127.0.0.1:26379 max_fails=3 fail_timeout=10s;
    }
    server {
        listen 5432;
        proxy_connect_timeout 30s;
        proxy_timeout 60s;
        proxy_pass redis;
    }
    server {
        listen 5433;
        proxy_connect_timeout 30s;
        proxy_timeout 60s;
        proxy_pass redis1;
    }
    server {
        listen 5434;
        proxy_connect_timeout 30s;
        proxy_timeout 60s;
        proxy_pass redis2;
    }
}
Copy after login

The above is the detailed content of How to implement Nginx proxy Redis sentinel master-slave configuration. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template