
OSSRS Case HTTP-FLV Cluster
OSSRS is a feature rich, high performance, live streaming solution. For more information, visit:
This post setup a working Clustered HTTP-FLV.
Server arrangement
| Server | IP Address | Deployment |
|---|---|---|
| serverA | 192.168.0.2 | origin server x 1 edge server x 1 |
| serverB | 192.168.0.3 | origin server x 1 edge server x 1 |
We will use pure Docker to deploy the server instances, so the configuration can be shared by them. As cross-server container communication is impossible, so the coworker address must be specified explicitly.
Configuration
Configuration files will be put at e.g., ${PWD}/conf which means you need to provide a conf directory under wherever you want.
origin server
Place the config at ${PWD}/conf/http.flv.live.conf :
listen 1935;
max_connections 1000;
daemon off;
srs_log_tank console;
http_server {
enabled on;
listen 8080;
dir ./objs/nginx/html;
}
http_api {
enabled on;
listen 9090;
}
vhost __defaultVhost__ {
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
hstrs on;
}
cluster {
mode local;
origin_cluster on;
coworkers origin-coworker-1:9090;
}
}
Ports are used for:
- 1935 RTMP
- 9090 cluster communication
- 8080 HTTP-FLV
edge server
Place the config at ${PWD}/conf/http.flv.live.edge1.conf :
listen 1935;
max_connections 1000;
daemon off;
srs_log_tank console;
http_server {
enabled on;
listen 8080;
dir ./objs/nginx/html;
}
vhost __defaultVhost__ {
mode remote;
origin origin-server-1 origin-server-2;
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
hstrs on;
}
}
Ports are used for:
- 1935 RTMP
- 8080 HTTP-FLV
Run
origin server
On serverA :
replace origin-coworker-1 with 192.168.0.3, as serverB deploys a origin server
On serverB :
replace origin-coworker-1 with 192.168.0.2, as serverA deploys a origin server
注意:
- 在没有容器集群的情况下, Cluster 的 coworker 地址必须明确指定. 如果使用hostname, 则 edge server 会通过 hostname 对流进行重定向, 当没有集群来支持容器跨节点访问时, 就会无法访问.
- 在有容器集群的情况下, 同样可以使用 hostname 或者 service name
Then start the origin server on serverA and serverB with:
docker run -d --name srs-origin-1 \
-p 1935:1935 -p 9090:9090 -p 8081:8080 \
-v `pwd`/conf/http.flv.live.conf:/usr/local/srs/conf/srs.conf \
ossrs/srs:3
edge server
Start on serverA and serverB with:
docker run -d --name srs-edge-1 \
-p 19351:1935 -p 8082:8080 \
--add-host=origin-server-1:192.168.0.2 \
--add-host=origin-server-2:192.168.0.3 \
-v `pwd`/conf/http.flv.live.edge1.conf:/usr/local/srs/conf/srs.conf \
ossrs/srs:3
Result
In case we are
- publishing a RTMP stream to
srs-edge-1onserverB(ie., 192.168.0.3:19351), - and that edge server forwarded to
srs-origin-1onserverA
Then the stream services' availability would be:
| Server | Container | RTMP | HTTP-FLV |
|---|---|---|---|
serverA |
srs-origin-1 |
Y | Y |
serverB |
srs-origin-1 |
N | N |
serverA |
srs-edge-1 |
Y | Y |
serverB |
srs-edge-1 |
Y | Y |
Conclusion
For more robust performance, both publish and play stream via edge server is always recommended.
Reason: edge server is designed to auto fail-over and load balance the upstream Clustered Origin Server.