Skip to content

v4_EN_SampleHlsCluster

Winlin edited this page Apr 4, 2022 · 7 revisions

HOME > EN > Edge Cluster

HLS Edge Cluster Example

Example for HLS Edge Cluster, like to create a CDN to deliver HLS files.

Suppose the server ip is 192.168.1.170

Step 1, Get SRS code. For detail, read GIT

git clone https://github.com/ossrs/srs
cd srs/trunk

Or update the exists code:

git pull

Step 2, Configure and build SRS. For detail, read Build

./configure && make

Step 3, Config origin srs, to generate HLS files. See HLS.

Please use config conf/hls.origin.conf, or create a config file by:

# conf/hls.origin.conf
listen              1935;
max_connections     1000;
pid                 objs/origin.pid;
srs_log_file        ./objs/origin.log;
http_server {
    enabled         on;
    listen          8080;
}
vhost __defaultVhost__ {
    hls {
        enabled         on;
    }
}

Step 4, Config edge NGINX to deliver HLS files. See Nginx for HLS.

Save bellow as config, or use conf/hls.edge.conf:

# conf/hls.edge.conf
worker_processes  3;
events {
    worker_connections  10240;
}

http {
    # For Proxy Cache.
    proxy_cache_path  /tmp/nginx-cache levels=1:2 keys_zone=srs_cache:8m max_size=1000m inactive=600m;
    proxy_temp_path /tmp/nginx-cache/tmp; 

    server {
        listen       8081;
        # For Proxy Cache.
        proxy_cache_valid  404      10s;
        proxy_cache_lock on;
        proxy_cache_lock_age 300s;
        proxy_cache_lock_timeout 300s;
        proxy_cache_key $scheme$proxy_host$uri;
        proxy_cache_min_uses 1;

        location ~ /.+/.*\.(m3u8)$ {
           proxy_pass http://127.0.0.1:8080$request_uri;
           # For Proxy Cache.
           proxy_cache srs_cache;
           proxy_cache_valid  200 302  10s;
        }
        location ~ /.+/.*\.(ts)$ {
           proxy_pass http://127.0.0.1:8080$request_uri;
           # For Proxy Cache.
           proxy_cache srs_cache;
           proxy_cache_valid  200 302  60m;
        }
    }
}

Step 5, Start SRS Origin and NGINX Edge Server.

./objs/srs -c conf/hls.origin.conf &
./objs/srs -c conf/edge.conf &

Step 6, start encoder. For detail, read RTMP and Edge

Use FFMPEG to publish stream:

    for((;;)); do \
        ./objs/ffmpeg/bin/ffmpeg -re -i ./doc/source.flv \
        -c copy \
        -f flv rtmp://192.168.1.170/live/livestream; \
        sleep 1; \
    done

Or use FMLE to publish:

FMS URL: rtmp://192.168.1.170/live
Stream: livestream

Step 7, play RTMP. For detail, read RTMP and Edge

Origin RTMP url is: rtmp://192.168.1.170:19350/live/livestream, User can use vlc to play the RTMP stream. Or, use online SRS player: srs-player-19350

Edge RTMP url is: rtmp://192.168.1.170:1935/live/livestream, User can use vlc to play the RTMP stream. Or, use online SRS player: srs-player

Note: Please replace all ip 192.168.1.170 to your server ip.

Winlin 2014.11

Welcome to SRS wiki!

SRS 5.0 wiki

Please select your language:

SRS 4.0 wiki

Please select your language:

SRS 3.0 wiki

Please select your language:

SRS 2.0 wiki

Please select your language:

SRS 1.0 wiki

Please select your language:

Clone this wiki locally