第一步,安装环境:
yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel
yum -y install git wget
yum -y install pcre-devel
第二步,进入opt目录下载nginx-rtmp-module
git clone https://github.com/arut/nginx-rtmp-module.git
第三步,下载安装nginx
wget http://nginx.org/download/nginx-1.14.1.tar.gz
tar -zxvf nginx-1.14.1.tar.gz
cd nginx-1.14.1
./configure --prefix=/usr/local/nginx --add-module=/opt/nginx-rtmp-module --with-http_ssl_module
make && make install
第四步,配置编辑nginx
1. 创建流媒体文件存放路径
mkdir -p /www/rtmp/hls
chmod 777 -R /www/
2. 编辑nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
#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;
}
rtmp {
server{
listen 6666; #推流端口 可自定义
chunk_size 4096;
application rtmplive{
live on;
max_connections 5; #最大观看人数
}
application hls{
live on;
hls on;
hls_path /www/rtmp/hls; #录像文件存储位置
hls_fragment 5s; #视频切片大小
}
}
}
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 808;
server_name 10.66.66.23;
#charset koi8-r;
#access_log logs/host.access.log main;
第五步,关闭防火墙
systemctl stop firewalld
第六步,运行nginx
cd /usr/local/nginx/sbin
./nginx
第七步,/usr/local/nginx/html 路径下创建live.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>直播</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet">
</head>
<body>
<video id=example-video width=960 height=540 class="video-js vjs-default-skin" controls>
<source
src="http://10.66.66.23:6666/hls/tre.m3u8"
type="application/x-mpegURL">
</video>
<script src="https://unpkg.com/video.js/dist/video.js"></script>
<script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>
<script>
var player = videojs('example-video');
player.play();
</script>
</body>
</html>
最后,检查nginx运行情况
netstat -tlaupn|grep nginx
ps -ef|grep nginx
可以看到nginx服务运行正常,推流监听端口6666,web直播页面808已经ok
PS:RMTP直播软件,流媒体查看软件下载地址: