HAProxy use urls in server config?
Right now, my config looks like this:
server node1 10.20.x.y:80 check
server node2 10.20.x.y:80 check
server node3 10.20.x.y:80 check
What would be the best way to use URLS here instead of IPs?
Something like (But this does not seem to work):
server node1 url-1.google.com:80 check
server node2 url-2.google.com:80 check
server node3 url-3.google.com:80 check
When you want to use hostnames rather than IP-addresses that is called DNS resolution in HAproxy jargon. You will need to specify a "resolvers" section where you configure DNS. For instance:
resolvers mydns
nameserver dns1 10.0.0.1:53
nameserver dns2 10.0.0.2:53
resolve_retries 3
timeout resolve 1s
timeout retry 1s
hold other 30s
hold refused 30s
hold nx 30s
hold timeout 30s
hold valid 10s
hold obsolete 30s
Then you must precise one resolvers
parameter on each server line where DNS
resolution is required.
server s1 app1.example.com:80 resolvers mydns resolve-prefer ipv6
Extra Credit Rather than enumerating each node in your config you can also use a round-robin DNS record in your URL. That means you can also reduce the configuration changes needed when you add/remove nodes from your cluster to only changing the DNS record.
A DNS record would then look like:
app1.example.com. IN A 192.0.2.1
app1.example.com. IN A 192.0.2.2
app1.example.com. IN A 192.0.2.3