文章目录

  • 前期环境准备
  • nginx安装
  • rmtp模组导入
  • 问题和解决


前期环境准备

安装环境: centos7 + nginx 1.16.1
1, 安装依赖库
#安装Nginx的编译环境gcc
	yum install gcc-c++
	#nginx的http模块使用pcre解析正则表达式所以安装perl兼容的正则表达式库
	yum install -y pcre pcre-devel
 
	#nginx使用zlib对http包的内容进行gzip
	yum install -y zlib zlib-devel
 
	#nginx不仅支持http协议,还支持https(即在ssl协议上传输http),如果使用了https,需要安装OpenSSL库
	yum install -y openssl openssl-devel

nginx安装

2, 下载nginx:地址: http://nginx.org/en/download.html

cd /root
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar  -zxvf nginx-1.16.1.tar.gz 
mv  nginx-1.16.1  nginx
cd nginx
./configure --prefix=/usr/local/nginx
make
make install

此处若出现日志文件找不到路径的情况,就去nginx下建一个logs(反正我这样装没遇到过)。

接下来环境变量配置一下:

vim /etc/profile

在export下添加两个:
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin

centos7安装open stack教程 centos安装openmp_linux

cd   /usr/local/nginx/sbin

./nginx

最后在浏览器输入ip地址即可查看nginx是否启动成功,

centos7安装open stack教程 centos安装openmp_rtmp_02

或者使用

netstat -antp|grep  80

查看80端口是否是listen

centos7安装open stack教程 centos安装openmp_centos_03


也可以使用ps -ef|grep nginx看有没有对应的进程。

注意: 不将tar.gz解压后的nginx文件放在/usr/local下是为了避免koi-win文件路径重复的错误。
如果放在了同一个路径下也可以使用:

./configure --prefix=/usr/local/nginx  --conf-path=/usr/local/nginx/conf/nginx.conf

规避。

#打开80端口
iptables -I INPUT -p tcp --dport 80 -j ACCEPT

#重启nginx
nginx -s reload

rmtp模组导入

3, 从git下载最新的rtmp模组:https://github.com/arut/nginx-rtmp-module

可以直接git拉或者下载源码解压,我因为之前下过,直接解压到了/root下面就直接进行模组的导入。

cd /usr/local/nginx
./configure --add-module=/root/module/nginx-rtmp-module
make
make install

如果之前报错koi-win没有解决,到这里打模组的时候也会再次出现,而且一直导致安装不上去。

然后修改配置文件:

vim /usr/local/nginx/conf/nginx.conf

在http上面添加如下代码:

rtmp {
    server {
        listen 1935; #监听的端口 
        chunk_size 4000;
        application tv_file {
            live on; #开启实时
            hls on; #开启hls
            hls_path /usr/local/nginx/html/tv_file; #rtmp推流请求路径,文件存放路径
            hls_fragment 5s; #每个TS文件包含5秒的视频内容
        }
    }
}

如果你需要更多其他的参数,可以直接去上面给的git网址去找。

centos7安装open stack教程 centos安装openmp_linux_04

然后重启nginx:

nginx -s reload

开放端口1935:

iptables -I INPUT -p tcp --dport 1935 -j ACCEPT

查看服务到底启动没有,可以使用之前的命令:

ps -ef|grep nginx

centos7安装open stack教程 centos安装openmp_linux_05

netstat -antp|grep 1935

centos7安装open stack教程 centos安装openmp_git_06

问题和解决

1, 我的是阿里云需要配置一下端口开放:

centos7安装open stack教程 centos安装openmp_nginx_07


2, 使用windows系统的cmd窗口中的telnet命令也可以查看服务是否连接的上:

centos7安装open stack教程 centos安装openmp_rtmp_08