1 - Setup LXC with Unifi Controller v5 on Ubuntu 16.04

This is the first of two posts about “how to setup an LXC Container with a Unifi Controller v5 on Ubuntu Server 16.04” and “migrate from an existing Unifi Controller v4.8.x to a new Unifi Controller v5 installation“.

I assume you have read all the involved release notes and changes (e.g. => https://community.ubnt.com/t5/UniFi-Updates-Blog/UniFi-5-2-9-is-released/ba-p/1694199 )! And also that you have made a BACKUP of all your data before starting with this tutorial!

First we prepare the Host (Ubuntu Server 16.04) and install LXC and bridge-utils:

sudo apt-get install lxc lxc-templates bridge-utils

For networking we use a bridge setup:

sudo vim /etc/network/interfaces

This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface #auto eno1 iface eno1 inet manual auto br0 iface br0 inet static bridgeports eno1 bridgefd 0 address 192.168.XXX.XXX netmask broadcast 192.168.XXX.255 gateway 192.168.XXX.1 dns-nameservers XX.XX.XX.XX XX.XX.XX.XX

Check your network interface name and use it for bridging. In me case the name of the interface is “eno1”. This has to be used for the “bridgeports” setting => bridgeports eno1

After this changes to your host system you have to reboot the server.

Login again to your server.

Now we can create a new Container like this:

sudo lxc-create -n UnifiController -t ubuntu

this will create a new LXC Container based on the ubuntu template. For more informations about the ubuntu template use the following command:

sudo lxc-create -t ubuntu -h

and also check this link: https://uk.images.linuxcontainers.org/

Don’t forget this:

# The default user is 'ubuntu' with password 'ubuntu'! # Use the 'sudo' command to run tasks as root in the container.

Now we have a new LXC Container. Check with:

sudo lxc-ls -f NAME STATE AUTOSTART GROUPS IPV4 IPV6 UnifiController STOPPED 0 - - -

The Container is not running right now. First we have to do some changes for the network settings:

sudo vim /var/lib/lxc/UnifiController/conf # Parameters passed to the template: # For additional config options, please look at lxc.container.conf(5) # Uncomment the following line to support nesting containers: #lxc.include = /usr/share/lxc/config/nesting.conf # (Be aware this has security implications) # Common configuration lxc.include = /usr/share/lxc/config/ubuntu.common.conf # Container specific configuration lxc.rootfs = /var/lib/lxc/UnifiController/rootfs lxc.rootfs.backend = dir lxc.utsname = UnifiController lxc.arch = amd64 # Network configuration lxc.network.type = veth #lxc.network.link = lxcbr0 lxc.network.link = br0 <-- change to your bridge interface name as configured above lxc.network.flags = up lxc.network.hwaddr = 00:16:3e:e9:1d:00 lxc.network.ipv4 = 192.168.XX.XX/24 <-- change the LXC Container IP*lxc.network.ipv4.gateway = 192.168.XX.1 <-- change Gateway# Autostart <-- this section is optional. Autostart settings after reboot of the host systemlxc.start.auto = 1lxc.start.delay = 5lxc.start.order = 115 <-- continuous number for the autostart order if you have other lxc containers with autostart enabled*

Add the lines in green. Change some of them as described.

And one other change:

sudo vim /var/lib/lxc/UnifiController/rootfs/etc/network/interfaces # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback auto eth0 iface eth0 inet manual <-- change from dhcp to manual dns-nameservers <-- add your dns settings

Add the lines in green. Change some of them as described.

Now we start the Container UnifiController:

sudo lxc-start -n UnifiController -d

Check if the Container is up:

sudo lxc-ls -f NAME STATE AUTOSTART GROUPS IPV4 IPV6 UnifiController RUNNING 1 - -

Now we can connect to the UnifiController Container

lxc-console -n UnifiController -e q Connected to tty 1 Type to exit the console, to enter Ctrl+q itself Ubuntu 16.04.1 LTS UnifiController pts/0 UnifiController login:

Login with ubuntu pw:ubuntu

UnifiController login: ubuntu Passwort: Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-38-generic x8664) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. To run a command as administrator (user "root"), use "sudo ". See "man sudoroot" for details. ubuntu@UnifiController:~$

Use this command to update first:

sudo apt-get update && sudo apt-get upgrade

Now we are ready to install the (currently latest) Unifi Controller v5.2.9. Important: Read first this site:


Follow this site as mentioned on the previous site (“For Debian/Ubuntu users, please update your APT source (see HERE).“) => https://help.ubnt.com/hc/en-us/articles/220066768

We’re going to add and edit this file: /etc/apt/sources.list.d/100-ubnt.list

sudo vim /etc/apt/sources.list.d/100-ubnt.list

add this line:

deb http://www.ubnt.com/downloads/unifi/debian unifi5 ubiquiti

save and quit.

Then use the following command to add the GPG Key:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv C0A52C50


sudo apt-get update

and finally install Unifi Controller latest in Version 5 Repository

sudo apt-get install unifi

Verify the installed package (dpkg -s unifi):

dpkg -s unifi Package: unifi Status: install ok installed Priority: optional Section: java Installed-Size: 137060 . Maintainer: UniFi developers unifi-dev@ubnt.com Architecture: all Version: 5.2.9-8748 Replaces: unifi-controller Provides: unifi-controller Depends: binutils, coreutils, jsvc, mongodb-server (>= 2.4.10) | mongodb-10gen (>= 2.4.14) | mongodb-org-server (>= 2.6.0), openjdk-6-jre-headless | openjdk-7-jre-headless | openjdk-8-jre-headless | java8-runtime-headless Pre-Depends: debconf (>= 0.5) | debconf-2.0 Conflicts: unifi-controller Description: Ubiquiti UniFi server Ubiquiti UniFi server is a centralized management system for UniFi suite of devices. After the UniFi server is installed, the UniFi controller can be accessed on any web browser. The UniFi controller allows the operator to instantly provision thousands of UniFi devices, map out network topology, quickly manage system traffic, and further provision individual UniFi devices. Homepage: http://www.ubnt.com/unifi

We also check the installed Java:

java -version openjdk version "1.8.091" OpenJDK Runtime Environment (build 1.8.091-8u91-b14-3ubuntu1~16.04.1-b14) OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)

Open now this URL in your Browser: