GNU/Linux >> Tutoriales Linux >  >> Linux

Cómo instalar Nginx con módulo RTMP en CentOS 8

RTMP es un protocolo de mensajería en tiempo real desarrollado por Macromedia que se puede usar para transmitir audio, video y datos a través de Internet. Nginx RTMP es un transmisor de medios basado en Nginx que viene con muchas características que incluyen soporte H264/AAC, transcodificación en línea con FFmpeg, soporte de devolución de llamada HTTP y un módulo de control HTTP para grabar audio/video.

En este tutorial, le mostraremos cómo compilar Nginx con el módulo RTMP y crear una transmisión en vivo RTMP en CentOS 8.

Requisitos

  • Un nuevo CentOS 8 VPS en la plataforma en la nube Atlantic.Net
  • Una contraseña de root configurada en su servidor

Paso 1:crear un servidor en la nube de Atlantic.Net

Primero, inicie sesión en su servidor en la nube de Atlantic.Net. Cree un nuevo servidor, eligiendo CentOS 8 como sistema operativo con al menos 2 GB de RAM. Conéctese a su servidor en la nube a través de SSH e inicie sesión con las credenciales resaltadas en la parte superior de la página.

Una vez que haya iniciado sesión en su servidor CentOS 8, ejecute el siguiente comando para actualizar su sistema base con los últimos paquetes disponibles.

yum update -y

Paso 2:instalar las dependencias requeridas

Antes de comenzar, deberá instalar las dependencias necesarias para compilar Nginx con soporte RTMP. Primero, instale el paquete de grupo de herramientas de desarrollo con el siguiente comando:

yum groupinstall 'Development Tools' -y

A continuación, instale el repositorio EPEL con el siguiente comando:

yum install epel-release -y

Una vez instalado, instale otras dependencias requeridas usando el siguiente comando:

yum install wget git unzip perl perl-devel perl-ExtUtils-Embed libxslt libxslt-devel libxml2 
libxml2-devel gd gd-devel pcre-devel GeoIP GeoIP-devel -y

Una vez que todos los paquetes estén instalados, puede proceder a compilar Nginx.

Paso 3:descargue los componentes necesarios

Primero, deberá descargar los componentes necesarios para compilar Nginx con soporte RTMP.

Primero, descargue la última versión estable de Nginx con el siguiente comando:

wget http://nginx.org/download/nginx-1.18.0.tar.gz

Una vez descargado, extráigalo usando el siguiente comando:

tar -xvzf nginx-1.18.0.tar.gz

A continuación, descarga PCRE y Zlib con el siguiente comando:

wget https://ftp.pcre.org/pub/pcre/pcre-8.42.zip
wget https://www.zlib.net/zlib-1.2.11.tar.gz

Una vez descargados, extráigalos con el siguiente comando:

unzip pcre-8.42.zip
tar -xvzf zlib-1.2.11.tar.gz

Una vez extraídos ambos, descarga OpenSSL con el siguiente comando:

wget https://www.openssl.org/source/openssl-1.1.0h.tar.gz

A continuación, extraiga el paquete descargado con el siguiente comando:

tar -xzvf openssl-1.1.0h.tar.gz

A continuación, descargue la última versión del módulo RTMP de Nginx desde el repositorio de Git con el siguiente comando:

git clone https://github.com/sergey-dryabzhinsky/nginx-rtmp-module.git

Una vez que se hayan descargado todos los componentes, puede continuar con el siguiente paso.

Paso 4:instale Nginx con compatibilidad con RTMP

Primero, cambie el directorio a Nginx con el siguiente comando:

cd nginx-1.18.0/

Luego, configure Nginx con soporte RTMP usando el siguiente comando:

./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--user=nginx \
--group=nginx \
--build=CentOS \
--builddir=nginx-1.18.0 \
--with-select_module \
--with-poll_module \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_geoip_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_geoip_module=dynamic \
--with-stream_ssl_preread_module \
--with-compat \
--with-pcre=../pcre-8.42 \
--with-pcre-jit \
--with-zlib=../zlib-1.2.11 \
--with-openssl=../openssl-1.1.0h \
--with-openssl-opt=no-nextprotoneg \
--add-module=../nginx-rtmp-module \
--with-debug

Una vez que se haya completado el proceso de configuración, debería obtener el siguiente resultado:

Configuration summary
+ using threads
+ using PCRE library: ../pcre-8.42
+ using OpenSSL library: ../openssl-1.1.0h
+ using zlib library: ../zlib-1.2.11

nginx path prefix: "/etc/nginx"
nginx binary file: "/usr/sbin/nginx"
nginx modules path: "/usr/lib64/nginx/modules"
nginx configuration prefix: "/etc/nginx"
nginx configuration file: "/etc/nginx/nginx.conf"
nginx pid file: "/var/run/nginx.pid"
nginx error log file: "/var/log/nginx/error.log"
nginx http access log file: "/var/log/nginx/access.log"
nginx http client request body temporary files: "/var/cache/nginx/client_temp"
nginx http proxy temporary files: "/var/cache/nginx/proxy_temp"
nginx http fastcgi temporary files: "/var/cache/nginx/fastcgi_temp"
nginx http uwsgi temporary files: "/var/cache/nginx/uwsgi_temp"
nginx http scgi temporary files: "/var/cache/nginx/scgi_temp"

A continuación, instale Nginx con el siguiente comando:

make
make install

Después de instalar Nginx, verifique la versión instalada de Nginx con el siguiente comando:

nginx -V

Deberías obtener el siguiente resultado:

nginx version: nginx/1.18.0 (CentOS)
built by gcc 8.3.1 20191121 (Red Hat 8.3.1-5) (GCC)
built with OpenSSL 1.1.0h 27 Mar 2018
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-
path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-
path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --
user=nginx --group=nginx --build=CentOS --builddir=nginx-1.14.0 --with-select_module --with-
poll_module --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-
http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-
http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --
with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-
http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-
http_random_index_module --with-http_secure_link_module --with-http_degradation_module --
with-http_slice_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log -
-http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-
path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-
uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp 
--with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_ssl_module --
with-stream_realip_module --with-stream_geoip_module=dynamic --with-
stream_ssl_preread_module --with-compat --with-pcre=../pcre-8.42 --with-pcre-jit --with-
zlib=../zlib-1.2.11 --with-openssl=../openssl-1.1.0h --with-openssl-opt=no-nextprotoneg --add-
module=../nginx-rtmp-module --with-debug

Paso 5:cree un archivo de servicio de Systemd para Nginx

A continuación, deberá crear un archivo de servicio Nginx para administrar el servicio Nginx. Puedes crearlo con el siguiente comando:

nano /lib/systemd/system/nginx.service

Agregue las siguientes líneas:

[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

Guarde y cierre el archivo cuando haya terminado, luego vuelva a cargar el demonio systemd con el siguiente comando:

systemctl daemon-reload

A continuación, inicie Nginx y habilítelo para que se inicie al reiniciar el sistema con el siguiente comando:

systemctl start nginx
systemctl enable nginx

Paso 6:configurar Nginx para usar RTMP

First, create a backup copy of the Nginx main configuration file with the following command:

mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak

A continuación, cree un nuevo archivo de configuración de Nginx con el siguiente comando:

nano /etc/nginx/nginx.conf

Agregue las siguientes líneas:

worker_processes auto;
events {
worker_connections 1024;
}

# RTMP configuration
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;

# Define the Application
application show {
live on;
# Turn on HLS
hls on;
hls_path /mnt/hls/;
hls_fragment 3;
hls_playlist_length 60;
# disable consuming the stream from nginx as rtmp
deny play all;
}

}
}

http {
sendfile off;
tcp_nopush on;
aio on;
directio 512;
default_type application/octet-stream;

server {
listen 8080;

location / {
# Disable cache
add_header 'Cache-Control' 'no-cache';

# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';

# allow CORS preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}

types {
application/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}

root /mnt/;
}
}
}

Guarde y cierre el archivo, luego cree un nuevo directorio para la configuración de HLS y otorgue la propiedad adecuada:

mkdir -p /mnt/hls
chown -R nginx:nginx /mnt/hls

Guarde y cierre el archivo cuando haya terminado.

Paso 7:Crear transmisión en vivo RTMP

A continuación, deberá crear una transmisión de video RTMP y crear una nueva transmisión RTMP en vivo. Puede hacerlo editando el archivo de configuración principal de Nginx:

nano /etc/nginx/nginx.conf

Encuentra las siguientes líneas:

hls_playlist_length 60;
# disable consuming the stream from nginx as rtmp
deny play all;
}

Agregue las siguientes líneas exactamente debajo de la línea anterior:

application vod {
play /mnt/mp4s;
}

# RTMP stream using OBS
application stream {
live on;
}

Guarde y cierre el archivo, luego reinicie el servicio Nginx con el siguiente comando:

systemctl restart nginx

A continuación, cree un directorio para almacenar video MP4:

mkdir -p /mnt/mp4s

A continuación, descargue el video de muestra usando el siguiente comando:

cd /mnt/mp4s
wget https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4 -O 
myfile.mp4

A continuación, asigne la propiedad adecuada al directorio /mnt/mp4s:

chown -R nginx:nginx /mnt/mp4s

Paso 8:instale FFmpeg e inicie el servidor de transmisión

Primero, deberá instalar FFmpeg en su servidor. De forma predeterminada, no está instalado en el repositorio predeterminado de CentOS 8, por lo que deberá habilitar el repositorio de Powertool en su sistema. Puede habilitarlo con el siguiente comando:

yum install epel-release dnf-utils
yum-config-manager --set-enabled PowerTools
yum-config-manager --add-repo=https://negativo17.org/repos/epel-multimedia.repo

A continuación, instale FFmpeg con el siguiente comando:

yum install ffmpeg -y

Una vez que FFmpeg esté instalado, inicie el servidor de transmisión con el siguiente comando:

ffmpeg -re -i /mnt/mp4s/myfile.mp4 -vcodec libx264 -vprofile baseline -g 30 -acodec aac -strict -2 -
f flv rtmp://your-server-ip:1935/show/vod

Paso 9:Pruebe la transmisión RTMP

A continuación, deberá probar la transmisión de vod RTMP con el reproductor multimedia VLC.

Una vez que el sistema cliente, abra el reproductor multimedia VLS, vaya a VLC Media => Open Network Stream . Debería ver la siguiente pantalla:

Proporcione la URL de su servidor de transmisión RTMP y haga clic en Reproducir botón.

Una vez que esté conectado con éxito, debería ver su video MP4 en la siguiente pantalla:

Conclusión

En el tutorial anterior, aprendió cómo instalar Nginx con soporte RTMP. También aprendió cómo configurar Nginx para transmitir video MP4 y reproducirlo con el reproductor multimedia VLC desde el sistema remoto. ¡Intente instalar Nginx con soporte RTMP en VPS Hosting de Atlantic.Net hoy!

Obtenga más información sobre nuestros servicios de alojamiento VPS y servidores privados virtuales.


Linux
  1. Cómo instalar phpMyAdmin con Nginx en CentOS 7

  2. Cómo instalar Nginx con módulo RTMP en CentOS 7

  3. Cómo instalar SuiteCRM con Nginx en CentOS 7

  4. Cómo instalar ModSecurity con Nginx en Rocky Linux 8

  5. Instalar Nginx en CentOS 6

Cómo instalar Java en CentOS 8

Cómo instalar Yarn en CentOS 8

Cómo instalar Bludit CMS con NGINX en Ubuntu 20.04

Cómo instalar Kubernetes con Minikube en CentOS 8

Cómo instalar Talkyard Forum con Nginx en Ubuntu 18.04

¿Cómo instalar Nginx en CentOS 7?