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 bitrating because they need more processing power. Ultra low latency is achieved by WebRTC and it is a CPU intensive protocol. Adaptive bitrating is downgrading video quality in bad networks if needed. It is also CPU intensive because there is a 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.

Architecture of 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.How to Setup Ant Media Server Clustering on Azure 1
  3. Select Classic in the Select a deployment model box in the Virtual Network pane that appears, then click Create.How to Setup Ant Media Server Clustering on Azure 2
  4. Enter the following values on the Create virtual network (classic) pane and then click Create:How to Setup Ant Media Server Clustering on Azure 3
  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:How to Setup Ant Media Server Clustering on Azure 4
  8. Enter edge-subnet for Name on the Add subnet pane. Enter 10.0.1.0/24 for Address range. Click OK:How to Setup Ant Media Server Clustering on Azure 5
  9. Now you created origin-subnet and edge-subnet.
  10. Important Note: You need to open TCP port range(TCP:5000-65000) for the internal network. It should not be open to public.

Step 2: Create a Public IP

Create a static public IP address described as 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.How to Setup Ant Media Server Clustering on Azure 6
    1. Under Public IP address, select Create.
    2. Enter the following values to the form and click How to Setup Ant Media Server Clustering on Azure 7
    3. 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:How to Setup Ant Media Server Clustering on Azure 8
    2. On the Storage Accounts window that appears, choose Add:How to Setup Ant Media Server Clustering on Azure 9
    3. Enter the following values and select Review + Create to review your storage account settings and create the account:How to Setup Ant Media Server Clustering on Azure 10
    4. Select Create.

    Step 4: Create a Virtual Machine for AntMedia

    1. Click Virtual Machines on the left bar and then click +Add:How to Setup Ant Media Server Clustering on Azure 11
    2. Enter the following values and click next:How to Setup Ant Media Server Clustering on Azure 12
    3. Enter the following values and click next:How to Setup Ant Media Server Clustering on Azure 13
    4. Enter the following values and click next:How to Setup Ant Media Server Clustering on Azure 14
    5. Enter the following values and click create+review:How to Setup Ant Media Server Clustering on Azure 15
    6. Click create.

    Step 5: Setup AntMedia in VM

    • Click Virtual Machines on the left bar and choose your virtual machine. Note the public ip address:How to Setup Ant Media Server Clustering on Azure 16
    • 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}
    • Download the AntMedia Server zip file and setup using this script.
    • After setting up MongoDB server as described in Step 6, Run this scriptsudo ./change_server_mode.sh cluster <MONGO_SERVER_IP>
    • MONGO_SERVER_IP is the private IP and can be learnt from MongoDB server in All Resources. Now server will start in cluster mode.
    • 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

    • Create another virtual machine following the Step 5.
    • 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
    • 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
    • Press “Ctrl + X” to save the file.
    • 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

          • Select Create a resource on the left menu of the Azure portal. The New window appears.
          • Select Networking and then select Application Gateway in the Featured list.
          • Enter the following values and click next:How to Setup Ant Media Server Clustering on Azure 17
          • Enter the following values, create new ip for this and click next:How to Setup Ant Media Server Clustering on Azure 18
          • Enter the following values for backend pool and click next:How to Setup Ant Media Server Clustering on Azure 19
          • Add another backend pool for edge scale.
          • 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:How to Setup Ant Media Server Clustering on Azure 20
          • Click Backend Targets tab and enter the following values:How to Setup Ant Media Server Clustering on Azure 21
          • Click Create New for HTTP Setting and enter the following values:How to Setup Ant Media Server Clustering on Azure 22
          • Click Add and add Http Settings.
          • Click add and add the rule.
          • Add another rule named http_80_origin which forwards 80 port calls to origin scale. Enter the following values:How to Setup Ant Media Server Clustering on Azure 23
          • Click Backend Targerts tab and enter the followings and click add:How to Setup Ant Media Server Clustering on Azure 24
          • Add another rule named https_5443_edge with the following values:

        How to Setup Ant Media Server Clustering on Azure 25

        How to Setup Ant Media Server Clustering on Azure 26

          • Add another rule for https_443_originHow to Setup Ant Media Server Clustering on Azure 27How to Setup Ant Media Server Clustering on Azure 28

         

        • In Review+Create section, click Create:How to Setup Ant Media Server Clustering on Azure 29

         

        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:How to Setup Ant Media Server Clustering on Azure 30
        2. Enter a name and select the resource group that you created before.How to Setup Ant Media Server Clustering on Azure 31
        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.How to Setup Ant Media Server Clustering on Azure 32
        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

        How to Setup Ant Media Server Clustering on Azure 33

        How to Setup Ant Media Server Clustering on Azure 34

        •  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.
        • Go to Application Gateway that you created previously and click Backendpools created previously:

        How to Setup Ant Media Server Clustering on Azure 35

         

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

        How to Setup Ant Media Server Clustering on Azure 36

         

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

         

        How to Setup Ant Media Server Clustering on Azure 37

        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 a 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

        Categories: Tutorial