Skip to main content
Version: 2.17

How to Setup Ant Media Server Cluster on Azure

This guide explains how to set up Ant Media Server clustering on Azure. When a single server can’t handle high traffic, a cluster allows you to manage the load efficiently.

For streaming applications with many publishers and viewers, a clustering solution becomes essential—especially when ultra-low latency and adaptive bitrate are required. WebRTC, which enables ultra-low latency, is CPU-intensive, and adaptive bitrate processing involves real-time video conversion, which also demands significant CPU resources. Fortunately, Ant Media Server Enterprise Edition supports clustering, allowing you to distribute the load across multiple servers and handle high traffic efficiently.

Requirements

To set up the Ant Media Server, having an Azure account and a ready AntMedia Server Image are needed.

  • The architecture of the cluster setup can be found here.

  • Introduction to clustering with AntMedia Server can be found here.

Let's proceed for the cluster deployment.

Step 1: Create a Resource Group

  • Each resource created must be in the same resource group. For this, we will first create a resource group. Named antmedia-cluster

  • From the left-hand menu, go to Resource Groups and click + Add to create a new group.

  • Enter Resource group then choose your zone

  • Proceed by clicking Create button

Step 2: Create a Virtual Network

We need to create a virtual network named antmedia-cluster-virtual-network, then we will add gateway-subnet, origin-subnet, and edge-subnet.

  • In the portal’s upper-left corner, click Create a Resource. In the Search the Marketplace box at the top of the New pane, type Virtual Network. When it appears in the search results, click Virtual Network

  • Click Create

  • Select the resource group that we created before, enter antmedia-cluster-virtual-network in the name field, and click on the "Next: IP Address" button.

  • Click on the Add subnet button and create the antmedia-origin-subnet, antmedia-edge-subnet, and antmedia-gw-subnet as shown in the figure below.

  • The process is completed by clicking on the "Create" button.

Step 3: Create a MongoDB Virtual Machine

  • Click Virtual Machines on the left bar and then click "+Add"

  • Enter the following values and click "Next: Disks"

    • Resource group "antmedia-cluster"
    • Image "Ubuntu 18.04 LTS"

  • Enter the following values and click "Next: Networking"

  • Select the Virtual Network that you created, click "Advanced" from "Nic network security group" and click "Create new"

  • Click the "Add an inbound rule" button in the windows that appear and click the "Add inbound security rule" button

  • Enter the following values and click "Next: Advanced"

  • Add the following lines to the "Custom data" area and click the "Review + Create" button to create a MongoDB instance.

    #!/bin/bash
    wget https://raw.githubusercontent.com/antmedia/Scripts/master/install_mongodb.sh && chmod +x install_mongodb.sh
    ./install_mongodb.sh

  • The process is completed by clicking on the "Create" button.

Step 4: Create Application Gateway

  • Click Create a Resource in the portal which is on the upper left. Enter Application Gateway in the Search the Marketplace box at the top of the New pane that appears.

    Click the "Application Gateway" when it appears in the search results.

  • Proceed by clicking "Create" button

  • Enter the Resource Group, Application Gateway Name, Region, and Virtual Network settings as follows and click "Next: Frontends"

  • Click on the "Add new" button and enter the public IP name then click "Next: Backends"

  • Click on "Add a backend pool", create pools for both origin and edge as shown in the screenshot, and click "Next: Configuration".

  • Click on "Add a routing rule" in the window that appears.

  • Enter the following values for Edge sides then click the "Add" button.

  • Select the "Edge" pool as the backend target and click "Add new" for HTTP settings.

  • Enter the following values. These values will be for both origin and edge.

  • If your settings are as follows, Edge configuration is finished.

  • Click on "Add a routing rule" again and set the HTTP settings for Origin. Make the settings as below and click "Backend target".

  • Select the Origin pool as the backend target and select the BackendHttpSettings that we created before as HTTP settings.

  • Now it's time to forward HTTPS requests to Origin. For this, make the settings as follows. You can use this link for a certificate.

  • Select "BackendHttpSetting" as HTTP Settings and Select "Origin" as Backend target.

  • Likewise, configure port 5443 for Edge as follows.

  • Select "BackendHttpSetting" as HTTP Settings and Select "Edge" as the Backend target.

  • Application gateway settings will look like the following. If everything is ok, click "Next: Tags"

  • The process is completed by clicking on the "Create" button.

Step 5: Create Origin & Edge Scale Sets

  • We need to set up scale sets. Click Create a Resource in the portal which is on the upper left. Enter "Virtual Machine Scale Set" in the Search the Marketplace box at the top of the New pane that appears. Click "Virtual Machine Scale Set" when it appears in the search results.

  • Proceed by clicking "Create" button

  • First, we will create the Origin Scale Set. Select the Resource Group, enter the Virtual Machine scale set name, and choose Region settings as follows. Then click on "Browse all public and private images"

  • In the window that appears, search for Ant Media Server and select the "Ant Media Server Enterprise 2.2.1" version.

  • Enter the following values and click "Next: Networking"

  • Select the antmedia-cluster-virtual-network that we created before as a Virtual Network in this screen. Select the origin subnet as the Network interface and click “Yes” to Use a load balancer choice. Select the application gateway that we created before and select Origin as the Backend pool then click the "Next: Scaling"

  • Select Custom and set the CPU threshold to 60%. You can set other settings according to yourself.

  • Continue by clicking directly next to the "Management" and "Health" tabs and add the following lines to the "Custom data" area in the Advanced section.

    #!/bin/bash
    cd /usr/local/antmedia/
    ./change_server_mode.sh cluster 10.0.2.4

    10.0.2.4 IP address is the private IP address of the MongoDB instance I have set up before. Change according to your own MongoDB instance.

  • Click the "Create" button to create the Scale Set for the Origin.

Edge Scale Set

Create a new Scale Set again and repeat the above steps that we followed for the Origin Scale Set.

Then edit the Network interface part as follows. There will be Edge Subnet as the Network Interface and Edge will be selected for the Application Gateway Backend pool.

Finally, your scale sets will look like the following.

Cluster Test

If the following pages are responding then your edge/origin redirects are working correctly.

When you go to the Cluster Menu, you can see the joined nodes as below.

Streaming Test

For publishing please visit the https://your-domain-name/live/ and click Start Publishing button.

For playing please visit the https://your-domain-name:5443/live/player.html, put your streamId and click Start Playing button.

As you figure out, we connect default HTTPS port (443) for publishing and 5443 port for playing. Because we configure load balancer to forward default port(443) to origin group and 5443 to edge group.

🔄 Stream Like a Boss — AMS on Azure! 🚀

Your Ant Media Server cluster is now live on Azure, featuring Origin and Edge Scale Sets, a MongoDB backend, and an Application Gateway to route traffic. With resources that scale automatically, your streaming infrastructure is ready to handle high loads with resilience and flexibility.

Your deployment is now clustered, scalable, and fully under your control! 🎯