nginx-rtmp-module icon indicating copy to clipboard operation
nginx-rtmp-module copied to clipboard

NGINX + RTMP from source on CentOS7

Open karlisk opened this issue 7 years ago • 1 comments

Not necessarily an issue, just wanted to share this with anyone and everyone to whom this might be of concern...

First of all, credit where credit is due - sources of information that resulted in this: https://github.com/rackmaze/nginx-lua-centos7 http://rtoaam.drandf.com/?p=180 http://repoforge.org/package/rebuild.html https://access.redhat.com/solutions/1189 ...and of course https://github.com/arut/nginx-rtmp-module/wiki/Installing-via-Build

NOTE/WARNING: I haven't fully tested this past just installing and starting the NGINX server so far.

## Step one - install EPEL repo: Not necessarily required on the servers you're going to run NGINX+RTMP on. Same as commented on "Step Three" - you don't need to have this on your production environment and can decide to have this only on your build machine for preparing the RPMs. sudo yum install epel-release

## Step two - install prerequisites: Also only necessary for the build process. sudo yum groupinstall --enablerepo=epel 'Development Tools'

## Step two - install NGINX+RTPM RPM build prerequisites: The following tools allow to prepare the build enviroment, build RPMs and the GIT package allows to clone the RTMP module (as well as pull the changes/updates later). You don't need to install these on every server you're going to run NGINX+RTMP on - you can have these installed on an offline "build" machine and transfer the RPM package to the server(-s) that you intend to run it on. sudo yum -y install yum-utils rpm-build redhat-rpm-config rpmdevtools git

## Step three - create 'builder' user required for the build process: Also needed only for the build process. Not required when installing the built RPM. sudo useradd builder -u 1000 -m -G users,wheel

## Step three - prepare the build environment: Run the following command to prepare the RPM build environment. A new folder 'rpmbuild' and a variable file '.rpmmacros' that are needed only for the build process. rpmdev-setuptree

## Step four - add the nginx.org key and repo: First, add the key: wget http://nginx.org/keys/nginx_signing.key && sudo rpm --import nginx_signing.key Then add the repo by creating a file(replace 'mainline' with 'stable' if you prefer/require the stable version): /etc/yum.repos.d/nginx.repo Contents of the file:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
enabled=1
gpgcheck=1

[nginx-source]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/SRPMS/
enabled=1
gpgcheck=1

## Step five - download the latest source RPM: Downloads all the necessary files from nginx repo for the latest NGINX version (you can include the version if you're trying to install a specific version). yum update && yumdownloader --source nginx An RPM file should be present in your current directory that you'll need for the build process, which also provides info about the pre-requisites that you will need to install on your production servers,

## Step six - install the required dependencies for NGINX: The following command will download and install the required packages in your build enviroment, don't bother running it on your production servers if you don't have the necessary packages from step three installed. sudo yum-builddep nginx-1.13.9-1.el7_4.ngx.src.rpm The necessary dependencies you can install manually on your production enviroment by issuing: sudo yum install pcre-devel openssl-devel libxml2-devel libxslt-devel gd-devel perl-ExtUtils-Embed GeoIP-devel

## Step seven - clone the RTMP module: Clone the module files from the repo to somewhere where the build process can access (for example, in your current users Home directory). This is also required only for the build process itself. git clone https://github.com/arut/nginx-rtmp-module.git

## Step eight - download the NGINX installation source files: The following command should populate the 'rpmbuild' directory with source files according to the source RPM downloaded in step five: rpm -ivv nginx-1.13.9-1.el7_4.ngx.src.rpm

## Step nine - add the RTMP module to the spec file: Edit the 'nginx.spec' file to add the module as a config param: nano rpmbuild/SPECS/nginx.spec Find '%define BASE_CONFIGURE_ARGS $(echo "--prefix=%{_sysconfdir}/nginx' (you can use Ctrl+W and copy paste it in nano to find the line) and add (replace '!!YOUR_USER_HERE!! with the account that you've prepared and which has 'rpmbuild' directory and '.rpmmacros' in the Home directory) : --add-module=/home/!!YOUR_USER_HERE!!/nginx-rtmp-module Somewhere near the end, so that it looks something like (basically adds the directory where you have the source for RTMP module) near the end of that line: --with-stream_ssl_module --with-stream_ssl_preread_module --add-module=/home/!!YOUR_USER_HERE!!/nginx-rtmp-module")

## Step ten - run the config before build: Run the spectool command to process the config params in the .spec file to prepare a build: spectool -g -R rpmbuild/SPECS/nginx.spec

## Step eleven - run the build to generate your RPM with the RTMP module included: Build the RPM according to the spec file that you just modified to include the RTMP module (Important - as standard practice, run this command as a regular user instead of as sudo or root): rpmbuild -ba rpmbuild/SPECS/nginx.spec

## Step twelve: install the RPM: This is the step that you can run on all your production servers to install the freshly built RPM. The RPM will be located inside the 'rpmbuild/RPMS/x86_64/' directory (or elsewhere similar if you're building it on a different arch). If the installation due to unmet dependencies - install the ones listed in step six: sudo rpm -ivv /home/!!YOUR_USER_HERE!!/rpmbuild/RPMS/x86_64/nginx-1.13.9-1.el7_4.ngx.x86_64.rpm

With these steps completed, you should have a working NGINX for CentOS7 with RTMP module so that you can immediately start it by typing: service nginx start

If you run into problems (i.e. - HLS files can't be accessed by end users, you might need to set the correct SE Linux context settings to treat the files as web served files .... or you can set SE Linux to permissive as a temporary workaround, but what's the point of running this on CentOS then).

karlisk avatar Mar 14 '18 00:03 karlisk

Just wanted to note that this works for Fedora, just use the centos 8 repo. You are a godsend my good sir!

Valinwolf avatar Feb 08 '22 14:02 Valinwolf