安装
nginx
#Nginx安装网上一搜一堆,其实就是下载nginx后 tar zxvf解压然后./configure 看看缺什么,然后yum imstanll什么。
最后省事一些注册到系统服务(/etc/init.d/nginx 配置文件网上一堆)
#基础组件
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
yum install -y wget
#下载与安装
wget nginx.tar
tar zxvf nginx.tar
./configure
make & make install
#注册到系统服务
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginxlive.conf" <----这个配置文件随意改成你要的
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
killall -9 nginx
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
#赋予权限
chmod 755 /etc/init.d/nginx
#添加到服务
chkconfig --add nginx
#开机启动
chkconfig --level 345 nginx on
nginx-rtmp-module
#安装此组件到nginx
nginx路径下
./configure --add-module=你的路径/nginx-rtmp-module --with-http_ssl_module --with-debug
make & make install
nginx-rtmp-module Config
#----参考资料
#----https://github.com/arut/nginx-rtmp-module
#----https://github.com/arut/nginx-rtmp-module/wiki/Directives
#----https://github.com/arut/nginx-rtmp-module
#----https://github.com/arut/nginx-rtmp-module/wiki/Directives
worker_processes 1;
events {
worker_connections 1024;
}
#rtmp协议头 监听1935端口 暴露application作为domain来接入
#有了这个才可以通过 rtmp://ip:post/domain/streamKey 进行推拉
rtmp {
server {
#========================
#========RTMP配置========
#========================
#监听端口,记得设置你的防火墙iptables
listen 1935;
#网络流块大小,数字越大服务器压力越小,MIN:128
chunk_size 4096;
#超时默认60s
timeout 60s;
#保活ping可以理解为心跳
#ping为主动发起心跳,ping_timeout为对方30s无响应
ping 3m;
ping_timeout 30s;
#缓冲区长度默认1000ms
buflen 5000ms;
application liveOnline {
#开启RTMP直播
live on;
#最大直播连接数
max_connections 1024;
#========================
#========HLS配置=========
#========================
#一定要开启HLS否则无法使用m3u8拉流
#开启HLS直播
hls on;
#HLS的m3u8文件保存路径
hls_path /tmp/liveOnlineHLS;
#每隔N秒保存1次
hls_fragment 1s;
#继续播放位置
hls_continuous on;
#hls播放列表长度
hls_playlist_length 3s;
#为了防止音视频不同步每隔n毫秒进行同步
hls_sync 50ms;
#开启hls加密
#hls_keys on;
#加密文件路径
#hls_key_path /tmp/hlskeys;
#共用同一个key的视频切片数
#hls_fragments_per_key 10;
#访问地址
#hls_key_url http://127.0.0.1/hlskeys/;
#旧片段保存默认关
#hls_continuous on;
#将ts碎片文件根据不同str eamkey放到子目录中
#hls_nested on;
#============================
#========录制配置低配========
#============================
#我们可以通过控制中心来开启录制和关闭录制,可以有若干个录制配置
recorder base { #启用录制
record all manual; #手动控制录制启停
record_suffix _record.flv; # _record结尾
record_interval 10s; #每隔n秒写一次 0是无间隔
record_path /tmp/recfile; #录制保存地址
record_append on; #新流追加到老流中
record_max_size 512000k; #录制文件最大值
}
#============================
#========录制配置高配========
#============================
recorder vip { #启用录制
record all manual; #手动控制录制启停
record_suffix _record.mp4; # _record结尾.mp4格式
record_interval 1s; #每隔n秒写一次 0是无间隔
record_path /tmp/recfile/vip; #录制保存地址
record_append on; #新流追加到老流中
record_max_size 3145728k; #录制文件最大值
}
#========================
#==录制完毕文件转为MP4===
#========================
exec_record_done bash -c "ffmpeg -i $path -y -vcodec copy -acodec copy $dirname/$basename.mp4;rm -rf $path";
#========================
#========推拉认证========
#========================
#推
on_publish http://xxx;
#推完成
on_publish_done http:/xxx;
#拉
on_play http://xxx;
#拉完成
on_play_done http://xxx;
#推流白名单
allow publish YouIp;
allow publish YouIp;
deny publish all;
}
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#保活timieout
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
#HLS拉流其实是提供一个http来访问*.ts文件目录
location /liveOnlineHLS {
types {
#m3u8 type设置
application/vnd.apple.mpegurl m3u8;
#ts分片文件设置
video/mp2t ts;
}
#hls m3u8文件目录
root /tmp;
add_header Cache-Control no-cache;
}
#通过这里可以在推拉中进行监听nginx-rtmp-module状态
location /liveStat { #监听器
#启动流监听/stat为访问domain
#监听保存到stat.xsl
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl { #状态xsl
#指向nginx-rtmp-module目录
#该目录中有stat.xsl及支持文件
root /software/nginxrtmp/nginx-rtmp-module-master/;
}
#这个就是控制中心入口,基本上很多控制命令都要从这个control域来发出,比如录制等
location /control { #控制器
rtmp_control all;
}
#播放我们录制的文件,录制文件我保存到mp4了,flv ios是拉不了的
location /vod/{ #hls点播地址
alias /tmp/recfile/;
}
}
}
上面的配置我这个版本的project一直在用,后期还有很多要调整优化的,以后有空再分享
HLS拉流是要做访问控制的恩,nginx-rtmp-module是没有提供对HTTP HLS拉流的on_{event}事件的!
这里要自己解决喽