How to Setup Ant Media Server Clustering on Azure?

In this guide, I will explain how to setup Ant Media Server Clustering on Azure. When your load is high, one server instance is not enough for you and you can handle that load with a clustering solution.

For streaming applications, you will need a clustering solution when you have high numbers of publishers and viewers. Especially when you require ultra-low latency and adaptive bitrate because they need more processing power. Ultra-low latency is achieved by WebRTC and it is a CPU intensive protocol. Adaptive bitrate is downgrading video quality in bad networks if needed. It is also CPU intensive because there is video conversion. Luckily, Ant Media Server Enterprise Edition supports clustering, so that you can handle high load in your streaming applications.

Requirements:
Having an Azure account and a ready AntMedia Server Image.

The architecture of a cluster setup could be found here.
Introduction to clustering with AntMedia Server could be found here.

Step 1: Create a Virtual network

Firstly, we need to create a virtual network named antmediaserver, and then we will add origin-subnet and edge-subnet as described in this doc.

1 - Click Create a Resource in the portal which is on the upper left.

2 - Enter Virtual network in the Search the Marketplace box at the top of the New pane that appears. Click Virtual network when it appears in the search results.

3- Select Classic in the Select a deployment model box in the Virtual Network pane that appears, then click Create.

4 - Enter the following values on the Create virtual network (classic) pane and then click Create:

5 - To create the second subnet, enter antmediaserver in the Search resources box at the top of the page. Click antmediaserver when it appears in the search results.

6 - Click antmediaserver (in the SETTINGS section) on the Create virtual network (classic) pane that appears.

7 - Click +Add on the antmediaserver — Subnets pane that appears:

8 - Enter edge-subnet for Name on the Add subnet pane. Enter 10.0.1.0/24 for Address range. Click OK:

9 - Now you created origin-subnet and edge-subnet.

Step 2: Create a Public IP

Create a static public IP address described here. Name it antmediaserver-ip.

1 - At the top, left corner of the portal, select + Create a resource.

2 - Enter public IP address in the Search the Marketplace box. When Public IP address appears in the search results, select it.

3 - Under Public IP address, select Create.

4 - Enter the following values to the form and click

5 - This will create the public ip address.:

Step 3: Create a Storage Account

Create a storage account as described here. Name it antmediamediastorage.

1 - In the Azure portal, select All services. In the list of resources, type Storage Accounts. As you begin typing, the list filters based on your input. Select Storage Accounts:

2 - On the Storage Accounts window that appears, choose Add:

3 - Enter the following values and select Review + Create to review your storage account settings and create the account:

4 - Select Create.

Step 4: Create a Virtual Machine for AntMedia

1 - Click Virtual Machines on the left bar and then click +Add:

2 - Enter the following values and click next:

3 - Enter the following values and click next:

4 - Enter the following values and click next:

5 - Enter the following values and click create+review:

6 - Click create.

Step 5: Setup AntMedia in VM

1 - Click Virtual Machines on the left bar and choose your virtual machine. Note the public IP address:

2 - Right now, you should connect to your instance. To Connect your instance, open a terminal and run a command something like. Please change {YOUR_KEY_FILE} and {INSTANCE_PUBLIC_IP} with your own credentials: ssh -i {YOUR_KEY_FILE} username@{INSTANCE_PUBLIC_IP}

3 - Download the AntMedia Server zip file and setup using this script.

4 - After setting up MongoDB server as described in Step 6, Run this script. sudo ./change_server_mode.sh cluster <MONGO_SERVER_IP>

5 - MONGO_SERVER_IP is the private IP and can be learnt from MongoDB server in All Resources. Now server will start in cluster mode.

6 - Run sudo waagent -deprovision+user

Warning: Be aware that it may take some time for the new VM to start up.

Step 6: Create a MongoDB Virtual Machine

1 - Create another virtual machine following Step 5.

2 - After you get connected, run the following commands in order to install MongoDB to your instance:

$ sudo apt-key adv — keyserver hkp://keyserver.ubuntu.com:80 — recv 9DA31620334BD75D9DCB49F368818C72E52529D4 
$ echo “deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
$ sudo apt-get update
$ sudo apt-get install -y mongodb-org

3 - Open /etc/mongod.conf file with an editor like nano and change bind_ip value to 0.0.0.0 to let MongoDB accept connections in all interfaces and save it: sudo nano /etc/mongod.conf

4 - Press “Ctrl + X” to save the file.

5 - Restart mongod and enable service.MongoDB installation is complete after this, just save your MongoDB instance’s local address somewhere. We will use it in later.:

sudo service mongod restart
sudo systemctl enable mongod.service

Step 7: Create Application Gateway

1 - Select Create a resource on the left menu of the Azure portal. The New window appears.

2 - Select Networking and then select Application Gateway in the Featured list.

3 - Enter the following values and click next:

4 - Enter the following values, create new ip for this and click next:

5 - Enter the following values for backend pool and click next:

6 - Add another backend pool for edge scale.

7 - Click Add a Rule and enter a rule named http_5080_edge for forwarding 5080 http calls to edge scale group. Enter the values as in the screen shot:

8 - Click Backend Targets tab and enter the following values:

9 - Click Create New for HTTP Setting and enter the following values:

10 - Click Add and add Http Settings.

11 - Click add and add the rule.

12 - Add another rule named http_80_origin which forwards 80 port calls to origin scale. Enter the following values:

13 - Click Backend Targets tab and enter the followings and click add:

14 - Add another rule named https_5443_edge with the following values:

15 - Add another rule for https_443_origin

16 - In Review+Create section, click Create:

Step 8: Create Scale Sets

1 - We need to setup scale sets. Click We need an image for this. So go to VM that you created and click Capture:

2 - Enter a name and select the resource group that you created before.

3 - Click Create a Resource which is on the top left and search for virtual machine scale set. Select virtual machine scale set in the list and click create.

4 - Create edgescale scale set as in the screenshot:

  • Enter a scale set name “edgescale”.
  • Set Availability zone to None.
  • Set username.
  • Set SSH public key.
  • Set instance count to minimum number that you need.
  • Select a VM size.
  • Enable AutoScale with min and max instance numbers.
  • Select Application Gateway as load balancer.
  • Select edge-subnet as subnet which is created before.
  • Enable public IP address per instance.
  • Click create

5 - Create a scale set for origin applying previous steps.:

  • Enter a scale set name “originscale”
  • Click browse all images and in my items tab select the image that you created.
  • Set username.
  • Set SSH public key.
  • Set instance count to 1.
  • Select a VM size.
  • Enable AutoScale with min and max instance numbers.
  • Select Application Gateway as load balancer.
  • Select origin-subnet as subnet which is created before.
  • Enable public IP address per instance.
  • Click create.

6 - Go to Application Gateway that you created previously and click Backendpools created previously:

7 - Click antmedia-gatewayoriginscale and set originscale as VMSS target:

8 - Then click antmedia-gatewayedgescale in Backend pools and set target as edgescale as VMSS:

End of Setting up Ant Media Server Clustering on Azure

This completes the setup. Now you can login to web panel via the https://application-gateway-ip.

If you want to use an Ant Media Server Enterprise ready Azure instance, you can get one from Azure Marketplace here.

If you have any questions, please send an email to contact@antmedia.io

This blog post originally published in https://antmedia.io/ssl-for-azure-app-gateway-for-scaling-azure-ant-media/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ant Media Server

Ant Media Server, open source software, supports publishing live streams with WebRTC and RTMP. It supports HLS(HTTP Live Streaming) and MP4 as well.