ubiquiti

  • UniFi Controller on a Raspberry Pi

    I was looking for a re-use of my old Raspberry Pi 3B+ and as I wanted to see what the Ubiquiti UniFi Controller offers. You can either buy one of their hardware controller, available in different sizes, use your computer (macOS, Windows, Linux) or a Raspberry Pi.

    The smallest and cheapest hardware controller is the UniFi Cloud Key Gen2. There is also a “Plus” version available with a built-in HDD but as I wouldn’t require it (useful if you have surveillance cameras) and the small version is currently not available due to chip-shortage/delivery delays I just tried to re-use my Raspberry Pi.

    So I found some scripts and how-to’s but quickly realized that the UniFi Controller still requires a very old MongoDB version – as far as I’m aware it’s MongoDB 3.6 (official EOL date April 2021)…and because of this you cannot use the latest Ubuntu or Raspbian releases as the installation will fail. There might be some ways out of that situation but I was looking for a straight forward installation method to get it up and running. So here is what finally worked.

    I’m using macOS but should be similar on Windows.

    Prerequisites

    Raspberry Pi 3 or newer + MicroSD card with around 8GB.

    Preparation

    Download the official Raspberry Pi Imager (available for macOS, Windows and Linux)

    Insert your microSD card in your SD-card reader/slot and select “Raspberry Pi OS (other)” in the Imager, now scroll all the way down and select “Raspberry Pi Lite (Legacy)” it should be a port of Debian Buster (any newer release won’t work out of the box, same for Ubuntu 20 and newer). If this one is not available anymore, I used this one. This is a 32-bit release which is mandatory. 64-bit does not work.

    Now choose your SD card and pre-configure the image (enable SSH, locale, WiFi…) as this already configures the system to be ready to use and you don’t need to connect a display and keyboard for the initial setup. So it is ready to run and you can logon via SSH – which we will do in the next step.

    Install UniFi controller

    Start the Raspberry with your newly created image and wait until it’s booted, find out the IP-address (e.g. on macOS use LanScan, easy and free).

    Open the Terminal (or Putty on Windows) and connect to the Raspberry:

    ssh <user>@<ipaddress> 

    and login.

    Now update installed packages:

    sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get autoremove && sudo apt-get autoclean

    Next add Ubiquiti as an additional new source for the package manager:

    echo deb https://www.ui.com/downloads/unifi/debian stable ubiquiti | sudo tee /etc/apt/sources.list.d/100-ubnt-unifi.list

    And trust the new source:

    sudo wget -O /etc/apt/trusted.gpg.d/unifi-repo.gpg https://dl.ui.com/unifi/unifi-repo.gpg

    Now install Java, here we are going to use OpenJDK:

    sudo apt-get update && sudo apt-get install openjdk-8-jre-headless -y

    Finally, you can install another tool called Haveged but this is not mandatory. The reason why I would recommend to install it is to speed up the start time of the UniFi controller. Some users complained that the start of the UniFi controller is very slow. This seems to be related to the fact that the UniFi controller relies on user-mouse-movements to generate random numbers etc. As your Raspberry will be most likely headless without any mouse connected this might be useful. So just install it:

    sudo apt install haveged -y

    After completing all previous installations, now all the required dependencies are available now and we can install the UniFi controller itself:

    sudo apt-get install unifi -y

    Once this is complete you can decide if you want to disable MongoDB, I did not try that but MongoDB seems only required for reporting and statistics, so if you don’t use/want/require that, feel free to try that:

    sudo systemctl disable mongodb && sudo systemctl stop mongodb

    Finally, check your installation:

    sudo service unifi status

    And do a reboot:

    sudo reboot now

    After your Raspberry has rebooted you can open your browser and start with the actual setup of the UniFi controller:

    https://<RaspberryPiIPAddress>:8443

    Have fun ­čśü