Feng's Notes

周海锋的个人博客

0%

srs_service

年会直播考虑到公司出口带宽的问题,需要在内网搭建一个srs直播服务,记录下搭建过程

Linux 内核参数优化

修改 /etc/sysctl.conf

fs.file-max = 999999
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.ip_local_port_range = 1024 61000
net.ipv4.tcp_rmem = 4096 32768 262142
net.ipv4.tcp_wmem = 4096 32768 262142
net.core.netdev_max_backlog = 8096
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 2097152
net.core.wmem_max = 2097152
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn.backlog=1024

sysctl -p

ulimit -n 查看是否生效

安装常用的运维软件

# 编译软件
yum install -y gcc gcc-c++ g++ make jq libpam-cracklib openssl-devel bzip2-devel ffmpeg
# 常规软件
yum install -y nano vim git unzip wget ntpdate dos2unix net-tools
yum install -y tree htop ncdu nload sysstat psmisc bash-completion fail2ban chrony nfs-utils
# 清空缓存和已下载安装的软件包
yum clean all

编译 SRS

git clone -b develop https://gitee.com/ossrs/srs.git &&
cd srs/trunk && ./configure && make && ./objs/srs -c conf/srs.conf

服务操作

./etc/init.d/srs status
./etc/init.d/srs start
./etc/init.d/srs stop
./etc/init.d/srs reload

配置防火墙

firewall-cmd --permanent --add-port=1935/tcp
firewall-cmd --permanent --add-port=1985/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-port=443/tcp
firewall-cmd --reload

拉流转推

ffmpeg -i rtmp://xxx/live/xxx -c:v libx264 -tune zerolatency -c:a copy -f flv rtmp://127.0.0.1:1935/live/xxx

碰到的问题

1、web播放提示跨域问题?

srs已经默认开启支持跨域,这个问题是因为 chrome 92以后,默认禁止http内网地址跨域访问资源。issue. 解决方案:配置下https证书。