centos6nginx+rtmp流媒服务器.docx
- 文档编号:8202891
- 上传时间:2023-01-29
- 格式:DOCX
- 页数:10
- 大小:19.79KB
centos6nginx+rtmp流媒服务器.docx
《centos6nginx+rtmp流媒服务器.docx》由会员分享,可在线阅读,更多相关《centos6nginx+rtmp流媒服务器.docx(10页珍藏版)》请在冰豆网上搜索。
centos6nginx+rtmp流媒服务器
RTMP(RealTimeMessagingProtocol)实时消息传送协议是AdobeSystems公司为Flash播放器和服务器之间音频、视频和数据传输开发的私有协议
需要的软件:
Nginx运行主程序;nginx_mod_h264_streaminMP4支持模块;nginx-accesskey资源防盗链支持模块;yamdi渐进式流支持模块;
1、安装依赖包:
#yum –y update
#yum -y install gcc glibc glibc-devel make nasm pkgconfig lib-devel openssl-devel expat-devel gettext-devel libtool mhash.x86_64 perl-Digest-SHA1.x86_64 gcc-c++ glibc.i686
2、安装git工具:
//新安装的软件都放在新建的softsource文件夹下
#mkdir softsource
#cd softsource
#wget http:
//www.codemonkey.org.uk/projects/git-snapshots/git/git-latest.tar.gz
#tar xzvf git-latest.tar.gz
#cd git-2015-11-23
#autoconf
#./configure
#make && make install
# git --version
git version 2.8.1.GIT
#cd ..
hwclock--set--date="月/日/年小时:
分钟:
秒钟"
hwclock--hctosys
比如:
hwclock--set--date="07/24/201212:
33:
22"
hwclock--hctosys是让上面设置的硬件时间同系统
3、安装ffmpeg及其依赖包:
++++++++Yasm+++++++++++
#wget
#tar xzvf yasm-1.2.0.tar.gz
#cd yasm-1.2.0
#./configure
#make
#make install
#cd ..
++++++++x264+++++++++++
#git clone git:
//git.videolan.org/x264
#cd x264
#./configure --enable-shared
#make
#make install
#cd ..
++++++++LAME+++++++++++
(#wget
#wget
(安装lame-3.98.4.tar.gz, 以免在第三步的时候出现ERROR:
libmp3lame >= 3.98.3 not found错误, 需要提前安装lame.
)
#tar xzvf lame-3.98.4.tar.gz
#cd lame-3.98.4
#./configure --enable-nasm
#make
#make install
#cd ..
++++++++libogg+++++++++++
#wget http:
//downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz
#tar xzvf libogg-1.3.0.tar.gz
#cd libogg-1.3.0
#./configure
#make
#make install
echo"/usr/local/lib">/etc/ld.so.conf.d/local-libraries.conf
exportPKG_CONFIG_PATH=/usr/local/lib/pkgconfig:
$PKG_CONFIG_PATH
#cd ..
++++++++libvorbis+++++++++++
#wget http:
//downloads.xiph.org/releases/vorbis/libvorbis-1.3.3.tar.gz
#tar xzvf libvorbis-1.3.3.tar.gz
#cd libvorbis-1.3.3
#./configure
#make
#make install
#cd ..
++++++++libvpx+++++++++++
#wget
gitclonehttp:
//git.chromium.org/webm/libvpx.git
#tar -vxjf libvpx-v1.1.0.tar.bz2
#cd libvpx-v1.1.0
#./configure --enable-shared
#make
#make install
#cd ..
++++++++FAAD2+++++++++++
#wget
#tar zxvf faad2-2.7.tar.gz
#cd faad2-2.7
#./configure
#make
#make install
#cd ..
++++++++FAAC+++++++++++
#wget
#tar zxvf faac-1.28.tar.gz
#cd faac-1.28
#cd common/mp4v2/
#vi mpeg4ip.h
从123行开始定位到129行后,保持退出
修改前:
#ifdef__cplusplus
extern"C"{
#endif
char*strcasestr(constchar*haystack,constchar*needle);
#ifdef__cplusplus
}
#endif
修改后:
#ifdef__cplusplus
extern"C++"{
#endif
constchar*strcasestr(constchar*haystack,constchar*needle);
#ifdef__cplusplus
}
#endif
回到faac-1.28目录下:
cd ..
Cd ..
#./configure
#make
#make install
#cd ..
++++++++Xvid+++++++++++
#wget http:
//downloads.xvid.org/downloads/xvidcore-1.3.2.tar.gz
#tar zxvf xvidcore-1.3.2.tar.gz
#cd xvidcore/build/generic
#./configure
#make
#make install
#cd ..
++++++++ffmpeg+++++++++++
#git clone git:
//source.ffmpeg.org/ffmpeg
http:
//ffmpeg.org/releases/ffmpeg-2.8.2.tar.bz2
#cd ffmpeg
#./configure --prefix=/opt/ffmpeg/ --enable-version3 --enable-libvpx --enable-libfaac --enable-libmp3lame --enable-libvorbis --enable-libx264 --enable-libxvid --enable-shared --enable-gpl --enable-postproc --enable-nonfree --enable-avfilter --enable-pthreads
#make && make install
#cd ..
++++++++ zlib+++++++++++
#wget
#tar xzvf zlib-1.2.8.tar.gz
#cd zlib-1.2.8
#./configure --prefix=/usr/local/zlib
#make && make install
修改/etc/ld.so.conf如下:
include ld.so.conf.d/*.conf
/lib
/lib64
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/opt/ffmpeg/lib
#ldconfig
二、安装Nginx相关模块
#wget http:
//h264.code-
#tar zxvf nginx_mod_h264_streaming-2.2.7.tar.gz
#git clone git:
//
#wget
#tar zxvf pcre-8.12.tar.gz
#cd pcre-8.12
#./configure –prefix=/usr/local/pcre
#make && make install
#cd ..
下载nginx-1.9.7安装包
#wget http:
//nginx.org/download/nginx-1.9.7.tar.gz
#tar zxvf nginx-1.9.7.tar.gz
#cd nginx-1.9.7
#groupadd www
#useradd -g www www
#cd ..
#cd nginx_mod_h264_streaming-2.2.7/src
#vi ngx_http_streaming_module.c
删除以下内容if(r->zero_in_uri)
{
returnNGX_DECLINED;
}
#cd ..
#cd nginx-1.5.3
#./configure --prefix=/usr/local/nginx --add-module=../nginx_mod_h264_streaming-2.2.7
--with-http_ssl_module --with-pcre=/root/softsource/pcre-8.12 –with-zlib=/root/softsource/zlib-1.2.8 --user=www --group=www --with-http_flv_module --with-http_stub_status_module --add-module=../nginx-rtmp-module
或者
./configure--user=www--group=www--prefix=/usr/local/nginx\
--with-http_stub_status_module\
--with-http_ssl_module\
--with-http_flv_module\
--with-http_gzip_static_module\
--with-http_mp4_module\
--with-cc-opt=-I/opt/ffmpeg/include\
--with-ld-opt='-L/opt/ffmpeg/lib-Wl,-rpath=/opt/ffmpeg/lib'\
--add-module=/server/nginx_mod/nginx_mod_h264_streaming/\
--add-module=/server/nginx_mod/nginx_mod_rtmp/\
--with-pcre=/server/nginx_mod/nginx_mod_pcre
#make
#make install
#cd ..
三、安装yamdi
yadmi的作用是为flv文件添加关键帧,才能实现拖动播放
下载yadmi
#wget
安装yadmi
#tar xzvf yamdi-1.4.tar.gz
#cd yamdi-1.4
#make && make install
#cd ..
使用方法:
yamdi -i input.flv -o out.flv
给input.flv文件 添加关键帧,输出为out.flv文件
#wgethttp:
//www.openssl.org/source/openssl-1.0.1c.tar.gz
#tar-zxvfopenssl-1.0.1c.tar.gz
#./config
#make
#makeinstall
# cp/root/nginx-rtmp-module/test/usr/local/nginx/html/nginx-rtmp-module/
# cp/root/nginx-rtmp-module/stat.xsl/usr/local/nginx/html/nginx-rtmp-module/
四、修改nginx主配置文件,配置虚拟主机(注意空格)
#cd /usr/local/nginx/conf
#vi nginx.conf 修改为以下内容(根据自身情况修改):
user www www;
worker_processes 30;
error_log /usr/local/nginx/logs/error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr – $remote_user [$time_local] ‘
‘”$request” $status $bytes_sent ‘
‘”$http_referer” “$http_user_agent” ‘
‘”$gzip_ratio”‘;
keepalive_timeout 60;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;//有空格
client_max_body_size50m;
Limit_conn_zone$binary_remote_addrzone=one:
256k;
limit_conn_log_levelnotice;
access_log /usr/local/nginx/logs/access.log;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;//有空格
gzip_types text/plain;
output_buffers 1 32k;//有空格
postpone_output 1460;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
######################################################################
server {
listen 8081;
server_name 172.16.10.200;###设置主机ip
root /usr/local/nginx/html/flv_file/;
limit_rate_after 5m; ####在flv视频文件下载了5M以后开始限速
limit_rate 512k; ####速度限制为512K
index index.html;
charset utf-8;
location ~ \.flv {
flv;
}
location ~ \.mp4 {
mp4:
}
location ~ {
root html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
保存退出;
#cd ..
五、基本上已经设置完毕,但是此时我们测试的时候还需要一个支持拖拽播放的flash播放器,开源的JW Player就可以实现这样的功能
下载播放器后,上传到上面设置的/usr/local/nginx/html/目录下,并把flv视频文件也放到该目录下!
播放器放到与index.html同级。
这个时候需要安装rar:
#wget
#tar zxvf rarlinux-3.8.0.tar.gz -C /usr/local
#yum install glibc.i686
#yum install libstdc++.so.6
此时,/usr/local/rar下就会有rar命令和unrar命令。
进入到nginx下的html文件夹下载视频播放工具player.swf
#cd
#cd /usr/local/nginx/html
#ls –l
可以看到解压到的文件;
六、根据nginx的配置文件的中的配置设置端口号
#vi /etc/sysconfig/iptables
开放8081端口
#/sbin/service iptables restart
重启防火墙,设置生效
修改防火墙配置文件,所在目录/etc/sysconfig/iptables,在里面增加需要开通的端口号,如下:
1
2-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8088 -j ACCEPT
#增加的代码必须放在以下代码之上,否则不会起作用.
1
2-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
七、启动nginx后测试:
启动命令:
#/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
启动nginx的帮助文档:
#/usr/local/nginx/sbin/nginx -h
#/usr/local/nginx/sbin/nginx –s reload
查看nginx的配置是否正确:
#/usr/local/nginx/sbin/nginx –t
如果配置是正确的会显示如下内容:
Nginx.conf syntax is ok.
Nginx.conf test is successful.
#/usr/local/nginx/sbin/nginx–squit优雅关闭
#/usr/local/nginx/sbin/nginx–sstop快速关闭
#lynxlocalhost:
端口字符页面查看网页服务是否正常
http:
//127.0.0.1/player.swf?
type=http&file=mp42.mp4
说明:
#这里的127.0.0.1是自己的ip
#player.swf是我的JW Player播放器
#http是表示居于http分发方式
#mp42.mp4是我的flv视频文件
#下载开源播放器jwplayer
cd/root/softsource/
mkdirjwplayer
cdjwplayer
wget#如果不能下载,则需要到官网注册然后下载
unzipjwplayer-7.7.2.zip
#复制播放器代码到站点文件夹,根据官方文档新建html文件播放页(省略)。
cp-rjwplayer/usr/local/nginx/html/
cd/usr/local/nginx/html/
viplayer.html
#复制以下内容到player.html中保存
cd/usr/local/nginx/html
viplayer.html
#复制以下内容到player.html中保存
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- centos6nginx rtmp 服务器