haproxy failover active-passive - load-balancing

i want to setup haproxy to switch to passive s2 after s1 fails but not to back to s1 when it gets healthy. i mean when switches to s2 if the s1 gets available, haproxy still send requests to s2 and s1 work as passive until failure of s1.
haproxy configuration :
listen http_web 192.168.1.3:80
mode http
balance roundrobin
option httpchk
option forwardfor
server server1 192.168.1.1:80 weight 1 maxconn 512 check backup
server server2 192.168.1.2:80 weight 1 maxconn 512 check backup
i set backup for both servers but when s1 fails haproxy send requests to s2 but when s1 gets back available it sends requests to s1 again.

round robin balancing mode, means that both servers will get requests one by one.
If you want persistence, you should use source method or add cookies.
Otherwise, if you don't need a load balacing feature and just active passive solution. You can use keepalived service ;)

Related

HaProxy - group tcp and http hosts dependent of each other

I have the following scenario:
Haproxy is running in front of my two groups of servers:
two http servers (active / backup)
two tcp servers (active / backup)
I now want to fail over from the active sides to the backup ones of ANY of the active services goes down (fail over HTTP and TCP at the same time).
Is there any way to do so in HAproxy? I so far was only able to fail over to one of them depending on the protocol but not both. Can these be grouped?
i was wondering if the can be done via ACLs and things like the fe_conn directive
I think haproxy's nbsrv works here. If your nbsrv count, number of healthy instances, falls below desired amount on EITHER pool switch both pools to the backup backend. Otherwise just use the default pool. Here is an example verified on 1.5.18 but should work fine on newer versions:
defaults all
timeout connect 30s
timeout client 30s
timeout server 30s
mode http
# http frontend
frontend http *:80
# use the backup service if EITHER service is down
acl use_backup nbsrv(http_service) lt 1
acl use_backup nbsrv(tcp_service) lt 1
use_backend http_service_backup if use_backup
default_backend http_service
# tcp frontend
frontend tcp_10000 *:10000
mode tcp
# use the backup service if EITHER service is down
acl use_backup nbsrv(http_service) lt 1
acl use_backup nbsrv(tcp_service) lt 1
use_backend tcp_service_backup if use_backup
default_backend tcp_service
backend tcp_service
mode tcp
# main tcp instance here
# can also include backup server here with backup directive if desired
server tcp-service1 tcp-service1.local:10000 check
backend tcp_service_backup
mode tcp
# backup tcp instance here
server tcp-service2 tcp-service2.local:10000 check
backend http_service
# main http instance here
# can also include backup server here with backup directive if desired
server http-service1 http-service1.local:80 check
backend http_service_backup
# backup http instance here
server http-service2 http-service2.local:80 check
See https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#nbsrv for more nbsrv details.

HAProxy, session sticky and balance algorithm

I got a HAProxy with basic configuration as below:
frontend fe_http
bind *:80
default_backend be_http
capture request header AWESOME-HEADER len 40
backend be_http
mode http
option forwardfor
balance hdr(AWESOME-HEADER)
stick-table type string len 40 size 5M expire 1m
stick on hdr(AWESOME-HEADER)
server s1 x.x.x.x1:8080 check
server s2 x.x.x.x2:8080 check
According to balance hdr(AWESOME-HEADER), requests with same AWESOME-HEADER will go to same server, and my test confirms that.
This is so called "session sticky", right? So, do we still need stick-table and stick on lines? (I do try to remove these 2 lines, and HAProxy still performs like session sticky as I expected)
Thanks.

RabbitMQ HA & Failover

I've read both the clustering and HA chapters and got a fair understanding on RabbitMQ clustering. One thing I did not understand is, having 2+ nodes on the cluster and a set of HA queues, how connections can be made by the clients so that if one node fails they automatically and seamlessly connect to the remaining node(s). Can this be achieved by a load balancer such as, say, Amazon ELB for deployments made in AWS?
Using a load balancer like Amazon ELB or HAProxy is exactly how you should route traffic to the available nodes in the Rabbit cluster.
I'd recommend HAProxy. Here's a sample HAProxy config:
global
log 127.0.0.1 local1
maxconn 4096
#chroot /usr/share/haproxy
user haproxy
group haproxy
daemon
#debug
#quiet
defaults
log global
mode tcp
option tcplog
retries 3
option redispatch
maxconn 2000
timeout connect 5000
timeout client 50000
timeout server 50000
listen stats :1936
mode http
stats enable
stats hide-version
stats realm Haproxy\ Statistics
stats uri /
listen aqmp_front :5672
mode tcp
balance roundrobin
timeout client 3h
timeout server 3h
option clitcpka
server aqmp-1 rabbitmq1.domain:5672 check inter 5s rise 2 fall 3
server aqmp-2 rabbitmq2.domain:5672 backup check inter 5s rise 2 fall 3
Note the last two lines. You'll need to substitute rabbitmq1.domain and rabbitmq2.domain with the location of your two nodes. Since the second server is setup as backup check HAProxy will balance the request only on the first node, and if this node fails the request will be route to the second node.
I would use simple keepalived deamon on all rabbit nodes. It just adds a virtual IP address shared between nodes which you can use for client access. Configuration is very simple, check this Hollenback's page.
Sample config:
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 1
priority 100
virtual_ipaddress {
192.168.1.1/24 brd 192.168.1.255 dev eth0
}
}
You have to configure mirror queue between rabbitmq-servers.
rabbitmqctl set_policy HA '^(?!amq\.).*' '{"ha-mode": "all"}'
In the example rabbitmq will be mirror queue have prefix with amq. When server A fail, those queue unitl exit on server B. You also HA on code(connect to server fail, then connect to server B) or using HA rabbitmq port using keepalive

Plone taking a long time to respond to byte-range request

We have two recently upgraded Plone 4.3.2 instances behind a haproxy load balancer which itself is behind Apache.
We limit each Plone instance to serving two concurrent requests using haproxy configuration.
We recently encountered an issue whereby a client sent 4 byte-range requests in quick succession for a PDF that each took between 6 and 8 minutes to get a response. This locked up all available requests for 6 minutes and so haproxy timed out other requests in the queue. The PDF is stored an ATFile object in Plone which I believe should have been migrated to blob storage in our recent upgrade.
My question is what steps should we take to prevent a similar scenario in the future?
I'm also interested in:
how to debug why the byte-range requests on an otherwise lightly loaded server should take so long to respond
how plone.app.blob deals with byte-range requests
is it possible to configure Apache such that byte-range requests are served from its cache but not from the back-end server
As requested here is the haproxy.cfg with superfluous configuration stripped out.
global
maxconn 450
spread-checks 3
defaults
log /dev/log local0
mode http
option http-server-close
option abortonclose
option redispatch
option httplog
timeout connect 7s
timeout client 300s
timeout queue 120s
timeout server 300s
listen cms 127.0.0.1:18181
id 3
balance leastconn
option httpchk
http-check send-state
timeout check 10s
acl cms_edit url_dom xxx.xxx.xxx.xxx
acl cms_not_ok nbsrv() lt 2
block if cms_edit cms_not_ok
server cms_instance1 app:18081 check downinter 10s maxconn 2 rise 1 slowstart 300s
server cms_instance2 app:18082 check downinter 10s maxconn 2 rise 1 slowstart 300s
You can install https://pypi.python.org/pypi/Products.LongRequestLogger and check its log file to see where the request gets stuck.
I've opted to disable byte-range requests to the back-end Zope server. I've added the following to the CMS listen section in haproxy.
reqidel ^Range:.*

How to do sticky load-balancing with HAProxy with Session transfer to new servers

I am using appsession config element for sticky session. I have 5 weblogic instances 3 of them are active and serving load now when load increases i start additional 2 instances. Now HAProxy marks them "Helthy" but does not transfer any traffic to it because it sticky.
How do I transfer existing sessions to new weblogic servers. I am using Terracotta for session clustering so it does not matter which server is serving the request. Below is my config for HAProxy.
# this config needs haproxy-1.1.28 or haproxy-1.2.1
global
log 127.0.0.1 local0
maxconn 1024
daemon
# debug
#quiet
defaults
log global
mode http
option httplog
option httpchk
option httpclose
retries 3
option redispatch
contimeout 5000
clitimeout 50000
srvtimeout 50000
stats uri /admin?stats
stats refresh 5s
listen terracotta 0.0.0.0:10001
# balance url_param JSESSIONID
balance roundrobin
option httpchk OPTIONS /Townsend
server L1_1 10.211.55.1:7003 check
server L1_2 10.211.55.2:7004 check
server L1_3 10.211.55.3:7004 check
appsession JSESSIONID len 52 timeout 3h
Then if it does not matter which server serves the request, disable stickiness and remove the appsession line. You must understand that stickiness is the opposite of load-balancing. If your issue is that you don't scale, don't stick first.