HAProxy image to be used with PostgreSQL HA Cluster
860
To run haproxy in docker container:
docker pull manwerjalil/haproxy:latestdocker create -it --network network_name --ip ip_address -h haproxy1 -p 5000:5000 -p 5001:5001 -p 7000:7000 --name haproxy1 haproxy:latestdocker start haproxy1docker exec -ti haproxy1 bash -c "nano /etc/haproxy/haproxy.cfg"global
log 127.0.0.1 local2
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
maxconn 100
daemon
defaults
mode tcp
log global
option tcplog
retries 3
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout check 10s
maxconn 100
listen stats
mode http
bind *:7000
stats enable
stats uri /
listen primary
bind *:5000
option httpchk OPTIONS /master
http-check expect status 200
default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
server postgres1 postgres1_ip:6432 maxconn 100 check port 8008
server postgres2 postgres2_ip:6432 maxconn 100 check port 8008
server postgres3 postgres3_ip:6432 maxconn 100 check port 8008
listen replicas
bind *:5001
balance roundrobin
option httpchk OPTIONS /replica
http-check expect status 200
default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
server postgres1 postgres1_ip:6432 maxconn 100 check port 8008
server postgres2 postgres2_ip:6432 maxconn 100 check port 8008
server postgres3 postgres3_ip:6432 maxconn 100 check port 8008
Start HAProxy
docker exec -ti haproxy1 bash -c "service haproxy start"Connect to database for writes-request from your host machine:
psql -h localhost -p 5000 -u postgresConnect to database for reads-request from your host machine:
psql -h localhost -p 5001 -u postgresContent type
Image
Digest
sha256:7c605ce1d…
Size
58 MB
Last updated
almost 4 years ago
docker pull manwerjalil/haproxy