Nginx版本:1.21.6
Center7.5及以上或Mas OS
建構Redis哨兵主從模式
Springboot整合Redis哨兵主從模式
提示:Nginx必須安裝upstream模組
Nginx設定有三個方案(詳見後續內容),其中:方案一將哨兵所有節點使用一個連接埠對外映射;方案二是每個哨兵端口配置一個對應的映射端口,總體和正常哨兵配置方式無差別;方案三其實就是方案一和方案二的結合體。個人認為其意義不大,有興趣的小夥伴可以自行嘗試。
# 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; } }
# 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; } }
# 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; } }
以上是Nginx代理Redis哨兵主從配置怎麼實現的詳細內容。更多資訊請關注PHP中文網其他相關文章!