按照之前的规划,源站安装在172.20.1.46和172.20.1.47两台服务器上。
系统CENTOS7.5
特殊说明:使用的SRS版本是 SRS5,支持WEBRTC。SRS的官网只有SRS3,也就是官方说的稳定版,4相对不够稳定,不过最近关注公众号,发现SRS5来了。
1.一键安装(注意:命令执行时,应该在我们指定的目录,比如 usr/local或者其他,我就没注意,所以放在了root下面。。。)
git clone -b develop https://gitee.com/ossrs/srs.git &&
cd srs/trunk && ./configure && make && ./objs/srs -c conf/srs.conf
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsICM38FdsYkRGZkRG9lcvx2bjxiNx8VZ6l2cs0TPRVGbKhVWzZkMMBjVtJWd0ckW65UbM5WOHJWa5kHT20ESjBjUIF2X0hXZ0xCMx81dvRWYoNHLrdEZwZ1Rh5WNXp1bwNjW1ZUba9VZwlHdssmch1mclRXY39CXldWYtlWPzNXZj9mcw1ycz9WL49zZuBnL3ADN1ADMxATM4IzNwEjMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
这样就安装完毕了,并且会自动切换到指定的目录中,按照指示就可以启动服务了。但是我们还是要先进行一些配置的。
2.关于端口
The ports used by SRS, kernel services:
tcp://1935, for RTMP live streaming server(CN,EN).
tcp://1985, HTTP API server, for HTTP-API(CN, EN), WebRTC(CN, EN), etc.
tcp://8080, HTTP live streaming server, HTTP-FLV(CN, EN), HLS(CN, EN) as such.
udp://8000, WebRTC Media(CN, EN) server.
For optional HTTPS services, which might be provided by other web servers:
tcp://8088, HTTPS live streaming server.
tcp://1990, HTTPS API server.
For optional stream caster services, to push streams to SRS:
udp://8935, Stream Caster: Push MPEGTS over UDP server.
tcp://554, Stream Caster: Push RTSP server.
tcp://8936, Stream Caster: Push HTTP-FLV server.
udp://10080, Stream Caster: Push SRT Media server.
For external services to work with SRS:
udp://1989, WebRTC Signaling server.
官方给出了所需要的端口配置,我对于内网端口的管理没有那么严格,目前只是先解除各种屏障,所以我选择了关闭防火墙。执行如下
# disable the firewall
/etc/init.d/iptables stop
/sbin/chkconfig iptables off
#或 systemctl disable iptables.service
执行的时候是不是找不到文件呀!对呀,这个命令是SRS官方给的,是基于CENTOS6的。CENTOS7的防火墙是基于firewall,所以执行下面的命令才对:
#查看防火墙状态
firewall-cmd --state
#开放端口和端口范围
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=8080-8085/tcp
#查看防火墙的开放的端口
firewall-cmd --permanent --list-ports
#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload
#停止防火墙
systemctl disable firewalld
#禁用
systemctl stop firewalld
当然selinux也需要disable,运行命令
getenforce
,若不是Disabled,执行下面的步骤:
getenforce
#Disabled 这样就不用管了,如果是开启,执行下面的:
编辑配置文件:sudo vi /etc/sysconfig/selinux
把SELINUX的值改为disabled:SELINUX=disabled
重启系统:sudo init 6
3.SRS源站1的配置
先说明下,默认的启动配置应该是srs.conf。我做了备份,修改了这个文件。
# main config for srs.
# @see full.conf for detail config.
#监听的流端口
listen 1935;
#最大连接数
max_connections 1000;
pid ./objs/srs.pid
srs_log_tank file;
srs_log_file ./objs/srs.log;
#是否为守护进程,如果要启动在console,那么需要配置daemon off(没理解)
daemon on;
http_api {
enabled on;
listen 1985;
}
http_server {
enabled on;
listen 8080;
dir ./objs/nginx/html;
}
vhost __defaultVhost__ {
# hls {
# enabled on;
# }
# http_remux {
# enabled on;
# mount [vhost]/[app]/[stream].flv;
# }
cluster {
#集群的模式,对于源站集群,值应该是local。
mode local;
#是否开启源站集群
origin_cluster on;
#源站集群中的其他源站的HTTP API地址
coworkers 172.20.1.46:1985;
}
}
这里我暂时关闭了FLV输出,稍后会单独对HTTP-FLV进行配置
启动服务
/root/srs/trunk/objs/srs -c /root/srs/trunk/conf/srs.conf
[2021-07-28 14:20:57.368][Trace][18481][ftpsx82d] XCORE-SRS/5.0.8(Leo)
[2021-07-28 14:20:57.369][Trace][18481][ftpsx82d] config parse complete
[2021-07-28 14:20:57.369][Trace][18481][ftpsx82d] you can check log by: tail -f ./objs/srs.log (@see https://github.com/ossrs/srs/wiki/v1_CN_SrsLog)
[2021-07-28 14:20:57.369][Trace][18481][ftpsx82d] please check SRS by: ./etc/init.d/srs status
这就启动了,注意 上面提供了两个命令来查看日志和状态,这些相关的文件都存储在了SRS的目录下面,即/root/srs/trunk/
4.SRS源站2的配置
源站2和源站1的配置差异 只在 最后一个 coworkers,写出了自己以外的源站IP即可
# main config for srs.
# @see full.conf for detail config.
#监听的流端口
listen 1935;
#最大连接数
max_connections 1000;
pid ./objs/srs.pid
srs_log_tank file;
srs_log_file ./objs/srs.log;
#是否为守护进程,如果要启动在console,那么需要配置daemon off(没理解)
daemon on;
http_api {
enabled on;
listen 1985;
}
http_server {
enabled on;
listen 8080;
dir ./objs/nginx/html;
}
vhost __defaultVhost__ {
# hls {
# enabled on;
# }
# http_remux {
# enabled on;
# mount [vhost]/[app]/[stream].flv;
# }
cluster {
#集群的模式,对于源站集群,值应该是local。
mode local;
#是否开启源站集群
origin_cluster on;
#源站集群中的其他源站的HTTP API地址
coworkers 172.20.1.47:1985;
}
}
5.使用OBS推流到负载均衡172.20.1.44
推流显示正常。
去访问46和47的SRS控制台,可以看到其中有一个已经有流了,我的负载到了46上。
用VLC播放我测试的 rtmp://172.20.1.46:1935/live/1234
一切正常!!!源站部署完毕!
接下来部署 边缘的三台服务器。