2020-03-02 Ubuntu 16.04 安装SRS3
1.准备软件
1.RSR3
git clone https://gitee.com/fesker85/srs.git
2.haproxy
apt install haproxy
2.安装
2.1 安装 SRS 3
./configure && make
2.2 安装 Haproxy
apt install haproxy
3.配制(集群式)
1. master.conf
listen 1945;
max_connections 1000;
pid ./objs/tms.master.pid;
srs_log_tank file;
srs_log_file ./objs/tms.master.log;
daemon off;
http_api {
enabled on;
listen 1955;
crossdomain on;
raw_api {
enabled off;
allow_reload off;
allow_query off;
allow_update off;
}
}
http_server {
enabled on;
listen 1965;
dir ./objs/nginx/html;
crossdomain on;
}
stats {
network 0;
disk sda sdb xvda xvdb;
}
vhost __defaultVhost__ {
tcp_nodelay on:
min_latency on;
play {
gop_cache off;
queue_length 10;
mw_latency 100;
}
forward {
enabled on;
destination 60.xx.xx.xx:1946 118.xx.xx.xx:1946;
}
}
2. slave.conf
listen 1946;
max_connections 1000;
pid ./objs/tms.slave.pid;
srs_log_tank file;
srs_log_file ./objs/tms.slave.log;
daemon off;
http_api {
enabled on;
listen 1956;
crossdomain on;
raw_api {
enabled off;
allow_reload off;
allow_query off;
allow_update off;
}
}
http_server {
enabled on;
listen 1966;
dir ./objs/nginx/html;
crossdomain on;
}
stats {
network 0;
disk sda sdb xvda xvdb;
}
vhost __defaultVhost__ {
tcp_nodelay on;
min_latency on;
play {
gop_cache off;
queue_length 10;
mw_latency 100;
}
}
3.edge.conf (可用nginx rtmp代替 因为测试中发现如果没有访问rtmp接口不会生成hls切片)
listen 1947;
max_connections 1000;
pid ./objs/tms.edge.pid;
srs_log_tank file;
srs_log_file ./objs/tms.edge.log;
daemon off;
http_api {
enabled on;
listen 1957;
crossdomain on;
raw_api {
enabled off;
allow_reload off;
allow_query off;
allow_update off;
}
}
http_server {
enabled on;
listen 1967;
dir ./objs/nginx/html;
crossdomain on;
}
stats {
network 0;
disk sda sdb xvda xvdb;
}
vhost __defaultVhost__ {
cluster {
mode remote;
origin 60.xx.xx.xx:1945 60.xx.xx.xx:1946 118.xx.xx.xx:1945 118.xx.xx.xx:1946;
}
tcp_nodelay on;
min_latency on;
play {
gop_cache off;
queue_length 10;
mw_latency 100;
}
hls {
enabled on;
hls_fragment 2;
hls_window 10;
hls_path ./objs/nginx/html;
hls_m3u8_file [app]/[stream].m3u8;
hls_ts_file [app]/[stream]-[seq].ts;
}
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
hstrs on;
}
4.开启服务
依次开启
./srs -c master.conf
./srs -c slave.conf
./srs -c edge.conf
热重启:killall -1 srs
5.配制Haproxy
global
log /dev/log local0
log /dev/log local1
notice chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
# Default SSL material locations
# ca-base /etc/ssl/certs
# crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
# ssl-default-bind-ciphers xxx
# ssl-default-bind-options no-sslv3
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
listen tms-cluster
bind *:1935
mode tcp
balance roundrobin
server master1 60.xx.xx.xx:1945
server master2 118.xx.xx.xx:1945
sudo systemctl restart haproxy
OK 搞定