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

How to implement Nginx proxy Redis sentinel master-slave configuration

王林
王林forward
2023-05-27 14:03:381839browse

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;
    }
}

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;
    }
}

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;
    }
}

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete