How-to use HAProxy with Wowza

This is a starter guide on how to implement HAProxy with Wowza. There are various deployments around the ‘net that suggest this integration is successful. Despite the obvious bandwidth bottleneck, you can couple several instances of this load balancer together to make a scalable solution. This guide, uses CentOS 6.5 as a test bed.

First you will want to ensure your Wowza server has enabled ports 554, 1935, and 80 within your VHost.

Bash Script: haproxy-install.sh

#!/bin/bash
#Update yum repos if desired
#yum update

# Good idea to ensure this property is set
echo “net.ipv4.ip_nonlocal_bind = 1″ >> /etc/sysctl.conf
sysctl -p

#turn off iptables for this example only
/etc/init.d/iptables save
/etc/init.d/iptables stop
chkconfig iptables off

# restart network
service network restart

# install haproxy
yum install haproxy -y
service haproxy restart

Run this bash script:

sh ./haproxy-install.sh

Now as a basic starter configuration, change your /etc/haproxy/haproxy.cfg as follows:

defaults
    mode http
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s

frontend http-554
        bind [your-public-lb-ip]:554
        mode tcp
        maxconn 600
        default_backend over-rtsp

frontend http-80
        bind [your-public-lb-ip]:80
        mode tcp
        maxconn 600
        default_backend over-http

frontend rtmp-1935
        bind [your-public-lb-ip]:1935
        mode tcp
        maxconn 600
        default_backend over-rtmp

backend over-http
        mode tcp
        balance roundrobin
        stick store-request src
        stick-table type ip size 200k expire 20m
        stick on src
        server mediaHTTP4 [your-private-wowza-ip]:80 weight 10 

backend over-rtmp
        mode tcp
        balance roundrobin
        stick store-request src
        stick-table type ip size 200k expire 20m
        stick on src
        server mediaRTMP4 [your-private-wowza-ip]:1935 weight 10 

backend over-rtsp
        mode tcp
        balance roundrobin
        stick store-request src
        stick-table type ip size 200k expire 20m
        stick on src
        server mediaRTSP4 [your-private-wowza-ip]:554 weight 10 

listen admin
    bind *:8080
    stats enable

Now restart haproxy as follows:

service haproxy restart

Provided this is successful, you should likely be able to see the basic stat provider as follows:

http://[your-haproxy-ip]:8080/haproxy?stats

Now you should be able to point your players at the lb IP for playback similar to the following:

RTMP

rtmp://[your-public-lb-ip]:1935/[app]/[streamname]

HLS

http://[your-public-lb-ip]:1935/[app]/[streamname]/playlist.m3u8


Comments are closed.