相关系列
【nginx-rtmp】搭建直播流服务器(一):安装nginx
【nginx-rtmp】搭建直播流服务器(二):搭建rtmp服务器
最近接到的新任务:用nginx-rtmp搭建一个基本的直播流服务器,为后续的其他开发做下知识储备。就又是从0摸起,真的每天都在学习新东西……吐血。
目录
Nginx
介绍
是个做服务器的好东西?暂时还没摸索清楚,后补。
安装方法(默认说的是linux)
通用方法
1.将nginx源码和nginx-rtmp模块源码下载一起编译,参考基于nginx的rtmp直播服务器
非典型安装方法
1.参考官网这个可以成功安装最新稳定版的Nginx,无其他报错问题,官方的就是靠谱。
http://nginx.org/en/linux_packages.html
装了两次centos和Ubuntu,centos上安装挺正常,Ubuntu上安装按照官方说明一次性安装指令执行会出错,需要单独安装。
2.需要增加rtmp的模块
参考链接:Nginx加载新的模块,编译报错记录
GitHub:https://github.com/arut/nginx-rtmp-module
下载页面:http://arut.github.io/nginx-rtmp-module/
1.获取nginx的版本号和配置参数
nginx -V
2.拷贝出现的configure参数
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
3.获取nginx源码,版本号根据前面获得的版本号
wget http://nginx.org/download/nginx-1.18.0.tar.gz
4.获取nginx-rtmp模块,如果linux下载比较慢可以到https://github.com/arut/nginx-rtmp-module下载,3和4的文件要在同一个文件夹下面
git clone https://github.com/arut/nginx-rtmp-module.git
5.目录结构如下,已经解压好了,arut-nginx-rtmp-module-791b613
这个名字是由于PC下载的命名方式跟直接gitclone下来不太一样,但确保里面是rtmp模块的源码就可以,名字不影响使用
tar zxvf nginx-1.18.0.tar.gz
tar zxvf arut-nginx-rtmp-module-791b613
[root@localhost nginx]# ls
arut-nginx-rtmp-module-791b613 arut-nginx-rtmp-module-v1.2.1-0-g791b613.tar.gz nginx-1.18.0 nginx-1.18.0.tar.gz
6.进入nginx源码目录,修改configure配置文件,在原来的配置上加上--add-module=../nginx-rtmp文件夹路径
,我这里是--add-module=../arut-nginx-rtmp-module-791b613
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=../arut-nginx-rtmp-module-791b613
7.编译
make
8.编译成功后,文件生成在nginx-1.18.0目录下的objs
文件夹,有生成nginx就可以
[root@localhost nginx-1.18.0]# ls objs/
addon Makefile nginx.8 ngx_auto_headers.h ngx_modules.o
autoconf.err nginx ngx_auto_config.h ngx_modules.c src
9.替换nginx
[root@localhost nginx]# which nginx
/usr/sbin/nginx
cd /usr/sbin/
cp nginx{,.bak}
cp /opt/rtmp/nginx-1.12.2/objs/nginx
cp /opt/rtmp/nginx-1.12.2/objs/nginx .
nginx
nginx -V
至此nginx安装成功,下面开始搭建服务器。