将RTMP连接从一台服务器重定向到另一台服务器

时间:2019-01-11 20:26:38

标签: php nginx load-balancing rtmp nginx-reverse-proxy

我正在设置一台服务器,以在服务器(代码转换器)之间加载平衡器。
我有许多转码服务器,我希望通过php算法在这些服务之间取得平衡,以选择女巫服务器来响应请求。 请求是RTMP。
示例:
客户要求:rtmp:// balancer_ip:1935 / live / 21?username = jhony&password = haha​​ha
平衡器工作流程:找到最佳的转码器,并在此转码服务器上获得客户端凭据,然后将客户端重定向或proxy_pass到此转码服务器。

在我使用RTMP模块安装并配置了nginx的转码服务器中,她通过php算法与rtmp身份验证工作正常。 在第一个平衡器服务器中,我尝试使用rtmp身份验证之类的方法在rtmp模块中使用on_play参数重定向客户端,但我没有成功。
因此,我进行了其他研究,发现使用此模块的nginx TCP和UDP负载平衡可以重定向或proxy_pass the客户端请求到代码转换服务器,但是平衡器的问题很多时候是proxy_pass the client to错误的代码转换服务器(客户端没有对此转码服务器的访问权限或rtmp流量下降)。

#in balancer nginx.conf
stream {
    #listen on rtmp port
    server {
        listen     1935;
        proxy_pass rtmp_servers;
    }
    upstream rtmp_servers {
        server transcoder_1_ip:1935;
        server transcoder_2_ip:1935;
        #check interval=10 passes=2 fails=3 port=1935;
    }
}
#in transcoder nginx.conf
rtmp {
    server {
        listen 1935;
        application live {
            live on;
            on_play http://127.0.0.1:80/rtmp-auth;
            notify_method get;
            record off;
        }
    }
}
// php function for rtmp stream authentication in transcoder
$app->get('/rtmp-auth', function (Request $request) use ($app) {
    $response = new Response();
    $response->setStatusCode(404);
    // check with database if user name and posword is ok
        $response->setStatusCode(201);
    }
    /* i tryed in balancer with this code and send a redirection
       in the return but she dont work :(*/
    return $response;
})->bind('rtmpAuth');

那么有什么方法可以通过自定义算法在服务器之间重定向或平衡?
还是在每个客户端请求中,在重定向客户端之前检查转码服务器的响应?
注意:我有tronscoding服务器可以处理某些类似客户国家的批评……所以我需要创建算法来重定向客户请求。

0 个答案:

没有答案