LoginSignup
11
10

More than 5 years have passed since last update.

Vagrant+nginxでストリーミングサーバーを作る方法

Posted at

ほとんど参考資料のままですが、ストリーミングサーバーをVagrantで作ったので共有します!

環境

サーバー構築

ストリーミングを中継するサーバーを構築します。

CentOS7のイメージをダウンロード

vagrant box add centos_7_x64_live_stream https://github.com/holms/vagrant-centos7-box/releases/download/7.1.1503.001/CentOS-7.1.1503-x86_64-netboot.box

mkdir vagrant_centos7_live_stream
cd vagrant_centos7_live_stream
vagrant init centos_7_x64_live_stream

ipアドレスを指定

Vagrantfile
# vi Vagrantfile
...
config.vm.network "private_network", ip: "192.168.33.44"
...

モジュール導入

起動後ログインして、各種設定を行います。

vagrant up
vagrant ssh

nginxをインストール

sudo su
yum update
yum groupinstall "Development Tools"
yum -y install pcre-devel zlib-devel openssl-devel

cd /usr/local/src/
wget http://nginx.org/download/nginx-1.8.0.tar.gz
sudo wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar -zxvf nginx-1.8.0.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
unzip master.zip

# build
cd nginx-1.8.0
./configure --with-http_ssl_module --add-module=../nginx-rtmp-module-master
make
make install

設定ファイルの一番下に以下の設定を追加

/usr/local/nginx/conf/nginx.conf
rtmp {
        server {
            listen 1935;
            chunk_size 4096;

            application live {
                live on;
                record off;
                wait_video on;
            }
        }
    }

iptablesをインストール

yum install iptables-services

firewallをオフ

systemctl stop firewalld

iptablesを無効化

systemctl enable iptables
systemctl stop iptables

nginxの起動確認

nginxを起動したら、Macブラウザからhttp://192.168.33.44にアクセスしてnginxが起動していることを確認します。

#起動
sudo /usr/local/nginx/sbin/nginx

#停止
sudo /usr/local/nginx/sbin/nginx -s quit

映像の配信と受信

詳しい手順は参考資料に譲りますが、サーバーの構築が完了したら、
OBSでrtmp://192.168.33.44/liveに動画と音声を配信開始します。(映像キャプチャデバイス+音声)
続いて、VLC media playerからhttp://192.168.33.44/live/testにアクセスすると、映像と音声が受信できるようになりました。

参考資料

11
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10