srs Vhost: Cluster redirect to different vhost or stream

m3eecexj  于 2022-12-31  发布在  其他
关注(0)|答案(1)|浏览(282)

描述(Description)
I am trying to use srs cluster mode to redirect srs-edge to different srs-origins with different vhosts.
For example:
Step One:
client play rtmp -> srs-edge.test.vhost (remote mode) -> srs-balancer.test.vhost (local mode) -> local coworker (this is my application that responds to an API cluster request)
Step Two:
local coworker (my application) Send api answer with Origin: {IP,PORT, vhost=pub1-vhost}-> srs-balancer Send RTMP Redirect with RTMP://IP:PORT/stream?vhost=srs-edge.test.vhost (it ignores vhost=pub1-vhost) -> srs-edge.test.vhost (remote mode) go to rtmp redirect
描述你遇到了什么问题(Please description your issue here)

Unfortunately, srs only uses the Host and Port from the api cluster response, but Vhost is still required for my cluster scheme.

  1. SRS版本(Version): 3.0.140
  2. SRS的日志如下(Log):
    srs-edge.test.vhost Log
[2020-03-30 19:26:34.459][Trace][61390][354] connect app, tcUrl=rtmp://srs-edge.test.vhost:20135/test, pageUrl=, swfUrl=, schema=rtmp, vhost=srs-edge.test.vhost, port=20135, app=test, args=null
[2020-03-30 19:26:34.459][Trace][61390][354] protocol in.buffer=0, in.ack=0, out.ack=0, in.chunk=128, out.chunk=128
[2020-03-30 19:26:34.561][Trace][61390][354] ignore AMF0/AMF3 command message.
[2020-03-30 19:26:34.642][Trace][61390][354] ignore AMF0/AMF3 command message.
[2020-03-30 19:26:34.642][Trace][61390][354] client identified, type=Play, vhost=srs-edge.test.vhost, app=test, stream=test, param=, duration=-1ms
[2020-03-30 19:26:34.642][Trace][61390][354] connected stream, tcUrl=rtmp://srs-edge.test.vhost:20135/test, pageUrl=, swfUrl=, schema=rtmp, vhost=srs-edge.test.vhost, port=20135, app=test, stream=test, param=, args=null
[2020-03-30 19:26:34.642][Trace][61390][354] source url=srs-edge.test.vhost/test/test, ip=46.242.119.122, cache=1, is_edge=1, source_id=-1[-1]
[2020-03-30 19:26:34.642][Trace][61390][354] create consumer, active=0, queue_size=0.00, jitter=30000000
[2020-03-30 19:26:34.642][Trace][61390][354] ignore disabled exec for vhost=srs-edge.test.vhost
[2020-03-30 19:26:34.642][Trace][61390][354] set fd=11, SO_SNDBUF=87380=>175000, buffer=350ms
[2020-03-30 19:26:34.642][Trace][61390][354] start play smi=0ms, mw_sleep=350, mw_enabled=1, realtime=0, tcp_nodelay=0
[2020-03-30 19:26:34.643][Trace][61390][354] update source_id=355[355]
[2020-03-30 19:26:34.651][Trace][61390][355] complex handshake success.
[2020-03-30 19:26:34.651][Trace][61390][355] protocol in.buffer=0, in.ack=0, out.ack=0, in.chunk=128, out.chunk=128
[2020-03-30 19:26:34.731][Trace][61390][355] connected, version=3.0.140.0, ip=127.0.0.1, pid=55417, id=689, dsu=1
[2020-03-30 19:26:34.731][Trace][61390][355] edge change from 100 to state 101 (pull).
[2020-03-30 19:26:34.771][Warn][61390][355][11] RTMP redirect srs-edge.test.vhost/test/test from 127.0.0.1:30135 to rtmp://10.0.0.2:20135/test/test?vhost=srs-edge.test.vhost
[2020-03-30 19:26:34.801][Warn][61390][355][111] EdgeIngester: Ignore error, code=1018 : connect upstream : edge pull rtmp://10.0.0.2:20135/test/test?vhost=srs-edge.test.vhost failed, cto=5000ms, sto=500ms. : connect : tcp: connect 10.0.0.2:20135 to=5000ms : connect to 10.0.0.2:20135

srs-balancer Log:

[2020-03-30 19:26:34.691][Trace][55417][689] connect app, tcUrl=rtmp://srs-edge.test.vhost:30135/test, pageUrl=, swfUrl=, schema=rtmp, vhost=srs-edge.test.vhost, port=30135, app=test, args=(obj)
[2020-03-30 19:26:34.691][Trace][55417][689] edge-srs ip=151.236.121.5, version=3.0.140, pid=61390, id=355
[2020-03-30 19:26:34.691][Trace][55417][689] protocol in.buffer=0, in.ack=0, out.ack=0, in.chunk=128, out.chunk=128
[2020-03-30 19:26:34.731][Trace][55417][689] client identified, type=Play, vhost=srs-edge.test.vhost, app=test, stream=test, param=?vhost=srs-edge.test.vhost, duration=-1ms
[2020-03-30 19:26:34.731][Trace][55417][689] connected stream, tcUrl=rtmp://srs-edge.test.vhost:30135/test, pageUrl=, swfUrl=, schema=rtmp, vhost=__defaultVhost__, port=30135, app=test, stream=test, param=?vhost=srs-edge.test.vhost, args=(obj)
[2020-03-30 19:26:34.731][Trace][55417][689] source url=/test/test, ip=127.0.0.1, cache=1, is_edge=0, source_id=-1[-1]
[2020-03-30 19:26:34.732][Warn][55417][689][11] use public address as ip: 151.236.121.5
[2020-03-30 19:26:34.732][Trace][55417][689] http: cluster redirect 10.0.0.2:20135 ok, url=http://127.0.0.1:30155/api/v1/clusters?vhost=__defaultVhost__&ip=srs-edge.test.vhost&app=test&stream=test&coworker=127.0.0.1:30155, response={"code":0,"data":{"query":{"ip":"srs-edge.test.vhost","vhost":"srs-edge.test.vhost","app":"test","stream":"test"},"origin":{"ip":"10.0.0.2","port":20135,"vhost":"srs-pub1.test.vhost","api":"srs-pub1.test.vhost:20185","routers":["srs-pub1.test.vhost:20185"]}}}

[2020-03-30 19:26:34.732][Trace][55417][689] rtmp: redirect in cluster, from=srs-edge.test.vhost:30135, target=10.0.0.2:20135, url=http://127.0.0.1:30155/api/v1/clusters?vhost=__defaultVhost__&ip=srs-edge.test.vhost&app=test&stream=test&coworker=127.0.0.1:30155, rurl=rtmp://10.0.0.2:20135/test/test?vhost=srs-edge.test.vhost
[2020-03-30 19:26:34.771][Trace][55417][689] client finished.

My app send:
response={"code":0,"data":{"query":{"ip":"srs-edge.test.vhost","vhost":"srs-edge.test.vhost","app":"test","stream":"test"},"origin":{"ip":"10.0.0.2","port":20135,**"vhost":"srs-pub1.test.vhost"**,"api":"srs-pub1.test.vhost:20185","routers":["srs-pub1.test.vhost:20185"]}}}

But RTMP Redirect:
rurl=rtmp://10.0.0.2:20135/test/test?vhost=srs-edge.test.vhost

  1. SRS的配置如下(Config):
    srs-edge.test.vhost
listen              20135;
max_connections     10000;
srs_log_tank        file;
srs_log_file        /var/log/srs/srs.log;
http_api {
    enabled         on;
    listen          20185;
}
http_server {
    enabled         on;
    listen          20180;
}

vhost srs-edge.test.vhost {
    cluster {
        mode remote;
        origin 127.0.0.1:30135;
        debug_srs_upnode    on;
    }
}

srs-balancer.

listen              30135;
pid                 objs/srs-balancer.pid;
max_connections     10000;
srs_log_tank        file;
srs_log_file        /var/log/srs/srs-balancer.log;
http_api {
    enabled         on;
    listen          30185;
}

vhost __defaultVhost__ {
    cluster {
        mode            local;
        origin_cluster  on;
        coworkers       127.0.0.1:30155;
    }
}

重现(Replay)

重现Bug的步骤(How to replay bug?)

  1. ffplay rtmp://srs-edge.test.vhost:20135/test/test
  2. tail -f /var/log/srs/srs.log
  3. tail -f /var/log/srs/srs-balancer.log

期望行为(Expect)
描述你期望发生的事情(Please describe your expectation)

Is it possible to teach SRS to use Vhost Param from API clusters answer to redirect RTMP?
Thanks.

vwoqyblh

vwoqyblh1#

Vhost Alias

这种就是vhost的Alias功能,别名。播放不同的vhost,实际上指向的是同一个vhost,可以实现上行和下行的vhost分离调度,也可以隔离风险。

Stream Alias

还有一种是stream alias,流的别名,可以实现热备,比如有两个流:

  • rtmp://xxx/app/streamA
  • rtmp://xxx/app/streamB

如果stream是streamA的别名, stream alias streamA ,若用户播放的是:

  • rtmp://xxx/app/stream

实际上播放的是streamA,可以用reload实现 stream alias streamB ,这样就实现热备。

有个workaround,用FFmpeg把streamA拉出来推成stream,就是 stream alias streamA

ffmpeg -f flv rtmp://xxx/app/streamA -c copy -f flv rtmp://xxx/app/stream

Please read more about the detail from this post

相关问题