简易RTMP流媒体服务器搭建 一

说在前面:

上一次搭建rtmp服务器就是因为有几个人一起看电影的需求,最后也成功搭建好了也不是不能看的服务器进行推拉流。有了上次的经验这次对RTMP服务器的搭建进行小小的总结~

本篇为记录文章,坑多!!如果想要直接上看二篇

一、硬件准备

(家中有服务器和网络条件的可以跳过这一步)

因为是临时的看电影需求这里就选择阿里云的按量付费云主机(用完就删)

tips:按量付费主机需要100余额才能开启

注册直接跳过,进入ecs,

高主频通用型4g16核主机

系统centos最新版(8.2)

带宽按固定宽带计费10m(理论上几个人观看就设置为几m)

登录凭证自定义密码(习惯密码登录)

在这里插入图片描述

至此创建好实例等待启动即可

为了后面顺利进行要配置安全组添加80,8080还有1935端口的入口

在这里插入图片描述

二、服务端软件安装

1.连接服务器

要想安装软件就得先连接上服务器(废话

windows下推荐FinalShell作为ssh客户端 点击下载

ssh连接的方法大同小异,输入服务器外网ip和密码即可(用户名默认为root

当界面出现[root@xxxxxx ~]# 时,即为连接成功

在这里插入图片描述

2.安装nginx(官网

根据官网的推荐我们选择yum来安装nginx(编译安装太麻烦了55)

1.安装前的准备

sudo yum install yum-utils

2.创建必要文件

vi /etc/yum.repos.d/nginx.repo

3.将下列配置复制进文件

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

4.保存并退出

按下esc后输入:wq 回车

5.运行安装

sudo yum install nginx

至此nginx就安装成功了

然后就会发现偷懒的方法安装好了nginx后想要添加rtmp扩展更加复杂,所以我们删除掉nginx(hhhh

yum remove nginx

下来通过源码编译来安装~

1.安装环境

sudo yum install git gcc make pcre-devel openssl-devel

2.下载rtmp扩展

sudo git clone git://github.com/arut/nginx-rtmp-module.git

3.下载nginx

sudo wget http://nginx.org/download/nginx-1.12.0.tar.gz
sudo tar xzf nginx-1.12.0.tar.gz
cd nginx-1.12.0

4.编译安装nginx和扩展

./configure --with-http_ssl_module --add-module=../nginx-rtmp-module
make 
make install

本想着一步到位!结果他抱错了q w q

src/core/ngx_murmurhash.c: In function ‘ngx_murmur_hash2’:
src/core/ngx_murmurhash.c:37:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
         h ^= data[2] << 16;
         ~~^~~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:38:5: note: here
     case 2:
     ^~~~
src/core/ngx_murmurhash.c:39:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
         h ^= data[1] << 8;
         ~~^~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:40:5: note: here
     case 1:
     ^~~~

也不是什么大问题,是安装时候把警告当成错误处理了。我们只需要一些小小的改动即可~

5.修复

vi objs/Makefile

删除第二行的-Werror (按i进入插入模式才可以进行编辑哦!)

在这里插入图片描述

vi的保存退出方法同上!!

接着兴冲冲的make一下,太棒了又报错啦

make -f objs/Makefile
make[1]: Entering directory '/root/nginx-1.12.0'
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter  -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I ../nginx-rtmp-module -I objs \
        -o objs/src/os/unix/ngx_user.o \
        src/os/unix/ngx_user.c
src/os/unix/ngx_user.c: In function ‘ngx_libc_crypt’:
src/os/unix/ngx_user.c:36:7: error: ‘struct crypt_data’ has no member named ‘current_salt’
     cd.current_salt[0] = ~salt[0];
       ^
make[1]: *** [objs/Makefile:858: objs/src/os/unix/ngx_user.o] Error 1
make[1]: Leaving directory '/root/nginx-1.12.0'
make: *** [Makefile:8: build] Error 2

报错说没有名字叫current_salt的。。这是因为centos在8.0的改动引起的所以我们要么换低版本系统要么换高版本nginx(为什么我一开始不用最新版呢??)


6.下载最新版nginx

cd ..
sudo wget http://nginx.org/download/nginx-1.19.1.tar.gz
tar xzf nginx-1.19.1.tar.gz
cd nginx-1.19.1
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module

7.去掉-Werror(方法同5)

8.编译安装(方法同4 除第一行外)

9.启动nginx

sudo /usr/local/nginx/sbin/nginx

启动成功后在浏览器输入服务器外网ip就会显示下面画面

在这里插入图片描述

3.配置Nginx

1.进入配置文件

vi /usr/local/nginx/conf/nginx.conf

2.在命令行模式下一直按着d(dd为删除当前行)把内容删光

3.替换为以下

#user  nobody;
worker_processes  1;

error_log  logs/error.log debug;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       8080;
        server_name  localhost;

        # sample handlers
        #location /on_play {
        #    if ($arg_pageUrl ~* localhost) {
        #        return 201;
        #    }
        #    return 202;
        #}
        #location /on_publish {
        #    return 201;
        #}

        #location /vod {
        #    alias /var/myvideos;
        #}

        # rtmp stat
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            # you can move stat.xsl to a different location
            root /usr/build/nginx-rtmp-module;
        }

        # rtmp control
        location /control {
            rtmp_control all;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

rtmp {
    server {
        listen 1935;
        ping 30s;
        notify_method get;

        application myapp {
            live on;

            # sample play/publish handlers
            #on_play http://localhost:8080/on_play;
            #on_publish http://localhost:8080/on_publish;

            # sample recorder
            #recorder rec1 {
            #    record all;
            #    record_interval 30s;
            #    record_path /tmp;
            #    record_unique on;
            #}

            # sample HLS
            #hls on;
            #hls_path /tmp/hls;
            #hls_sync 100ms;
        }

        # Video on demand
        #application vod {
        #    play /var/Videos;
        #}

        # Video on demand over HTTP
        #application vod_http {
        #    play http://localhost:8080/vod/;
        #}
    }
}

4.重启nginx

sudo /usr/local/nginx/sbin/nginx -s stop
sudo /usr/local/nginx/sbin/nginx

服务端配置就到这里!

三、客户端软件安装

1.推流客户端

像是主播一样我们可以选择OBS来推流到服务器。下载链接

进入设置

在这里插入图片描述

修改推流服务器

在这里插入图片描述

服务器为rtmp://你的ip/myapp(可在配置中修改)

串流秘锁相当于直播间的房间号仅用于标示~连接时候填写

设置好后开始推流即可

2.拉流客户端

推荐使用VLC(播放器中老大哥
下载地址:官网

在播放器中在串流地址中填写你的rtmp地址+/秘锁即可

例:rtmp://服务器ip/myapp/mystream

  • 1
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值