Posted in Servers onJuly 15, 2022
一、环境
Nginx版本:1.21.6
Center7.5及以上或Mas OS
提示:Nginx必须安装upstream模块
二、配置
Nginx配置有三个方案(详见后续内容),其中:方案一将哨兵所有节点使用一个端口对外映射;方案二是每个哨兵端口配置一个对应的映射端口,总体和正常哨兵配置方式无差别;方案三其实就是方案一和方案二的结合体。个人认为其意义不大,有兴趣的小伙伴可以自行尝试。
2.1、方案一(推荐)
# 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、方案二
# 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、方案三
# 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哨兵主从配置的实现的文章就介绍到这了,更多相关Nginx代理Redis哨兵主从内容请搜索三水点靠木以前的文章或继续浏览下面的相关文章希望大家以后多多支持三水点靠木!
Nginx代理Redis哨兵主从配置的实现
- Author -
Rewloc- Original Sources -
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Tags in this post...
Reply on: @reply_date@
@reply_contents@