Skip to content
This repository was archived by the owner on Nov 18, 2017. It is now read-only.

Commit 0463180

Browse files
committed
add a haproxy router for a single connection point
1 parent d3f96ad commit 0463180

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ From there, you will see a high-availability cluster start up. Test
1414
different settings in the YAML files to see how behavior changes. Kill
1515
some of the different components to see how the system behaves.
1616

17+
To get a haproxy load balancing between these two hosts, run:
18+
19+
```
20+
> haproxy -f haproxy.cfg
21+
> sh haproxy_status.sh 127.0.0.1 5432 15432
22+
> sh haproxy_status.sh 127.0.0.1 5433 15433
23+
```
24+
1725
# Requirements on a Mac
1826

1927
Run the following on a Mac to install requirements:

haproxy.cfg

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
global
2+
maxconn 100
3+
4+
defaults
5+
log global
6+
mode tcp
7+
retries 2
8+
timeout client 30m
9+
timeout connect 4s
10+
timeout server 30m
11+
timeout check 5s
12+
13+
frontend ft_postgresql
14+
bind *:5000
15+
default_backend bk_db
16+
17+
backend bk_db
18+
option httpchk GET
19+
20+
server postgresql_127.0.0.1_5432 127.0.0.1:5432 maxconn 100 check port 15432
21+
server postgresql_127.0.0.1_5433 127.0.0.1:5433 maxconn 100 check port 15433

haproxy_status.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
while true
4+
do {
5+
response=$(echo "SELECT pg_is_in_recovery();" | psql -t postgres --port $2 --host $1 2> /dev/null)
6+
7+
if [ "${response}" == " f" ]
8+
then
9+
echo "HTTP/1.1 200 OK"
10+
echo "X-XLOG-POSITION: $(echo "SELECT pg_current_xlog_location();" | psql -t postgres 2> /dev/null | tr -d ' ' | head -n 1)"
11+
else
12+
echo "HTTP/1.1 503 Service unavailable"
13+
echo "X-XLOG-POSITION: $(echo "SELECT pg_last_xlog_replay_location();" | psql -t postgres 2> /dev/null | tr -d ' ' | head -n 1)"
14+
fi
15+
16+
} | nc -l $3; done

0 commit comments

Comments
 (0)