我尝试为patroni(postgresql)数据库创建nginx tcp代理。
15432 - postgresql
8008 - patroni, HTTP 200 如果可以,所有其他 - 错误
对于工作,我使用ngx_stream_core_module和ngx_stream_upstream_check_module。 对于我创建的每个节点
stream {
...
upstream db {
server 127.0.0.1:15432;
check interval=3000 rise=2 fall=5 timeout=1000 port=8008 type=http;
check_http_send "HEAD / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
server {
listen 15434;
proxy_bind 127.0.0.1;
proxy_connect_timeout 4s;
proxy_timeout 100s;
proxy_pass db;
#return 444;
}
...
}
群集配置
upstream db_cluster {
server 192.168.8.201:15434 max_fails=3 fail_timeout=10s;
server 192.168.8.202:15434 max_fails=3 fail_timeout=10s;
}
server {
listen 5432;
proxy_connect_timeout 100s;
proxy_timeout 100s;
proxy_pass db_cluster;
}
但是当所有上游都死了,我需要返回tcp拒绝(或者另外考虑另一个)吗?