This page describes how to set up HAProxy as a load balancer and transparent proxy for an on-premise Fredhopper installation.
| HAProxy is only available for Unix and Unix-like systems. Please contact Fredhopper for options to configure load-balancing on Windows. |
Introduction
Load-balancing FAS is required to ensure that the frontend can always access a FAS query server even when a reindex operation is currently running. Load-balancing FAS requires at least two "live instances" in addition to the indexer.
| Fredhopper recommends to use multiple servers for the FAS live instances itself to avoid a hardware failure bringing down the complete FAS service. Similarly the load balancer setup can be duplicated for additional redundancy. |
Step-by-Step Instructions
Step 1: Install HAProxy
HAProxy is available in the package repositories of the common Unix versions and Linux distributions, but can also be installed manually from the source archives.
On a RedHat-based system (RHEL, CentOS, Fedora) use yum install haproxy, on Debian-based systems (including Ubuntu) apt-get install haproxy should work.
Step 2: Create Configuration
The HAProxy configuration file consists of usually three sections: general settings, global defaults, and a section for every environment that should be available via the load balancer. A default template is available in the Fredhopper installation directory as config/fredhopper-haproxy.default.cfg.
Start by copying this example file to config/fredhopper-haproxy.cfg, and open it for editing in a text editor.
Global and Default Settings
The common configuration and defaults could look like this:
global # log 127.0.0.1 local0 local1 local5 notice info # maxconn <num> # nbproc 1 user fredhopper group fredhopper pidfile /home/fredhopper/fredhopper/tmp/fredhopper-haproxy.pid log 127.0.0.1 user info # stats socket /home/fredhopper/fredhopper/tmp/fredhopper-haproxy.socket user fredhopper group fredhopper level admin defaults log global mode http option httplog option dontlognull option allbackups option redispatch option log-separate-errors # Options used with 1.5+ to improve performance # option tcp-smart-accept # option tcp-smart-connect # option splice-auto option abortonclose retries 3 maxconn 2000 contimeout 5000 clitimeout 60000 srvtimeout 60000 grace 100
| The default configuration assumes that Fredhopper is installed in /home/fredhopper/fredhopper, and that the Fredhopper user is called 'fredhopper'. |
Environment-specific settings
The environment-specific settings are derived from the config/topology.txt, and link all live instances of a particular environment to be available using haproxy. In this example the config/topology.txt file looks like this:
# See https://www.fredhopper.com/learningcenter/x/BAobAQ for more # information about the contents of this file. # # instance name | host | preset | indexer | comment demo|192.0.2.1|1|-|Indexer and Preview environment for demo setup demolive1|192.0.2.2|1|demo|Live Query Server for demo setup demolive2|192.0.2.3|1|demo|Live Query Server for demo setup
The load balancer should be available at http://192.0.2.1:8080, and balance over the demolive1 and demolive2 instances of the demo environment.
|
Load-Balancing for the Indexer The indexer instance should not be included in the load balancer configuration together with the live instances, as it contains the unpublished configuration. |
For each environment a section like this needs to be added to the config/fredhopper-haproxy.cfg file:
listen query localhost:8080 balance leastconn option httpchk GET /status/ # Server templates: # server NAME HOST:PORT check inter 3000 rise 2 fall 3 maxconn 50 [weight INTEGER] [backup] server demolive1 192.0.2.2:8180 check inter 3000 rise 2 fall 3 maxconn 50 server demolive2 192.0.2.3:8180 check inter 3000 rise 2 fall 3 maxconn 50
|
Load Balancing Strategy HAProxy supports multiple strategies for load-balancing, the example uses the "leastconn" strategy as it distributes load based on the number of currently running queries on each server, avoiding uneven server load due to query processing time differences. |
Step 3: Configure FAS
FAS needs to be able to connect to itself in certain situations, for example for accessing parts of the Business Manager. If FAS is queried directly it determines its own address based on the query, but a load balancer or transparent proxy can interfere with this logic.
This logic can be disabled by configuring each FAS explicitly to point to itself for queries by setting an option:
| Option | Value |
|---|---|
| /com/fredhopper/transformservlet/TransformServlet/@xml-url-server-port | Port of the query server (8180, 9180, ...) |
Execute the following command for each instance of the environment, replacing HOST, INSTANCE and PORT according to the settings from config/topology.txt.
bin/deployment-agent-client --location HOST set-option INSTANCE /com/fredhopper/transformservlet/TransformServlet/@xml-url-server-port=PORT
|
Determining the correct port For FAS 7.1 and earlier the port is typically calculated as "instance number" * 1000 + 7180, so that instance 1 would use port 8180, instance 2 would use port 9180, etc. For FAS 7.2 and later the port can be determined using this command: bin/deployment-agent-client --location HOST get-option INSTANCE qserver_http_port |
Step 4: Start HAProxy
The following command is used to start haproxy as a daemon process using the config/fredhopper-haproxy.cfg configuration file:
haproxy -D -q -f /home/fredhopper/fredhopper/config/fredhopper-haproxy.cfg
|
Debugging When testing the configuration it is helpful to see some verbose messages from haproxy on the console rather than have it run as a daemon. This can be achieved by starting haproxy in the foreground: haproxy -d -f /home/fredhopper/fredhopper/config/fredhopper-haproxy.cfg |
Step 5: Test
Ensure that all FAS instances are running first. It should then be possible to open the preview pages of FAS using the load balancer IP and port, for example http://192.0.2.1:8080/preview. If this is correctly working you can execute a bin/fresh-index-to-live INSTANCE. While this is running haproxy should continue to answer queries, and should print information about servers "going up" and "going down" in the order in which the fresh-index-to-live proceeds to update them.
Step 5: Enable HAProxy to run continuously
As a last step haproxy should be configured to run at boot time as a service.
Comments
0 comments
Please sign in to leave a comment.