Introduction: Unifi Controller on Google Cloud Platform (GCP)
Ubiquity's Unifi Controller allows for web management of their Unifi products including wireless access points, routers, and switches. They have an excellent guide for setting up the controller on Amazon AWS using the free tier that gives a free VM for 12 months. Once the year is up, you must pay to continue using the VM.
Google Cloud Platform (GCP) also offers a free tier with a free micro VM forever with similar specs to the Amazon offer. The purpose of this guide is to document the steps to setup a Unifi Controller in GCP.
Step 1: Register/Create Google Cloud Platform Account
- Navigate to: https://cloud.google.com/free/ and click the "Try Free" button to begin registering for an account
- Login with your account at: https://console.cloud.google.com
- Select the project you wish utilize for the Unifi Controller. If setting up a free account, you will have "My first project" selected.
- This can be renamed by going to Menu>IAM & admin>Settings and changing the Project name
Step 2: Creating the VM Instance
- From the Menu button in the upper left corner, select "Compute Engine" then "VM Instances"
- Wait for the Compute Engine to finish initializing if prompted.
- Under "VM Instances" on the left pane, click "Create" in the right pane.
- Enter a name for your VM. In this case "unifi-controller"
- Select a Zone or leave on default
- Change Machine Type to "micro" if using the Free offering
- Click "Change" on Boot disk. Select an Ubuntu image, such as "Ubuntu 17.04"
- Increase the disk type to Standard Persistent Disk and size 20 GB
- Note: 30 GB may be required for proper operation of the controller software.
- Leave Firewall options unchecked. These will be configured later.
- Click "Management, disks, networking, SSH key" link, then click the Networking tab. Under "Network tags" enter: unifi-server
- This will be used when creating firewall rules
- Click "Create" to begin the process
- Click "Create firewall rule" at the top of the page. Several rules will be needed. They can be broken out into individual rules, or one rule to include all needed ports. List of ports
- Name: unifi-ports
- Target tags: unifi-server
- Source IP ranges: 0.0.0.0/0
- Specified protocols and ports: tcp:8880; tcp:8443; tcp:8843; tcp:8080; tcp:6789; udp:3478
Step 3: Configuring Swap on the VM
If using the f1-micro instance, it is quite possible that the VM will run out of the 600 MB ram and stop functioning. To help with this, configure a swap file. If using a larger VM, this may not be necessary. This article walks you through the steps for Ubuntu:
The following commands can be copied and pasted into the SSH session to your VM to create the swap file and make it permanent
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
To verify how much memory is being used, both RAM and swap, use the following command
Step 4: Installing Controller Software
- Click Menu>Compute Engine>VM Instances. On the line with the controller VM, click the SSH button. A new window will appear with and SSH session to the VM.
- Run the following commands to add the Ubiquity repository and add the GPG key. These can be copied and pasted into the SSH window:
echo "deb http://www.ubnt.com/downloads/unifi/debian stable ubiquiti" | sudo tee -a /etc/apt/sources.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 06E85760C0A52C50
- Note: After an upgrade to a new release, the source may be disabled. Edit the sources.list file to remove the # from the beginning of the ubnt line
- sudo nano /etc/apt/sources.list
sudo apt-get update
sudo apt-get install unifi
- replace External-IP with the External IP of your VM
- Note: Step 2 will not discover any devices as the controller is not on the same subnet as the devices. See the Ubiquity article on Layer 3 Adoption
Note: On subsequent reboots, it may take 20-25 minutes for the controller software to start. This is a result of the "Creation of SecureRandom Instance" taking 18+ minutes with the micro instance.