Step 2 – Unifi Controller Installation

Ubiquiti Management Controller


1. Installing the dependencies

We will be using the unifi package from the official Debian repository of UBNT. It has two main dependencies: MongoDB and a Java Virtual Machine. This time, MongoDB is an easy one: it is available in the Raspbian repositories and will be installed automatically when the unifi package is installed.
The unifi depends on OpenJDK 7 to provide the Java Virtual Machine. That’s fine on x86/amd64 platforms, but on a Raspberry Pi this would is not optimal. The performance of OpenJDK JVM is low compared to the Oracle JVM, because it uses soft-floats instead of hard-floats.

3. Installing the UniFi controller

To be able to use packages from the UBNT repository for Debian, we need to tell our package manager where the repository is located. We’ll need to create the file /etc/apt/sources.list.d/unifi.list with the following content: deb stable ubiquiti. You can do so manually, or lcould be done by running the following command:
sudo echo ‘deb stable ubiquiti’ | sudo tee -a /etc/apt/sources.list.d/ubnt.list > /dev/null

Next, we’ll need to pass it the UBNT public key (you can verify it here) for this repo:

sudo apt-key adv –keyserver –recv C0A52C50

Then we’ll tell apt to update its index and install the unifi package.

sudo apt-get update
sudo apt-get install unifi -y

Let’s have a look at the output of the last command.

pi@ubiquiti:~ $ sudo apt-get install unifi

Reading package lists… Done
Building dependency tree
Reading state information… Done
The following extra packages will be installed:
ca-certificates-java icedtea-7-jre-jamvm jsvc libcommons-daemon-java libpcap0.8 libpcrecpp0 libsctp1 libsnappy1 lksctp-tools mongodb-clients
mongodb-server openjdk-7-jre-headless tzdata-java
Suggested packages:
sun-java6-fonts fonts-ipafont-gothic fonts-ipafont-mincho ttf-wqy-microhei ttf-wqy-zenhei fonts-indic
The following NEW packages will be installed:
ca-certificates-java icedtea-7-jre-jamvm jsvc libcommons-daemon-java libpcap0.8 libpcrecpp0 libsctp1 libsnappy1 lksctp-tools mongodb-clients
mongodb-server openjdk-7-jre-headless tzdata-java unifi
0 upgraded, 14 newly installed, 0 to remove and 0 not upgraded.
Need to get 266 MB of archives.
After this operation, 398 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

You can see OpenJDK 7 (openjdk-7-jre-headless) is being installed. We won’t need it, but it’s not easy to exclude and it won’t really harm us if there’s plenty of disk space around.…….
Get:7 jessie/main openjdk-7-jre-headless armhf 7u95-2.6.4-1~deb8u1+rpi1 [37.4 MB]

4. Disable default MongoDB

Disable the default MongoDB database instance, using the following commands:

sudo echo ‘ENABLE_MONGODB=no’ | sudo tee -a /etc/mongodb.conf > /dev/null

Without making this small configuration change, you will have two separate instances of MongoDB running; an unused default database instance, and the UniFi database instance. This is obviously not desirable on a device with limited resources, such as the Raspberry Pi.

5. Modify the start script in order to use Oracle Java 8 instead of OpenJDK 7

By modifying the unifi.init startup script to force the JAVA_HOME path to Oracle Java 8. The problem with this approach is that when you perform a package upgrade using sudo apt-get upgrade and the UniFi package gets updated, this startup script will be automatically overwritten and you will be reverted to OpenJDK Java 7 without notification.

A smarter solution is to trick the startup script into believing Java 6 is installed, which it will use in preference to Java 7, by creating a symbolic link for Java 6 pointing to Java 8. The startup script will launch UniFi using what it believes is Java 6, but is actually Java 8, without any changes required to the UniFi startup script or package itself.

1.If you are using Raspbian Jessie Lite, you will first need to install the Oracle Java 8 JDK, using the following package install command: sudo apt-get install oracle-java8-jdk -y

2.Create a symbolic link for Java 6 pointing to Java 8, using the following command:
sudo ln -sf jdk-8-oracle-arm-vfp-hflt/jre /usr/lib/jvm/java-6-openjdk-armhf

3.Set Java 8 as the default Java Runtime Environment, using the following command:
sudo update-alternatives –set java /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/bin/java

4.Execute the following command to determine the default Java Runtime Environment.
java -version
The command will produce output similar to the following. ◦java version “1.8.0”
◦Java(TM) SE Runtime Environment (build 1.8.0-b132)
◦Java HotSpot(TM) Client VM (build 25.0-b70, mixed mode)

OpenJDK Java 7
If you wish to switch back to Java 7 at any point, execute the following commands:
sudo rm -f /usr/lib/jvm/java-6-openjdk-armhf
sudo update-alternatives –auto java
sudo reboot

Once completed, reboot your Raspberry Pi using the following command:
sudo reboot

When the reboot is complete, use a web browser to view HTTPS port 8443 on your Raspberry Pi:


sudo systemctl start unifi

It will take some time (about 2 minutes on my old RPi model B rev 2) for the controller to start, but eventually you should be able to connect to https://<ip.of.your.rpi&gt;:8443.

If things are not working for you, you should view the server’s log file.

sudo tail /var/log/unifi/server.log

You can (and should) also verify the controller is running as the unifi user. The first column shows the name of the user.

pi@ubiquiti:~ $ ps aux | grep unifi


Note that it also shows you it is using the Oracle 8 JVM and the lowered memory setting.

A note on log rotation
The UniFi controller comes with built-in log rotation which is fine in most situations. Especially when you’re using a large SD card (16 GB or more), which should leave you with enough disk space to avoid excessive wear on it. It would be wise to create a backup image now, however. If your SD card would eventually fail due to write wear, you could just get another one and flash your image on it, upload your backup config (don’t forget) in the UniFi interface and you’re all set again.