Balance multiple View Connection Servers using HAProxy

0 Flares Twitter 0 Facebook 0 LinkedIn 0 Email -- 0 Flares ×

In medium and large deployments, you can distribute the load on VMware View Connection Server by adding many of them thanks to the “Replica” role. However, the balance and failover between them is not available directly inside the software. To distribute View clients among them, you need an external balancer.

VMware has its own way of doing it, by leveraging balancing features of VCNS (VMware vCloud Networking & Security, formerly known as vShield Edge). However, I always find myself more at ease with HAProxy. This program is really small on memory, and has neat features like SSL offloading, multiple algorythms for load balancing and others.

HAProxy can work on a single linux machine, balancing multiple backend servers, but for a real HA deployments, is better to deploy at least 2 nodes, with a virtual IP address managed by another great program, Keepalived. For my deployments, I use CentOS 6, so this tutorial will be based on this linux distribution. The network has these machines and IP addresses:

hostnameIP AddressNote
lb1.domain.local192.168.1.162Load Balancer 1, master
lb2.domain.local192.168.1.163Load Balancer 2, slave
view.domain.local192.168.1.170Virtual IP managed by balancers
view01.domain.local192.168.1.165View Connection Server
view02.domain.local192.168.1.166View Connection Server (Replica)

HAProxy can work both with 1 or 2 network connections, in this example all the servers will be connected on the same network.

First we need to activate the Extra Packages for Enterprise Linux (EPEL) repository, which should host packages of the HAProxy and Keepalived software. Install EPEL repo info into YUM:

Now we will install the HAproxy and Keepalived software:

Edit the Keepalived config file and make it look something like below:

 

A quick explanation on the parameters you see in this configuration file:

  • Keepalived uses VRRP to manage the virtual IP between the balancers. VRRP is an active/passive system, so at any given time the virtual IP is listening only on one of the balancers. This makes the use of keepalived more “network friendly” since the IP is up only on one servers, so there is no need for dedicated configurations
  • the proper VRRP configuration is wrapped inside a check script that monitors the status of HAProxy, this is vital to guarantee a working configuration. There is in fact no use in having the virtual IP listening on a balancer where for some reason HAProxy is dead. So, if HAProxy check fails, the script failovers the virtual IP to the other balancer, where HAProxy is supposed to be running.
  • Priority is 101 on master, and 100 on all other slaves. Remember to change this value when you copy the configuration on the slave nodes.
  • to protect the communications between nodes, you should use a password. This is a pre-shared key you would need to configure on every balancer.
Before you can load the virtual IP and test it, there are some other configuration changes to be made. First, add this line at the end of the /etc/sysctl.conf file:

and apply the new parameter by executing:

Extra configuration of iptables is required for keepalived, in particular we must enable support for multicast broadcast packets:

Then, add this rule for the VRRP IP protocol:

In addition insert a rule that will correspond with the traffic that you are load balancing, for View is HTTP and HTTPS (by default is only https, but I’m going to create a rule inside HAProxy to redirect http calls to https):

Finally save the iptables config so it will be restored after restarting, and start Keepalived:

Once you configured both balancers, you can see the virtual IP listening on the master node:

If you run the same command on the slave node, there will be only the physical IP. You can test the virtual IP by pinging it, and stopping keepalived service on the master node. You would maybe see a failed ping (depending on the speed of the underlying network infrastructure), and then the ping replies will come back to you from the slave node. Once you will restart Keepalived on the master, it will regain control of the virtual IP.

Cool! Let’s move on to HAProxy configuration:

Let’s look in details at the last three sections, the first part are common configurations:

  • “frontend unsecured” is a simple redirect, it intercepts every connection attempt to port 80 (http) and redirects it to 443 (https). So even lazy users forgetting to write https in the url will get a correct connection instead of a 404 error.
  • “frontend secured” is the real frontend. It listen on the virtual IP, on port 443. If you want to issue a dedicated SSL certificate for the hostname “view.domain.local”, you can use OpenSSL to create a certificate request, and once you have the PEM file, you can save it into both balancers and remove the comment to enable it
  • backend “view” holds the configuration of the balanced servers. Balancing mode is “source”: every source IP address will be always redirected to the same Connection Server as long as that Connection Server is alive (check port 443 is used right to verify View is listening). Source is a good configuration for connections coming from many different source IPs like View clients. Be careful if connections are redirected by NAT systems or other network services, source does not work well when there are few source IPs.

Once everything is configured, enable HAProxy and Keepalived to start automatically on system boot and start HAProxy:

You will be able to connect to https://view.domain.local and see one of your View Connection servers.