Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haproxy solr healthcheck with authentication

Tags:

haproxy

here is my config file

listen  solr 0.0.0.0:8983
mode http
balance roundrobin
option httpchk GET "/solr/select/?q=id:1234" HTTP/1.1
server solr_slave 1.1.1.1:8983 maxconn 5000 weight 256 check
server solr_master 2.2.2.2:8983 maxconn 5000 weight 1 check

the problem is that my solr server is protected using basic http password authentication and hence the health check fails always

how do i tell haproxy to use those credentials during the health checks?

like image 215
Sanket Gupta Avatar asked Nov 10 '12 20:11

Sanket Gupta


1 Answers

A little late, but I just came across the same problem, and wanted to share the solution with the world. First, you base64-encode the credentials:

$ echo -n "user:pass" | base64
dXNlcjpwYXNz

(Make sure you use the -n switch so you don't append a newline.)

The option httpchk allows you to add arbitrary HTTP headers to the request; this feature isn't documented very well. (According to this discussion, future versions of Haproxy might get a more user-friendly method.) To use basic authentication:

option httpchk GET /solr/ HTTP/1.0\r\nAuthorization:\ Basic\ dXNlcjpwYXNz

Note that I used HTTP 1.0; for 1.1, you also need a Host header.

like image 69
Mike Baranczak Avatar answered Sep 29 '22 19:09

Mike Baranczak