作者个人研发在高并发场景下提供了一个简单、稳定、可扩展的延迟消息队列框架,具有精准的定时任务和延迟队列处理功能。开源半年多以来,已成功为十几家中小企业提供精准定时调度解决方案,经受住了生产环境的考验。为了造福更多的童鞋,这里提供一个开源的框架地址:https://github.com/sunshinelyz/mykit-delay前面写过,这几年直播行业比较火,不管是直播传统行业的直播,或者购物、游戏、教育,都涉及到直播。作为一个在互联网行业奋斗多年的小伙伴,有没有想过如果使用Nginx我们如何搭建直播环境呢?别着急,接下来我们就一起使用Nginx搭建直播环境。安装Nginx注意事项:这里以CentOS6.8服务器为例,以root用户安装Nginx。1.安装依赖环境yum-yinstallwgetgcc-c++ncursesncurses-develcmakemakeperlbisonopensslopenssl-develgcc*libxml2libxml2-develcurl-devellibjpeg*libpng*freetype*autoconfautomakezlib*fiex*libxml*libmcrypt*libtool-ltdl-devel*libaiolibaio-develbzrlibtoolwget:httpsinstallation/www.openssl.org/source/openssl-1.0.2s.tar.gztar-zxvfopenssl-1.0.2s.tar.gzcd/usr/local/src/openssl-1.0.2s./config--prefix=/usr/local/openssl-1.0.2smakemakeinstall3.安装pcrewgethttps://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gztar-zxvfpcre-8.43.tar.gzcd/usr/local/src/pcre-8.43./configure--prefix=/usr/local/pcre-8.43makemakeinstall4。安装zlibwgethttps://sourceforge.net/projects/libpng/files/zlib/1.2.11/zlib-1.2.11.tar.gztar-zxvfzlib-1.2。11.tar.gzcd/usr/local/src/zlib-1.2.11./configure--prefix=/usr/local/zlib-1.2.11makemake5.下载nginx-rtmp-moduleenginx-rtmp-module官方github地址:https://github.com/arut/nginx-rtmp-module使用命令:gitclonehttps://github.com/arut/nginx-rtmp-module.git6。安装Nginxwgethttp://nginx.org/download/nginx-1.19.1.tar.gztar-zxvfnginx-1.19.1.tar.gzcd/usr/local/src/nginx-1.19.1./configure--prefix=/usr/local/nginx-1.19.1--with-openssl=/usr/local/src/openssl-1.0.2s--with-pcre=/usr/local/src/pcre-8.43--with-zlib=/usr/local/src/zlib-1.2.11--add-module=/usr/local/src/nginx-rtmp-module--with-http_ssl_modulemakemakeinstall这里需要注意的是:安装Nginx时,指定openssl、pcre和zlib的源码解压目录,并安装完成Nginx配置文件的完整路径为:/usr/local/nginx-1.19.1/conf/nginx.conf配置Nginx配置Nginx主要是配置Nginx的nginx.conf文件。我们可以在命令行输入以下命令来编辑nginx.conf文件。vim/usr/local/nginx-1.19.1/conf/nginx.conf在文件中添加以下内容。rtmp{server{listen1935;#monitoredportchunk_size4096;applicationhls{#rtmppushrequestpathliveon;hlson;hls_path/usr/share/nginx/html/hls;hls_fragment5s;}}}其中hls_path需要有可读写权限.接下来,我们创建/usr/share/nginx/html/hls目录。mkdir-p/usr/share/nginx/html/hlschmod-R777/usr/share/nginx/html/hls接下来修改http:server{listen81;server_namelocalhost;#charsetkoi8-r;#access_loglogs/host中的server模块。access.logmain;location/{root/usr/share/nginx/html;indexindex.htmlindex.htm;}#error_page404/404.html;#redirectservererrorpagestothestaticpage/50x.html#error_page500502503504/50x.html;location=/50x。html{roothtml;}}并启动Nginx:/usr/local/nginx-1.19.1/sbin/nginx-c/usr/local/nginx-1.19.1/conf/nginx.conf使用OBS推送OBS(打开Broadcaster软件)是免费的开源软件,用于通过Internet流式传输实时内容。需要下载这个软件,用这个软件推流(电脑没有摄像头,好像安装不了。。。)OBS的下载链接是:https://obsproject.com/zh-cn/下载。安装完成后,桌面上会出现如下图所示的图标。打开之后,我们需要有一个场景,在这个场景中,有一个流源(可以是一个窗口,如果选择了视频,会自动识别摄像头),接下来就是设置了.配置中最需要注意的是流的配置。由于是自建流媒体服务器,我们配置如下。rtmp://你的服务器ip:port(1935)/live#URL填入推流地址并设置好,我们就可以开始推流了。pulltestaddress推荐一个pulltest地址,可以测试各种协议的pulltest,需要注意图中几个地方,因为我们使用的是rtmp协议,所以我们选择这一栏,在填写我们的pushflow我们在上面的obs设置中配置的底部地址和流的名称,启动,okdone!!!转载本文请联系冰川科技公众号。
