安装gcc g++的依赖库
sudo apt-get install build-essential
sudo apt-get install libtool
安装pcre依赖库
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev
安装zlib依赖库
sudo apt-get install zlib1g-dev
安装SSL依赖库
1、wget https://www.openssl.org/source/openssl-3.0.1.tar.gz
2、tar -zxvf openssl-3.0.1.tar.gz
3、cd openssl-3.0.1
4、使用./config生成MakeFile,不加任何参数,默认的安装位置为:/usr/local/bin/openssl
5、sudo make && make install
>到上一步openssl就算安装好了,但是还无法使用,需要通过软链接的方式将新旧版本就行替换,依次运行下列命令。
sudo mv /usr/bin/openssl /usr/bin/openssl.old //将旧版本的openssl进行备份
sudo ln -s /usr/local/bin/openssl /usr/bin/openssl //将新版本的openssl进行软链接
cd /etc/ //进入etc目录
su //下一步一定要切换到root用户
echo “/usr/local/lib” >> ld.so.conf //将openssl的安装路径加入配置中
ldconfig //重新加载配置
切换成root用户步骤
1、sudo passwd root
2、修改root密码
>**#下载最新版本**
两种方式 (本文使用wget安装)
1:git clone https://github.com/nginx/nginx.git
2: wget http://nginx.org/download/nginx-1.20.2.tar.gz**#解压:**tar -zxvf nginx-1.20.2.tar.gz**#进入到解压目录**cd nginx-1.20.2**#下载最新版本**./configure --prefix=/usr/local/nginx --with-openssl=/usr/local/openssl-3.0.1**#编译**make**#安装**sudo make install**#启动:**
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
**#至此nginx就安装成功了**
网上很多都是装nginx-rtmp-module 但是nginx-http-flv-module 包含了 nginx-rtmp-module 所有的功能,所以不要将 nginx-http-flv-module 和 nginx-rtmp-module 一起编译。所以本文装的是nginx-http-flv-module ,因为后面要利用flv 拉流
配置参考地址
https://github.com/winshining/nginx-http-flv-module/blob/master/README.md
安装nginx-http-flv-module步骤
1.下载nginx-http-flv-module
git clone https://github.com/winshining/nginx-http-flv-module.git
2…/configure --add-module=…/nginx-http-flv-module --prefix=/usr/local/nginx --with-openssl=/usr/local/openssl-3.0.1
3.sudo make && make install
配置nginx
#user nobody;
worker_processes 1;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024;
}
http {include mime.types;default_type application/octet-stream;#log_format main '$remote_addr - $remote_user [$time_local] "$request" '# '$status $body_bytes_sent "$http_referer" '# '"$http_user_agent" "$http_x_forwarded_for"';#access_log logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}location /live {flv_live on; #打开 HTTP 播放 FLV 直播流功能chunked_transfer_encoding off; #支持 'Transfer-Encoding: chunked' 方式回复add_header 'Access-Control-Allow-Origin' '*'; #添加额外的 HTTP 头add_header 'Access-Control-Allow-Credentials' 'true'; #添加额外的 HTTP 头}location /hls {types {application/vnd.apple.mpegurl m3u8;video/mp2t ts;}root /tmp;add_header 'Cache-Control' 'no-cache';}location /dash {root /tmp;add_header 'Cache-Control' 'no-cache';}location /stat {rtmp_stat all;rtmp_stat_stylesheet stat.xsl;}location /stat.xsl {root /usr/local/nginx-http-flv-master/;}#如果需要 JSON 风格的 stat, 不用指定 stat.xsl#但是需要指定一个新的配置项 rtmp_stat_format#location /stat {# rtmp_stat all;# rtmp_stat_format json;#}location /control {rtmp_control all; #rtmp 控制模块的配置}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html## proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#}}
rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp_socket_dir /tmp;
rtmp {out_queue 4096;out_cork 8;max_streams 128;timeout 15s;drop_idle_publisher 15s;log_interval 5s; #log 模块在 access.log 中记录日志的间隔时间,对调试非常有用log_size 1m; #log 模块用来记录日志的缓冲区大小server {listen 1935;chunk_size 4096;application vod {play /opt/video/vod; }application live {live on;# 非常重要, 设定让ngnix断开阻塞中的连接, 才能触发exec_record_done# 以及客户端的LFLiveKit reconnectCount自动重新连接才会好用drop_idle_publisher 5s;meta off; # 为了兼容网页前端的 flv.js,设置为 off 可以避免报错gop_cache on; # 支持GOP缓存,以减少首屏时间allow play all; # 允许来自任何 ip 的人拉流wait_key on;}application flv {live on;gop_cache on; #打开GOP缓存,减少首屏等待时间}application dash {live on;dash on;dash_path /tmp/dash;}application hls {live on;hls on;hls_path /opt/video/rtmp/hls;}}
}
下载OBS
链接地址:https://obsproject.com/
https://obsproject.com/wiki/install-instructions#linux
这里有相关命令
>设置obs 推流
>修改/usr/local/nginx/html/index.html下的页面
只需要将ip端口号改成对应的就行
<!DOCTYPE html><html><head><meta content="text/html; charset=utf-8" http-equiv="Content-Type"><title>Dynabook</title><style>.mainContainer {display: block;width: 1024px;margin-left: auto;margin-right: auto;}.urlInput {display: block;width: 100%;margin-left: auto;margin-right: auto;margin-top: 8px;margin-bottom: 8px;}.centeredVideo {display: block;width: 100%;height: 576px;margin-left: auto;margin-right: auto;margin-bottom: auto;}.controls {display: block;width: 100%;text-align: left;margin-left: auto;margin-right: auto;}</style>
</head><body><div class="mainContainer"><video id="videoElement" class="centeredVideo" controls autoplay width="1024" height="576">Your browser is tooold which doesn't support HTML5 video.</video></div><br><!-- <div class="controls"><button οnclick="flv_load()">加载</button><button οnclick="flv_start()">开始</button><button οnclick="flv_pause()">暂停</button><button οnclick="flv_destroy()">停止</button><input style="width:100px" type="text" name="seekpoint" /><button οnclick="flv_seekto()">跳转</button></div> --><script src="https://cdn.bootcdn.net/ajax/libs/flv.js/1.6.2/flv.min.js"></script><script>var player = document.getElementById('videoElement');if (flvjs.isSupported()) {var flvPlayer = flvjs.createPlayer({type: 'flv',isLive: true, // 如果是直播流需要设置这个值为 trueurl: 'http://192.168.140.172:80/live?port=1935&app=live&stream=test',hasAudio: true,hasVideo: true,enableStashBuffer: true,// ↑ 拉流示例地址,stream参数一定要和推流时所设置的流密钥一致});flvPlayer.attachMediaElement(videoElement);flvPlayer.load(); //加载flvPlayer.play();// flv_start();}function flv_start() {player.play();}function flv_pause() {player.pause();}function flv_destroy() {player.pause();player.unload();player.detachMediaElement();player.destroy();player = null;}function flv_seekto() {player.currentTime = parseFloat(document.getElementsByName('seekpoint')[0].value);}</script>
</body></html>
一个小坑
>记得关闭防火墙
或者用以下命令开启对应端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=1935/tcp --permanent
访问对应ip 192.168.140.172即可显示拉流画面
一些安装过程中的小tips
修改ubuntu的镜像源地址加速下载本文修改为清华大学镜像源
地址:https://mirrors.tuna.tsinghua.edu.cn/help/AOSP/
1、备份Ubuntu默认的源地址
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
2、vim /etc/apt/sources.list
将镜像源替换完成后,更新镜像源执行
sudo apt-get update
至此镜像源更新完毕
Ubuntu安装ssh
安装ssh服务器
sudo apt install openssh-server
配置ssh服务器
vim /etc/ssh/sshd_config
重启ssh服务
sudo /etc/init.d/ssh restart
配置环境变量
1、vim /etc/profile
2、export PATH="$PATH:/usr/local/nginx/sbin"
3、source /etc/profile