Installing Red5 Pro on a Linux Server

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

Note: If you are hosting on AWS, be aware that the Amazon Linux AMI does not support all of the libraries needed for some Red5 Pro functionality. Please choose the Ubuntu 16.04 AMI.


Software Dependencies - Ubuntu 16.04

We suggest running your server on Ubuntu v16.04. You will need to install Java (recommended version 8 or higher) and unzip to run and deploy Red5 Pro server.

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

Depending on your version of Ubuntu, you may also need to install the following libraries to support WebRTC:

apt-get install -y libva1 libva-drm1 libva-x11-1 libvdpau1

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 or higher.

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

yum -y update
yum -y install java
yum -y install unzip
rpm --import http://packages.atrpms.net/RPM-GPG-KEY.atrpms
rpm -ivh http://dl.atrpms.net/all/atrpms-repo-6-7.el6.x86_64.rpm
yum -y update --skip-broken
yum -y --enablerepo=atrpms install libva libvdpau1

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
5080 default web access of Red5 Pro
1935 default Red5 Pro RTMP port
8554 default RTSP port
6262 websockets (for second screen and HLS)
8088 second screen client registry

Ports required for WebRTC server using SSL:

Port Description Protocol
22 SSH TCP
80 modified web access of Red5 Pro TCP
443 standard HTTPS port TCP
1935 default Red5 Pro RTMP port TCP
8554 default RTSP port TCP
6262 websockets for HLS TCP
8081 websockets for WebRTC TCP
8083 secure websockets for WebRTC TCP
40000-65000 TURN/STUN/ICE port range UDP

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 http://account.red5pro.com and download the server from https://account.red5pro.com/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 in 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

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.

[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
# 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.0.15.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 \
    -Xms256m -Xmx2g -Xverify:none \
    -XX:+TieredCompilation -XX:+UseBiasedLocking \
    -XX:MaxMetaspaceSize=128m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC \
    -XX:InitialCodeCacheSize=8m -XX:ReservedCodeCacheSize=32m \
    -outfile ${RED5_HOME}/log/jsvc-service.log -errfile ${RED5_HOME}/log/jsvc-error.log \
    -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

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. 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 /etc/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.

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. Red5 Pro with SSL walks you through setting up the certificate on your server. Additionally, as with other Red5 Pro server distributions, you will need to install Java (minimum version 8.0).

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 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, Websockets

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

To modify the default Websockets port, edit the Websocket section:

# WebSocket
ws.host=0.0.0.0
ws.port=8081

Note: this is also where you define secure websockets (wss) if you need them.

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