Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1396821
  • 博文数量: 188
  • 博客积分: 1784
  • 博客等级: 上尉
  • 技术积分: 2772
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-05 22:20
个人简介

发上等愿,结中等缘,享下等福;择高处立,就平处坐,向宽处行。

文章分类

全部博文(188)

文章存档

2020年(12)

2019年(11)

2018年(4)

2017年(3)

2016年(11)

2015年(22)

2014年(19)

2013年(25)

2012年(32)

2011年(49)

分类: 高性能计算

2013-07-26 16:37:59

Load Balancing Wowza Media Server

Load Balancer provides system for load balancing between multiple Wowza Pro servers. It leverages the IServerNotify (ServerListener) interface in Wowza Pro. Each edge server is configured to use the ServerListenerLoadBalancerSender ServerListener class. We will call these servers the “edge” servers. Edge servers will periodically (about every 2.5 seconds) send load and status information over UDP (you must add UDP port to firewall exception) to a single (or multiple) Wowza Pro server running the ServerListenerLoadBalancerListener ServerListener. We will call this server the “load balancer”. The load balancer will keep track of the load and availability of each of the edge servers to which it is communicating.
When a Flash client wishes to communicate with one of the edge servers, it will first make a request to the load balancer to get the address of the least loaded edge server. The Flash client will then connect directly to this edge server. There are currently two ways for a Flash client to obtain the address of the least loaded edge server. The first method is to make a NetConnection.connect() request to an application on the load balancer that is running the ModuleLoadBalancerRedirector module. The ModuleLoadBalancerRedirector module rejects this connection request with a info.code of “NetConnection.Connect.Rejected”. The redirect url will be contained in the info.ex.redirect field. The second method is to make an HTTP request to the load balancer from Flash using the URLLoader class. The load balancer will return the redirect host name or ip address in the response to this request.
The load balancing mechanism is dynamic. Each time a new edge server is started or stopped it will communicate with the load balancer to send its current status. This makes it very easy to add and remove servers from the pool of available edge servers simply by starting or stopping an edge server. There is also a Java and JMX API for temporarily removing an edge server from the pool.

Steps to Setup Load Balancer and Origin Server:
·        Copy the file wms-plugin-loadbalancer.jar from this zip archive to the [install-dir]/lib/ folder of the Wowza Pro server

  • Copy the file conf/crossdomain.xml from this zip archive to the [install-dir]/conf/ folder of the Wowza Pro server.
  • Edit [install-dir]/conf/Server.xml and make the following changes

Add the following ServerListener entry to the list

    com.wowza.wms.plugin.loadbalancer.ServerListenerLoadBalancerListener
  • Add the following properties to the section at the bottom of Server.xml:
  • loadBalancerListenerKey

    023D4FB4IS83

    loadBalancerListenerIpAddress

    *

    loadBalancerListenerPort

    1934

    Integer

    loadBalancerListenerRedirectorClass

    com.wowza.wms.plugin.loadbalancer.LoadBalancerRedirectorConcurrentConnects

    loadBalancerListenerMessageTimeout

    5000

    Integer

  • Edit [install-dir]/conf/VHost.xml and replace the HostPort/HTTPProvider with the following XML snippet


    com.wowza.wms.plugin.loadbalancer.HTTPLoadBalancerRedirector

    enableServerInfoXML

    true

    Boolean

  • Edit [install-dir]/conf/applications/myapp/Application.xml file and set stream type to “liverepeater-origin”.

Steps To setup Edge Server :

  • Copy the file wms-plugin-loadbalancer.jar from this zip archive to the [install-dir]/lib/ folder of the Wowza Pro server.  Also add wms-plugin-amazonaws.jar if not available.(Optional needed if you are using amazon server)
  • Edit [install-dir]/conf/applications/myapp/Application.xml file and set stream type to “liverepeater-edge”.
  • Edit [install-dir]/conf/Server.xml and make the following changes.

Add the following ServerListener entry to the list:

    com.wowza.wms.plugin.loadbalancer.ServerListenerLoadBalancerSender


    com.wowza.wms.plugin.amazonaws.ec2.env.ServerListenerEC2Variables

    Add the following properties to the section at the bottom of Server.xml:

    loadBalancerSenderTargetPath

    ${com.wowza.wms.AppHome}/conf/loadbalancertargets.txt

    loadBalancerSenderRedirectAddress

    ${com.wowza.amazonaws.ec2.AWSEC2_METADATA_PUBLIC_IPV4}

    loadBalancerSenderMonitorClass

    com.wowza.wms.plugin.loadbalancer.LoadBalancerMonitorDefault

    loadBalancerSenderMessageInterval

    2500

    Integer

Where [redirect-address] is the external ip address or domain name of this machine. This address will be used when redirecting to this edge server. When using this system on EC2 you can set the [redirect-address] to ${com.wowza.amazonaws.ec2.AWSEC2_METADATA_PUBLIC_IPV4} and upon server startup it will use the public ip address of the server for this value.

  • Create the file [install-dir]/conf/loadbalancertargets.txt using a text editor and enter the following two lines (the first line is a comment):

# [load-balancer-ip-address],[load-balancer-port],[encryption-key]

[load-balancer-ip-address],1934,023D4FB4IS83

  • Set stream type as “liverepeater-edge” in Application.xml file and uncomment the line,


    rtmp://192.168.1.72

  • Also set AutoAccept to true if not.

Where [load-balancer-ip-address] is the ip address or domain name of the load balancer.

This configurations uses UDP port 1934 for communication between the edge servers and the load balancer. Be sure this port is open on your firewall. All communication between the edge server and the load balancer is encrypted and signed. The encryption key is set on the load balancer server using the loadBalancerListenerKey property and in the loadbalancertargets.txt file on the edge servers. These keys must match. An edge server can communicate with multiple load balancers by adding additional lines to the loadbalancertargets.txt file.

You can now startup the load balancer and multiple edge servers. If functioning properly, the edge servers will update the load balancer every 2.5 seconds with status and load information. You can get information from the load balancer in regards to which edge servers are currently registered and their status by opening a web browser and entering the following url:

Where [load-balancer-ip-address] is the ip address or domain name of the load balancer. It will return an XML document contains detailed information on each of the edge servers. Once you have your load balancing server up and running and in a production environment, you may wish to turn off this query interface. You can do this by setting the HTTPProvider/Properties/Property enableServerInfoXML in [install-dir]/conf/VHost.xml to false.

Get least loaded server using http

One of the methods to get the least loaded server from the load balancer is to make a request to the load balancer over http. The url for this request is:

Where [load-balancer-ip-address] is the ip address or domain name of the load balancer. This request will return the ip address of the least loaded server in the form “redirect=[ip-address]“.

Get least loaded server using NetConnection redirect

You can also get the least loaded server by configuring an application on the load balancer that uses the ModuleLoadBalancerRedirector module. To setup an application that uses this module follow these steps:

  • Create the folder [install-dir]/applications/redirect.
  • Create the folder [install-dir]/conf/redirect and copy the file [install-dir]/conf/Application.xml into this new folder.
  • Edit the newly copied Application.xml file and set stream type to “liverepeater-edge”
  • Edit the newly copied Application.xml file and add the following module entry as the last entry in the modules list:


    ModuleLoadBalancerRedirector

    ModuleLoadBalancerRedirector

    com.wowza.wms.plugin.loadbalancer.ModuleLoadBalancerRedirector

  • Add the following properties the properties section at the bottom of the Application.xml file:


    redirectAppName

    [application-name]

    redirectPort

    [redirect-port]

    –>

    redirectScheme

    rtmp

    –>

    redirectOnConnect

    true

    Boolean

Where [application-name] is the name of the application you wish to redirect to on the edge server and [redirect-port] is the port to redirect to (such as port 1935 or port 80). The redirectPort and redirectScheme are commented out so that the system will use the same scheme and port used to connect to the load balancer to connect to the edge server. This will work better when using any type of protocol (rtmp to rtmpt) or port rollover scheme.

 
阅读(2029) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~