How to easily Make your own video streaming service! Part 1.

in #streaming3 years ago

Step 1 - The Server

You need a server

It doesn’t matter what VPS host you choose, or even if you choose to run it locally via Vagrant or other VM. I chose DigitalOcean but you can use whatever host you’re comfortable with.

You Need a Lunix OS

Thus guide is very opinionated about almost everything and especially assumes its being deployed on a fresh CentOS 7 install. But if you're savvy enough to apply this guide to your own favorite bistro then I'm sure it will work just fine. However, from here on in this guide assumes a newly launched CentOS 7 server hosted on digital Ocean.

You Need A Domain Name

OK this one isn’t strictly required but makes everything a lot easier to work with. I’m using boltstream.me for this guide, but you can use any subdomain of a domain you already own, or even just an IP address if you want.

Prepare The Server

Bring the System Up-to-Date

$ yum update -y

You need to allow some services through the firewall. On CentOS 7 you need to install the potable-services package:

$ yum install -y iptables-services
$ sytemctl enable iptables

Specifically the ports you need are:

  • tcp/22 (SSH)
  • tcp/80 (HTTP)
  • tcp/443 (HTTPS)
  • tcp/1935 (RTMP)

Put this file at /etc/sysconfig/iptables

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT -m comment --comment "ssh"
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -m comment --comment "http"
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT -m comment --comment "https"
-A INPUT -m state --state NEW -m tcp -p tcp --dport 1935 -j ACCEPT -m comment --comment "rtmp"
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

And then run

$ systemctl restart iptables

Step 2 - Installing NGINX source RPMS

I don’t like installing packages from source but sometimes it’s necessary. In this case we need to compile NGINX from source in order to add support for a few 3rd-party modules that we need. However, we’re not going to do just straight source installs, but rather we’re going to rebuild the NGINX source RPMs with the required modules.

Building NGINX with RTMP support

$ yum install -y peel-release yum-utils rpm-build wget gcc

Install NGINX dependencies

$ yum-builddep -y nginx

We're going to rebuild the nginx source RPMs so we need to add the mockbuild user:

$ user add mock build
$ su mock build
$ cd

Download the NGINX source RPM

$ yumdownloader --source nginx

Install the source RPM

$ rpm -U nginx-1.12.2-1.el7.src.rpm

This installed the NGINX source RPM in /home/mockbuild/rpmbuild:

$ find rpmbuild/
rpmbuild/
rpmbuild/SOURCES
rpmbuild/SOURCES/404.html
rpmbuild/SOURCES/50x.html
rpmbuild/SOURCES/README.dynamic
rpmbuild/SOURCES/UPGRADE-NOTES-1.6-to-1.10
rpmbuild/SOURCES/index.html
rpmbuild/SOURCES/nginx-1.12.2.tar.gz
rpmbuild/SOURCES/nginx-1.12.2.tar.gz.asc
rpmbuild/SOURCES/nginx-auto-cc-gcc.patch
rpmbuild/SOURCES/nginx-logo.png
rpmbuild/SOURCES/nginx-upgrade
rpmbuild/SOURCES/nginx-upgrade.8
rpmbuild/SOURCES/nginx.conf
rpmbuild/SOURCES/nginx.logrotate
rpmbuild/SOURCES/nginx.service
rpmbuild/SOURCES/poweredby.png
rpmbuild/SPECS
rpmbuild/SPECS/nginx.spec

The file that we’re interested in is nginx.spec. In order to add RTMP support to our NGINX install, we need to copy that file to rpmbuild/SPECS/nginx-rtmp.spec and modify it.

$ cp rpmbuild/SPECS/nginx.spec rpmbuild/SPECS/nginx-rtmp.spec

But First we need to get nginx-rtmp-module

$ wget -qO- https://github.com/sergey-dryabzhinsky/nginx-rtmp-module/archive/dev.tar.gz | tar zx

This is a fork of nginx-rtmp-module from https://github.com/arut/nginx-rtmp-module that adds a few useful features that we want.
Find and add this line in nginx-rtmp.spec:
    --with-pcre \
    --with-pcre-jit \
    --with-stream=dynamic \
    --with-stream_ssl_module \
    # add this line: 
    --add-module=/home/mockbuild/nginx-rtmp-module-dev \
%if 0%{?with_gperftools}
    --with-google_perftools_module \
%endif
    ...

Now build NGINX with RTMP support:

$ rpmbuild -bb rpmbuild/SPECS/nginx-rtmp.spec

Exit out of the mock build shell by pressing ctrl-D or type exit

Install out new NGINX RPMs

$ find /home/mockbuild/rpmbuild/RPMS -name 'nginx-*.rpm' | xargs rpm -U --force

Coin Marketplace

STEEM 0.19
TRX 0.13
JST 0.030
BTC 62714.40
ETH 3447.03
USDT 1.00
SBD 2.51