第一部分
主要步骤及命令记录:
1、下载nginx,地址http://nginx.org/en/download.html,选择最新版本下载、解压。当前最新版为:nginx-1.7.9。
2、为了增加对rtmp的支持,下载nginx-rtmp-module,地址:https://github.com/arut/nginx-rtmp-module#example-nginxconf,这个是个开源项目。解压后,为了和我在网上看到的教程同步,我改了文件夹名字,将其改成了nginx-rtmp-module。然后将其放到/home/user/目录下(今天才知道h和user非常像的目录usr是Unix System Resource的意思)。
- cp -rf 123/nginx-rtmp-module/ /home/user/
3、进入到nginx-1.7.9文件夹目录下,执行如下命令:
- ./configure --prefix=/usr/local/nginx --add-module=/home/user/nginx-rtmp-module --with-http_ssl_module
4、待上述命令执行完成之后,执行如下命令安装:
5、make完成之后,执行:
6、希望能顺利完成以上步骤。安装完成后,打开nginx的配置文件nginx.conf进行配置:在root前提下执行下面命令打开nginx.conf
- gedit /usr/local/nginx/conf/nginx.conf
7、nginx.conf中增加rtmp的支持,下面是修改过得文件,以后可能还会修改更新:
8、保存完配置文件之后,启动nginx服务
- /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
9、启动时可能会遇到端口占用的问题,
- nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:1935 failed (98: Address already in use)
- nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
- nginx: [emerg] still could not bind()
上述的显示是因为我的nginx服务已经在运行了,所以再启动时1935和80端口会占用,可以使用下面命令来终止服务:
当遇到不是因为服务已经启动造成的端口占用时可以通过下面命令来查看是哪个线程占用的端口,然后杀死他(例如端口号1935):
然后系统会显示:
- tcp 0 0 0.0.0.0:1935 0.0.0.0:* LISTEN 20211/nginx.conf
注意到这个20211就是线程号,后面跟着的是服务名字,也就是说nginx占用着1935端口,可以使用下面命令杀死他:
10、然后再启动服务,当服务启动成功的话,在本机浏览器输入:http://localhost/
- Welcome to nginx!
-
- If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
-
- For online documentation and support please refer to nginx.org.
- Commercial support is available at nginx.com.
-
- Thank you for using nginx.
如果出现上述内容,则服务成功启动。
11、可以通过netstat -ltn 命令可以看到端口的监听情况.
- 激活Internet连接 (仅服务器)
- Proto Recv-Q Send-Q Local Address Foreign Address State
- tcp 0 0 0.0.0.0:1935 0.0.0.0:* LISTEN
- tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
- tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN
- tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
- tcp6 0 0 ::1:631 :::* LISTEN
80是nginx默认的http监听端口。
12、用ffmpeg推本地视频头流到nginx,myapp上,用如下命令:
-
ffmpeg -f dshow -i video="Integrated Webcam" -s 640x360 -vcodec libx264 -b:v 1000k -ab 128k -f flv rtmp://192.168.31.102:1935/myapp/test1
在VLC上打开网络串流 ,填写
rtmp://192.168.31.102:1935/myapp/test1
可以看到监控画面,有大约2~3秒的延时。
明天继续,将流推送到hls上……