如何设置/让 Haproxy 基于 REST 方法将来自应用程序的同一端口 5432 的读写请求发送到 postgres-patroni 集群的后端服务器。
我有三个节点的 postgres-patroni 集群作为 docker 服务/容器在 Haproxy 后面运行。我想将来自端口 5432 上的 my-application 的读取/获取请求发送到我的集群的副本,并将来自端口 5432 上的 my-application 的写入/(删除|发布|更新) 请求发送到主服务器。
我尝试使用以下配置来实现它。但目前还没有成功。
任何想法如何使 Haproxy 实现上述场景。
这是我的 Haproxy.cfg 文件
global
maxconn 100
defaults
log global
mode tcp
retries 2
timeout client 30m
timeout connect 4s
timeout server 30m
timeout check 5s
# never fail on address resolution
default-server init-addr none
resolvers docker_resolver
nameserver dns 127.0.0.11:53
listen stats
mode http
bind *:7000
stats enable
stats uri /
frontend master_postgresql
bind *:5432
acl is_post method "POST|UPDATE|DELETE"
use_backend backend_master if is_post
default_backend backend_master
frontend replicas_postgresql
bind *:5432
acl is_get method GET
use_backend backend_replicas if is_get
default_backend backend_replicas
frontend patroni_api
bind *:8008
default_backend backend_api
backend backend_master
balance source
hash-type consistent
option httpchk OPTIONS /master
server postgres1 postgres1:5432 maxconn 100 check port 8008 resolvers docker_resolver resolve-prefer ipv4
server postgres2 postgres2:5432 maxconn 100 check port 8008 resolvers docker_resolver resolve-prefer ipv4
server postgres3 postgres3:5432 maxconn 100 check port 8008 resolvers docker_resolver resolve-prefer ipv4
backend backend_replicas
option httpchk OPTIONS /replica
server postgres1 postgres1:5432 maxconn 100 check port 8008 resolvers docker_resolver resolve-prefer ipv4
server postgres2 postgres2:5432 maxconn 100 check port 8008 resolvers docker_resolver resolve-prefer ipv4
server postgres3 postgres3:5432 maxconn 100 check port 8008 resolvers docker_resolver resolve-prefer ipv4
backend backend_api
option httpchk OPTIONS /master
server postgres1 postgres1:8008 maxconn 100 check port 8008 resolvers docker_resolver resolve-prefer ipv4
server postgres2 postgres2:8008 maxconn 100 check port 8008 resolvers docker_resolver resolve-prefer ipv4
server postgres3 postgres3:8008 maxconn 100 check port 8008 resolvers docker_resolver resolve-prefer ipv4