How to Install Janus WebRTC Server on Ubuntu 18.04

Written by: Bagus Facsi Aginsa
Published at: 31 Aug 2021


Janus is an open-source WebRTC server designed and developed by Meetecho. Janus has great documentation for the user on how to install and use them, you can see the original post on their github. This tutorial hopefully will make it even easier to start Janus. In addition, we will also create a systemd & logrotate service for Janus, so it will be easier to manage.

Prerequisite

Ubuntu 18.04. We are testing this installation on Ubuntu 18.04, but it may also work on another version of Ubuntu.

Sudo Privileges

Before starting, we make sure that we will have no permission issues on the installation & configuration.

sudo su

Install Dependencies Available in Package Manager

Install dependencies using the apt package manager

apt install libmicrohttpd-dev libjansson-dev \
    libssl-dev libsofia-sip-ua-dev libglib2.0-dev \
    libopus-dev libogg-dev libcurl4-openssl-dev liblua5.3-dev \
    libconfig-dev pkg-config gengetopt libtool automake \
    git python3 python3-pip make cmake ninja-build

Install libnice

To install libnice, we need another dependency called meson. The easiest way to install it is using pip3 by running this command:

pip3 install meson

To confirm the installation, run:

meson -v

You should get version 0.58.1 or higher.

After installing meson, go to your home directory:

cd ~

Clone the libnice repo from the GitLab

git clone https://gitlab.freedesktop.org/libnice/libnice.git

Go to libnice directory

cd libnice

(optional) It is up to you to run which version of libnice, the documentation didn’t provide the detail. But the latest commit we already tested is the commit number a0cfef7. To move libnice to that commit run this command:

git checkout a0cfef7

Install libnice using meson:

meson --prefix=/usr build && ninja -C build && sudo ninja -C build install

Install libsrtp

Before we install libsrtp, make sure you don’t have them installed:

apt list libsrtp*

If you have installed them, uninstall them first

apt remove --purge libsrtp*

After no libsrtp installed in your machine, go to your home directory:

cd ~

Download libsrtp v2.2.0 from GitHub

wget https://github.com/cisco/libsrtp/archive/v2.2.0.tar.gz

Extract the package

tar xfv v2.2.0.tar.gz

Go to the libsrtp directory

cd libsrtp-2.2.0

Run these commands to configure, compile, and install libsrtp

./configure --prefix=/usr --enable-openssl
make shared_library && make install

Install usrsctp

Go to your home directory:

cd ~

Clone usrsctp from the GitHub

git clone https://github.com/sctplab/usrsctp

Go to the usrsctp directory

cd usrsctp

(optional) It is up to you to run which version of usrsctp, the documentation didn’t provide the detail. But the latest commit we already tested is the commit number 965b19a. To move the branch, we can run this command:

git checkout 965b19a

Run these commands to compile and install usrsctp

./bootstrap
./configure --prefix=/usr --disable-programs --disable-inet --disable-inet6
make && make install

Install libwebsockets

Although it is optional, most conference use cases will use WebSocket for webrtc control plane. so it is very recommended to install this library.

Go to your home directory:

cd ~

Clone libwebsockets from the repository

git clone https://github.com/warmcat/libwebsockets.git

Go to libwebsockets directory

cd libwebsockets

Use the stable version of libwebsockets

git checkout v3.2-stable

Create a directory named build and go to the directory

mkdir build
cd build

Run these commands to compile and install libwebsockets

cmake -DLWS_MAX_SMP=1 -DLWS_WITHOUT_EXTENSIONS=0 -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_C_FLAGS="-fpic" ..
make && sudo make install

Install Janus

Go to your home directory:

cd ~

Clone Janus project from the repository

git clone https://github.com/meetecho/janus-gateway.git

Go to Janus directory

cd janus-gateway

(optional) It is up to you to run which version of Janus, you can check the list of the versions here. But the latest commit we already tested is the the v0.12.0 version. To move the branch, we can run this command:

git checkout v0.12.0

Generate Janus configuration file

sh autogen.sh

Run these commands to compile, build, and install Janus

./configure --prefix=/opt/janus
make
make install

Create Janus default config file

make configs

Right now, you have already installed the Janus webrtc server. you can find all the Janus config files here:

/opt/janus/etc/janus/

Create Systemd File

Create a janus systemd file

nano /etc/systemd/system/janus.service

Copy this script

[Unit]
Description=Janus WebRTC Server
After=network.target

[Service]
User=root
Nice=1
Restart=on-abnormal
LimitNOFILE=65536
PIDFile=/tmp/janus.pid
ExecStart=/usr/bin/sudo /opt/janus/bin/janus

[Install]
WantedBy=multi-user.target

And then exit and save,

After that reload the daemon service

systemctl daemon-reload

Check weather the systemd file is working properly

service janus status
service janus start
service janus status
service janus stop
service janus status

Create Logrotate File

Before creating logrotate, I want to inform you that you can choose where Janus will write the log file. First, edit your Janus configuration to determine the log location:

nano /opt/janus/etc/janus/janus.jcfg

Search for the log_to_file phrase and set your desired log location. In this tutorial, I will place the log file in the common log directory on ubuntu: "/var/log/janus/janus.log"

Create the log folder

mkdir /var/log/janus

Create a janus logrotate file

nano /etc/logrotate.d/janus

Copy this script

/var/log/janus/janus.log {
        daily
        missingok
        rotate 7
        compress
        delaycompress
        notifempty
}

The file /var/log/janus/janus.log should be created automatically when Janus service started, if not, you can create the file by writing this command:

touch /var/log/janus/janus.log

That’s it! Congratulation you successfully installing Janus WebRTC Server in Ubuntu 18.04.