Implement a new Front End on HAProxy

In some cases you may need to implement a new Front End in your load balancer config. For example, if you want to send traffic to a different set of backend nodes or you need to add a new SSL certificate. You will need one frontend per SSL certificate.

To create a new frontend you can duplicate an existing one and change the settings.

1.Change directory to the HAProxy root.

james@primary:~$ cd /etc/haproxy

2. Take a look at the config file to see what you need to copy

james@primary:~$ cat haproxy.cfg

3. Before making any changes take a backup of the existing config.

james@primary:~$ sudo cp haproxy.cfg haproxy{INSERT DATE HERE}.cfg 

4. Open the config file with an elevated VIM editor

james@primary:~$ sudo vim haproxy.cfg

5. Select the section which starts “frontend”. Selecting it will copy to the clipboard.

Here is an example section:
frontend

6. Copy and paste the section to the bottom of the config file by right clicking on the putty window

7. Edit the section updating any IP addresses, SSL certificates and changing the name.

Here is an example:
frontend2

8. Save and quit out of Vim by typing Esc then :wq

9. Check you configuration is valid by running the following command

james@primary:~$ haproxy -f /etc/haproxy/haproxy.cfg -c

valid

10. Next we need to add the IP Address to haresources file.

james@primary:/etc/haproxy$ sudo vim /etc/heartbeat/haresources

haresources
11. Save and quit out of Vim by typing Esc then :wq

12. Once you have updated the haresources files with the IP Address the front end should start to work. I have found it can take a short while to start working.

To speed up the process (BEWARE IN PRODUCTION ENVIRONMENTS) you can restart the Heartbeat process

james@primary:/etc/haproxy$ sudo service heartbeat restart
james@primary:/etc/haproxy$ sudo service heartbeat status

heartbeat

Advertisements
Tagged with: , ,
Posted in HAProxy, Linux

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: