Greetings to Olanis, HAProxy Technologies partner in Germany, for the idea and the content of this article.

Synopsis

You (or your clients) want to deliver video using the RTMP protocol, and of course you want a reliable architecture!
On the server side, you can use crtmpserver to deliver videos over rtmp.
One of the advantage of crtmpserver is that it runs well on small systems.
And to build the reliable and scalable part of the architecture, why not using HAProxy or the ALOHA appliance?

The architecture

To make it simple, let’s consider we have a single load-balancer which balance traffic to 3 media servers.
We’ll configure the load-balancer in transparent proxy mode.
No need to draw a diagram to understand how things are connected together 😉

HAProxy Configuration for RTMP

By default, RTMP works over TCP 1935 port. So HAProxy configuration will be configured in TCP mode, like below.
media03 has a lower weight because it is used by clients to upload their videos, which are synchronized to other servers.
[sourcecode language=”text”]
frontend ft_rtpm
bind <public ip>:1935 name rtmp
mode tcp
maxconn 600
default_backend bk_rtmp

backend bk_rtmp
mode tcp
balance roundrobin
stick store-request src
stick-table type ip size 200k expire 20m
stick on src
source 0.0.0.0 usesrc clientip
server media01 10.0.0.1:1935 check maxconn 200 weight 10
server media02 10.0.0.2:1935 check maxconn 200 weight 10
server media03 10.0.0.3:1935 check maxconn 200 weight 8
[/sourcecode]

HAProxy Configuration for RTMP over HTTP

Some firewall may not allow port 1935, so there is a failover solution: delivering RTMP over HTTP (or even HTTPs), on regular TCP port 80:
[sourcecode language=”text”]
frontend rtmp-80
bind <public ip>:80
mode tcp
maxconn 600
default_backend rtmp-over-http

backend rtmp-over-http
mode tcp
balance roundrobin
stick store-request src
stick-table type ip size 200k expire 20m
stick on src
source 0.0.0.0 usesrc clientip
server media01 10.0.0.1:1935 check maxconn 200 weight 10
server media02 10.0.0.2:1935 check maxconn 200 weight 10
server media03 10.0.0.3:1935 check maxconn 200 weight 8
[/sourcecode]

Links