Red5 Documentation

Linux Install – JDK 8

The following document is to be used for installing Red5 Pro server versions prior to 9.0.0. Release 9.0.0 and subsequent releases will require Java version 11

Installing Red5 Pro on a Linux Server

Recommended: Ubuntu 16.04 64-bit. Alternatively, Centos 7 64-bit

The following describes the steps in installing Red5 Pro on an Ubuntu linux server. We recommend running Red5 Pro on linux for optimal performance.

NOTES:

  • If you are hosting on AWS, be aware that the Amazon Linux AMI may not support all of the libraries needed for some Red5 Pro functionality. Please choose the Ubuntu 16.04 AMI.
  • Red5 Pro only has library support for 64-bit operating systems

INSTALLER: For quick deployment, please use the Red5 Pro Installer.


Software Dependencies – Ubuntu

Ubuntu 16.04

We suggest running your server on Ubuntu v16.04, especially if your solution includes RTSP (Red5 Pro mobile SDK). Ubuntu 18.04 is required for SRT restreaming.

You will need to install Java 8 and unzip to run and deploy Red5 Pro server. In addition, there are several native libraries required for WebRTC support, and jsvc is necessary for running Red5 Pro as a service. NTP service is necessary for autoscaling and communication with any other Red5 Pro servers if you are running a cluster.

Depending on your permissions, you may need to pre-pend the following commands with sudo:

apt-get update
apt-get install -y default-jre unzip libva1 libva-drm1 libva-x11-1 libvdpau1 jsvc ntp

Ubuntu 18.04

To run Red5 Pro on Ubuntu 18, run the following:

apt-get install -y openjdk-8-jre-headless unzip libva2 libva-drm2 libva-x11-2 libvdpau1 jsvc ntp

As of June 2020, Red5 Pro only supports Java 8. Java 11 support will be coming with a future release.

Software Dependencies – CentOS 7

Note: Red5 Pro with WebRTC does not run on CentOS 6 due to an older and less secure version of glibc that has been updated with CentOS 7. If you want to run Red5 Pro on CentOS, you must use build 7 (note that we have not tested with CentOS 8).

Open SSL Configuration for CentOS

IMPORTANT: Because of different libcrypto library versions supported between CentOS and Ubuntu, with release 5.2.2 it is necessary to modify {red5pro}/conf/webrtc-plugin.properties, and change openssl.enabled=true to openssl.enabled=false.

Depending on your permissions, you may need to pre-pend the following commands with sudo:

yum -y update
yum -y install java unzip jsvc ntp libva libvdpau

Required TCP and UDP Ports

The following Inbound ports need to be open on your server/firewall for Red5 Pro features to work:

Port Description
22 SSH TCP
5080 default web access of Red5 Pro/Websockets for WebRTC TCP
443 modified https access of Red5 Pro; secure websockets for WebRTC TCP
1935 default Red5 Pro RTMP port TCP
8554 default RTSP port TCP
6262 websockets for HLS TCP
8081 websockets for WebRTC (severs earlier than 5.4.0) TCP
8083 secure websockets for WebRTC (severs earlier than 5.4.0) TCP
40000-65535 TURN/STUN/ICE port range for WebRTC UDP

* If you are running a version of Red5 Pro earlier than 5.4.0, then you must add the websocket ports (8081/8083).

* As of release 5.4.0, websockets automatically use the same ports as http/https as defined in red5.properties.


Red5 Pro Installation

To install the Red5 Pro Server:

  1. Download the server .zip distribution to your local machine. Make sure to login with your account on https://account.red5.net and download the server from https://account.red5.net/download.
  2. SFTP the server .zip distribution into the /tmp directory of your server
  3. Choose a location to run your instance and navigate to that directory. For this example, we’re running from /usr/local
    cd /usr/local
  4. Copy the server distribution to this directory:
    sudo cp /tmp/red5pro-server-xxx.zip .
  5. Unzip the Red5 Pro distribution in the directory:
    sudo unzip red5pro-server-xxx.zip
  6. For ease of use, rename the Red5 Pro distribution directory to red5pro:
    sudo mv red5-server-xxx-release red5pro

Your Red5 Pro Server License Key

Red5 Pro server will not function without a valid license key. As of release 3.0.0, your LICENSE.KEY file will be included in your server download in the root of the Red5 Pro server directory. You can find your license key listed on your Red5 Pro Professional account overview page.

Add execute permissions to the following files

  • red5.sh
  • red5-shutdown.sh
  • red5-debug.sh

sudo chmod +x *.sh will do the job.

Modify Maximum Java Heap Size For Red5 Pro Java Process

You can modify the maximum Java heap size by modifying red5.sh. Increasing the maximum heap size will allow the server to assign as much memory from what is available to Red5 Pro when necessary.

The default maximum heap size is 2 gigabytes (-Xmx2g).

# JAVA options
# You can set JVM additional options here if you want
if [ -z "$JVM_OPTS" ]; then
    JVM_OPTS="-Xms256m -Xmx2g -Xverify:none -Djava.net.preferIPv4Stack=true -XX:+TieredCompilation -XX:+UseBiasedLocking -XX:InitialCodeCacheSize=8m -XX:ReservedCodeCacheSize=32m -Dorg.terracotta.quartz.skipUpdateCheck=true -XX:MaxMetaspaceSize=128m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC"
fi

If you want to launch Red5 Pro manually, you can do so now by running sudo ./red5.sh. Note that the process will stop when you close your terminal session. If you want to keep it running, then run sudo ./red5.sh &. To ensure that Red5 Pro starts if your instance reboots, set it up as a service.

Defining Red5 Pro as a Service

To allow for ease of startup/shutdown of Red5 Pro, in addition to automatically starting the service on server reboot, you will want to add a systemd unit file for Red5 Pro. The Apache jsvc application is required to run Red5 Pro as a service on Linux.

IMPORTANT: If you had previously defined the /etc/init.d/red5pro service, you will need to remove that before configuring the systemd service. Run: sudo systemctl disable red5pro.service.

On Ubuntu or Debian run:

$ sudo apt-get install -y jsvc

On CentOS/Fedora/Redhat:

$ sudo yum -y install jsvc

Next, create a red5pro.service file in the /lib/systemd/system directory:

$ sudo touch /lib/systemd/system/red5pro.service

You can copy and paste the following into the red5pro.service file using your editor of choice.

Note that in our script, RED5_HOME is set to the system path mentioned above (/usr/local/red5pro), and that JAVA_HOME is set to the path that the above java installation results in (/usr/lib/jvm/java-8-openjdk-amd64) for Ubuntu. If you are running on Centos, the path is /usr/lib/jvm/jre-1.8.0-openjdk. You may need to change these variables if your installation varies.
NOTE 2: You should increase the memory allocation by editing the line -Xms2g -Xmx2g -Xverify:none and making each value equal to 1 to 2G less than your total system memory.

IMPORTANT: This file has been modified with the 5.6.0 server release (the line -cp ${RED5_HOME}/commons-daemon-1.1.0.jar:${RED5_HOME}/red5-service.jar:${RED5_HOME}/conf has been modified from -cp ${RED5_HOME}/commons-daemon-1.0.15.jar:${RED5_HOME}/red5-service.jar:${RED5_HOME}/conf in previous releases)

[Unit]
Description=Red5 Pro
After=syslog.target network.target

[Service]
Type=forking
Environment=PID=/var/run/red5pro.pid
Environment=JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
LimitNOFILE=65536
# for Centos:
# Environment=JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk
Environment=RED5_HOME=/usr/local/red5pro
WorkingDirectory=/usr/local/red5pro
ExecStart=/usr/bin/jsvc -debug \
    -home ${JAVA_HOME} \
    -cwd ${RED5_HOME} \
    -cp ${RED5_HOME}/commons-daemon-1.1.0.jar:${RED5_HOME}/red5-service.jar:${RED5_HOME}/conf \
    -Dred5.root=${RED5_HOME} \
    -Djava.library.path=${RED5_HOME}/lib/amd64-Linux-gpp/jni \
    -Djava.security.debug=failure -Djava.security.egd=file:/dev/./urandom \
    -Dcatalina.home=${RED5_HOME} -Dcatalina.useNaming=true \
    -Dorg.terracotta.quartz.skipUpdateCheck=true \
    -Xms2g -Xmx2g -Xverify:none \
    -XX:+TieredCompilation -XX:+UseBiasedLocking \
    -XX:MaxMetaspaceSize=128m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC \
    -XX:InitialCodeCacheSize=8m -XX:ReservedCodeCacheSize=32m \
    -XX:CMSInitiatingOccupancyFraction=60 \
    -outfile /dev/null -errfile /dev/null \
    -wait 60 \
    -umask 011 \
    -pidfile ${PID} org.red5.daemon.EngineLauncher 9999

ExecStop=/usr/bin/jsvc -stop -pidfile ${PID} org.red5.daemon.EngineLauncher 9999

[Install]
WantedBy=multi-user.target

NOTE: For debugging, change the line -outfile /dev/null -errfile /dev/null to be -outfile ${RED5_HOME}/log/jsvc-service.log -errfile ${RED5_HOME}/log/jsvc-error.log . This will generate two additional logiles under the red5pro/log directory: {red5pro}/log/jsvc-service.log and {red5pro}/log/jsvc-error.log. Also note that these files are not affected by the rolling logfile appender, so they can get quite large, which is why it is recommended not to enable these in a production environment.

Make the file read/write for root and read-only for everyone else:

sudo chmod 644 /lib/systemd/system/red5pro.service

Reload the daemon:

sudo systemctl daemon-reload

Enable Red5 Pro Service:

sudo systemctl enable red5pro.service

Starting / Stopping

The Red5 Pro Server can now be started by issuing:

$ sudo systemctl start red5pro

Note: There will be no console logging if you start Red5 Pro this way. Red5 Pro server logging will be written to the /log/red5.log file. Consequently, you may want to create a startred5pro.sh script as per the following (make the file executable by typing chmod +x startred5pro.sh:

#!/bin/bash
sudo systemctl start red5pro
tail -f /usr/local/red5pro/log/red5.log

The Red5 Pro process will be running under jsvc

PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
9664 root      20   0 4724212 419736  19728 S  10.0 11.6   0:35.54 jsvc

Also note that this will result in two red5pro PIDs. There will also be two log files created in /usr/local/red5pro/log: jsvc-error.log and jsvc-service.log. If there are any issues with the service, these logs will be helpful in debugging.

To stop the Red5 Pro Server from running (note, it can take up to 30 seconds for the server to fully shut down):

sudo systemctl stop red5pro

Additionally, you can restart the Red5 Pro Server by issuing:

sudo systemctl restart red5pro

Service Removal

To disable and remove the service, execute the following two steps in a terminal:

sudo systemctl disable red5pro.service
sudo rm /lib/systemd/system/red5pro.service

Checking Service Status

To check the status of the Red5 Pro service, issue this command:

sudo systemctl status red5pro

The result should appear similar to this:

● red5pro.service - Red5 Pro
   Loaded: loaded (/lib/systemd/system/red5pro.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2017-05-09 19:49:15 UTC; 27s ago
  Process: 6952 ExecStop=/usr/bin/jsvc -stop -pidfile ${PID} org.red5.daemon.EngineLauncher 9999 (code=exited, status=0/SUCCESS)
  Process: 6974 ExecStart=/usr/bin/jsvc -debug -home ${JAVA_HOME} -cwd ${RED5_HOME} -cp ${RED5_HOME}/commons-daemon-1.0.15.jar:${RED5_HOME}/red5-service.jar:${RED5_HOME}/conf -Dred5.root=${R
 Main PID: 6976 (jsvc)
    Tasks: 94
   Memory: 375.5M
      CPU: 10.911s
   CGroup: /system.slice/red5pro.service
           ├─6976 jsvc.exec -debug -home /usr/lib/jvm/java-8-openjdk-amd64 -cwd /usr/local/red5pro -cp /usr/local/red5pro/commons-daemon-1.0.15.jar:/usr/local/red5pro/red5-service.jar:/usr/l
           └─6977 jsvc.exec -debug -home /usr/lib/jvm/java-8-openjdk-amd64 -cwd /usr/local/red5pro -cp /usr/local/red5pro/commons-daemon-1.0.15.jar:/usr/local/red5pro/red5-service.jar:/usr/l

May 09 19:49:01 ip-172-31-19-47 jsvc[6974]: get_pidf: 5 in /var/run/red5pro.pid
May 09 19:49:01 ip-172-31-19-47 jsvc[6974]: get_pidf: pid 6977
May 09 19:49:01 ip-172-31-19-47 jsvc[6974]: check_tmp_file: /tmp/6977.jsvc_up
May 09 19:49:08 ip-172-31-19-47 jsvc[6974]: get_pidf: 5 in /var/run/red5pro.pid
May 09 19:49:08 ip-172-31-19-47 jsvc[6974]: get_pidf: pid 6977
May 09 19:49:08 ip-172-31-19-47 jsvc[6974]: check_tmp_file: /tmp/6977.jsvc_up
May 09 19:49:15 ip-172-31-19-47 jsvc[6974]: get_pidf: 5 in /var/run/red5pro.pid
May 09 19:49:15 ip-172-31-19-47 jsvc[6974]: get_pidf: pid 6977
May 09 19:49:15 ip-172-31-19-47 jsvc[6974]: check_tmp_file: /tmp/6977.jsvc_up
May 09 19:49:15 ip-172-31-19-47 systemd[1]: Started Red5 Pro.

Verifying Red5 Pro is Running

Once you have started the Red5 Pro Server, you can verify that it is running and available by visiting your instance at port 5080.

Open a web browser and navigate to http://__your server ip__:5080 (like http://127.0.0.0:5080)

To not publicly expose the default web access at port 5080, you can do either of the following:

  • Don’t expose the port 5080 in your Inbound security for the instance.
  • Redefine the default port as the http.port value in the conf/red5.properties file of your Red5 Pro Server install.

Rolling Log Files

There are a number of options for rolling logs, utilizing the Logback RollingFileAppender. To implement logging rollover, add the options that you want in your {red5pro}conflogback.xml files after the <appender class="ch.qos.logback.core.FileAppender" name="FILE"> section. Displayed below are two of the rolling styles available:

Change FileAppender output filename

The rolling logfile needs to use a different output than the default, so you should change the default (note: this will result in an empty placeholder red5_blank.log file).

change from

  <appender class="ch.qos.logback.core.FileAppender" name="FILE">
    <file>log/red5.log</file>
    <append>true</append>
    <encoder>
      <pattern>%d{ISO8601} [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
  </appender>

to:

  <appender class="ch.qos.logback.core.FileAppender" name="FILE">
    <file>log/red5_blank.log</file>
    <append>true</append>
    <encoder>
      <pattern>%d{ISO8601} [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
  </appender>

Size-based rolling policy

As configured below, the log will roll-over at or just over 200 Mb with a maximum log file count of 20.

<appender class="ch.qos.logback.core.rolling.RollingFileAppender" name="ROLLING_LOG">
    <File>log/red5.log</File>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
        <fileNamePattern>log/red5.%i.log</fileNamePattern>
        <minIndex>1</minIndex>
        <maxIndex>20</maxIndex>
    </rollingPolicy>
    <triggeringPolicy
        class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
        <maxFileSize>200MB</maxFileSize>
    </triggeringPolicy>
    <encoder>
        <pattern>%d{ISO8601} [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
</appender>

Time-based rolling policy

As configured below, the log will roll-over daily for a maximum of 30 days.

<appender class="ch.qos.logback.core.rolling.RollingFileAppender" name="ROLLING_LOG">
    <File>log/red5.log</File>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>log/red5.%d{yyyy-MM-dd}.log</fileNamePattern>
      <maxHistory>30</maxHistory>
    </rollingPolicy>
    <encoder>
        <pattern>%d{ISO8601} [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
</appender>

Modify root level Definition

change from

<root level="INFO">
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="FILE"/>
  </root>

to:

<root level="INFO">
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="ROLLING_LOG"/>
  </root>

Red5 Pro WebRTC

Red5 Pro Server Release 2.0.0 (WebRTC Beta2) includes WebRTC support and front-end integration of the Red5 Pro HTML5 SDK.

WebRTC (Web Real-Time Communication) is supported by the Chrome, Firefox and Opera browsers on desktop. In addition, the Chrome browser on Android supports WebRTC. Safari and Internet Explorer do not support WebRTC (but reportedly, Microsoft Edge does).

Broadcasting/subscribing of WebRTC to WebRTC, WebRTC to HLS, WebRTC to Flash, and Flash to WebRTC are all supported.

Subscribing to a WebRTC publisher using the Red5 Pro Android or iOS SDK client is supported. In addition, subscribing with WebRTC to a stream published with Red5 Pro Android or iOS SDK client is supported.

WebRTC Broadcaster/Subscriber combinations supported, in a nutshell:

  • WebRTC <==> WebRTC
  • WebRTC <==> Flash
  • WebRTC <==> Red5 Pro iOS SDK
  • WebRTC <==> Red5 Pro Android SDK
  • WebRTC ==> HLS

WebRTC Overview

WebRTC runs on the standard HTTPS port (443). To publish via WebRTC on a Red5 Pro server you need to have a valid SSL Certificate for a registered URL.

If you are running the server, without an SSL cert, on your local machine or on a server:

  1. You will be able to publish/subscribe locally (between browsers).
  2. You will be able to subscribe to a stream that is being published from localhost (e.g.: http://localhost:5080/live/broadcast.jsp) from a device within the same network (pointing to the IP address of your machine, not to localhost). To subscribe from a mobile device, either via a browser on Android or via SDK client on iOS or Android, the device must be on the same Wifi network as the desktop.
  3. You will not be able to publish via a WebRTC client that is not local to the machine.

How to modify default ports

Some firewalls or even service providers may block some of the Red5 Pro default ports, so you may want to modify those. There are two files that allow you to define the ports that Red5 Pro uses: {red5pro}/conf/red5.properties, and {red5pro}/conf/red5pro-activation.xml

red5.properties file : RTMP, HTTP

To modify the default RTMP port, edit {red5pro}/conf/red5.properties RTMP section:

# RTMP
rtmp.host=0.0.0.0
rtmp.port=1935

To modify the default HTTP (or HTTPS) port, edit the HTTP section:

# HTTP
http.host=0.0.0.0
http.port=5080
https.port=5443

red5pro-activation.xml file: RTSP, secondScreen, websocket (for HLS)

Modify the configuration bean if you wish to modify any of the default ports for RSTP, WebSockets for HLS, or Second Screen:

<bean name="configuration" id="configuration" class="com.red5pro.activation.Red5ProConfiguration">
<property name="rtsp" value="true"/>
<property name="secondscreen" value="true"/>
<property name="websockets" value="true"/>
<property name="rtspPort" value="8554"/>
<property name="secondScreenPort" value="8088"/>
<property name="websocketPort" value="6262"/>
<property name="enableRecording" value="true"/>
</bean>

Legacy – Stop/Start Red5 Pro Service Via /etc/init.d

While init.d is being phased out of Linux distributions, launching Red5 Pro using /etc/init.d/red5pro is still an option on some systems. The one advantage to using this method is that you can view the console output when launching this way.

NOTE: If you want Red5 Pro service defined in both the init.d and systemd, you will need to choose a different name for one of them.

To begin, create a red5pro file in init.d:

sudo touch /etc/init.d/red5pro

You can copy and paste the following into the red5pro file using your editor of choice:

#!/bin/sh
### BEGIN INIT INFO
# chkconfig: 2345 85 85
# description: Red5 Pro streaming server
# Provides:          Red5 Pro
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Red5Pro
# processname: red5
### END INIT INFO

PROG=red5
RED5_HOME=/usr/local/red5pro
DAEMON=$RED5_HOME/$PROG.sh
PIDFILE=/var/run/$PROG.pid

start() {
  # check to see if the server is already running
  if netstat -an | grep ':5080'; then
    echo "Red5 is already started..."
    while netstat -an | grep ':5080'; do
      # wait 5 seconds and test again
      sleep 5
    done
  fi
  cd ${RED5_HOME} && ./red5.sh &
}

stop() {
  cd ${RED5_HOME} && ./red5-shutdown.sh
}

case "$1" in
  start)
    start
    exit 1
  ;;
  stop)
    stop
    exit 1
  ;;
  restart)
    stop
    start
    exit 1
  ;;
  **)
    echo "Usage: $0 {start|stop|restart}" 1>&2
    exit 1
  ;;

esac

Make the file executable:

sudo chmod 777 /etc/init.d/red5pro

Configure Red5 Pro to Automatically Start on Boot/Reboot

Run the following commands to configure the Red5 Pro init.d service to start on server startup (IMPORTANT: do NOT run these if you have already set up systemd to start red5pro on restart of server):

sudo /usr/sbin/update-rc.d red5pro defaults
sudo /usr/sbin/update-rc.d red5pro enable

For CentOS:

sudo systemctl daemon-reload
sudo systemctl enable red5pro.service

Starting / Stopping

The Red5 Pro Server can now be started by issuing:

sudo /etc/init.d/red5pro start

To stop the Red5 Pro Server from running (note, it takes approximately 30 seconds for the server to fully shut down):

sudo /etc/init.d/red5pro stop

Additionally, you can restart the Red5 Pro Server by issuing:

sudo /etc/init.d/red5pro restart

Troubleshooting

  1. Some hosting facilities’ virtual servers may not be able to transmit their public/private IP addresses to Red5 Pro server. This information is necessary for the ICE negotiation in WebRTC. In some cases you may need to give the Red5 Pro server a little help by “forcing” these IP assignments. To do so, modify the {red5pro}/conf/webrtc-plugin.properties file. Uncomment the following lines and modify with your server’s public and private IP addresses.
# Forcing a public IP address
force.public.ip=server-public-ip-address

# Forcing a private IP address
force.local.ip=erver-private-ip-address

If you are still having ICE failures, you may also need to enabled port availability checking by uncommenting:

# Configure port availability checking
check.port.availability=true