Bobcares

Unifi Controller on Google Cloud Platform | In 5 easy steps

by | Jun 15, 2022

Unifi Controller on Google Cloud Platform allows users to manage their Unifi products, such as wireless access points, routers, and switches, from a web browser.

As part of our Google Cloud Platform Support, Bobcares responds to all inquiries, no matter how big or small.

Let’s take a closer look at Google Cloud Platform’s Unifi Controller.

Unifi Controller on Google Cloud Platform

The Unifi Controller from Ubiquity allows web management of Unifi products such as wireless access points, routers, and switches. They have a great guide for setting up the controller on Amazon AWS using the free tier, which includes a free virtual machine for a year. If we want to keep using the VM after the year is up, we’ll have to pay.

Google Cloud Platform (GCP) also has a free tier that includes a free micro VM for life, similar to what Amazon provides. The goal of this guide is to lay out the steps for setting up a Unifi Controller in Google Cloud Platform.

Step 1: Create or sign up for a Google Cloud Platform account.

  1. Firstly, go to https://cloud.google.com/free/.
  2. Then, to begin registering for an account, click the Try Free button.
  3. Then go to https://console.cloud.google.com and log in with the Google account.
  4. Select the Unifi Controller project that we want to use. My first project will be selected when creating a free account.
  5. Finally, change the Project name under Menu>IAM & admin>Settings.

Step 2: Creating Scripted Instances.

Google Cloud Shell allows us to build an instance from the command line rather than going through the GUI step by step. Misconfiguration errors caused by missed steps or typos are no longer a problem.

If we use this method with Petri’s script, we won’t need to do anything else because everything on Debian is automated. The steps after this walk through the configuration are for those who want to build it manually or understand the nuts and bolts behind the scenes.

After logging into the console site, click the Activate Cloud Shell button in the upper right corner. The Cloud Shell interface will appear in a black box in the lower portion of the page. Replace text as needed after copying and pasting the commands.

Creating a storage bucket

The backups will be stored in a separate location in a storage bucket, allowing us to quickly destroy the controller and restore from a recent backup. Make sure some-unique-name is replaced with a name of our choosing. Other regions, with the exception of us-east4, are available in the free tier as long as they are in the United States.

gsutil mb -c regional -l us-central1 gs://some-unique-name

Creating a static external IP

The external IP can be reserved and remains free as long as it is attached to a running VM instance to prevent it from changing over time. We may be charged for the static IP until we delete it if we destroy the instance without creating a replacement or if we turn it off for more than 1 hour.

gcloud compute addresses create unifi-external \ --region us-central1

Create the Firewall Rules

This series of lines will generate several firewall rules for the Unifi controller and add them to the unifi-server tag, which will be assigned to the server instance as well.


gcloud compute firewall-rules create "unifi-http" \

--allow tcp:80,tcp:8443,tcp:8880,tcp:8843 \

–description=”Ports used for HTTP and HTTPS on non-standard ports” \

–target-tags=unifi-server


gcloud compute firewall-rules create "unifi-inform" \

–allow tcp:8080 \

–description=”Port for device and controller communication” \

–target-tags=unifi-server


gcloud compute firewall-rules create "unifi-stun" \

–allow udp:3478 \

–description=”Port used for STUN” \

–target-tags=unifi-server


gcloud compute firewall-rules create "unifi-throughput" \

–allow tcp:6789 \

–description=”Port used for UniFi mobile speed test” \

–target-tags=unifi-server

Creating the VM Instance

unifi controller on google cloud platform

Within the free tier allowances, this series of lines will create the instance. To change the name of the instance, edit the first line after create. Modify or remove the last line beginning with –metadata if we don’t want to use Petri’s automatic configuration script or if we want to add more options.

gcloud compute instances create unifi-controller \
	--machine-type f1-micro \
	--image-family debian-9 \
	--image-project debian-cloud \
	--boot-disk-type pd-standard \
	--boot-disk-size 25GB \
	--zone us-central1-c \
	--description "Unifi Controller" \
	--scopes=default,storage-rw \
	--tags unifi-server \
	--address unifi-external \
	--metadata=startup-script-url=gs://petri-unifi/startup.sh,timezone=US/Central,dns-name=your.domain.com,bucket=some-unique-name

 

If we want to use another OS image, we can get the full list from the Cloud Shell with the command below.

gcloud compute images list

Take note of the Family and Project names, which are “debian-9” and “debian-cloud” in this case.

Step 3: Creating a Virtual Machine Instance

  1. Firstly, choose Compute Engine and then VM Instances from the menu button in the upper left corner.
  2. Then, if prompted, wait for the Compute Engine to complete initialising.
  3. Then, click Create in the right panel under VM Instances in the left panel.
  4. For the VM, type a name.
  5. Then choose a Zone or leave it at default.
  6. Then, if using the Free offering, change Machine Type to micro.
  7. On the Boot disc, click Change. Choose a version of Ubuntu, such as Ubuntu 16.04 LTS.
  8. An incompatible version of MongoDB is present in more recent images of Ubuntu. Debian is an alternative.
  9. Then, make the disc size 25 GB and the disc type Standard Persistent.
  10. The controller software may need 30 GB to function properly. Unless this instance is size to 25 GB, The Cloud Shell consumes 5 GB and may exceed the free limits.
  11. Then, uncheck the Firewall checkboxes. Later, these will be configured.
  12. Then, select Set access for each API under Access Scopes and change Storage to Read Write if configuring backups as described later in this guide.
  13. On the Networking tab, click the Management, discs, networking, SSH key link. Enter unifi-server in the Network tags box.
  14. When creating firewall rules, this will be used.
  15. Then, to begin the process, click Create.
  16. Then, allow a few minutes for the VM to be created. When finished, a green checkbox will appear to the left of the name.
  17. Go to Google Cloud Platform Menu>Networking>VPC Network>Firewall rules.
  18. At the top of the page, click Create firewall rule. A number of rules will be required. They can be broken down into individual rules or combined into a single rule that covers all required ports.
  19. Then select Google Cloud Platform menu>Networking>VPC Network>External IP Addresses from the Google Cloud Platform menu.
  20. Then, to prevent the IP from changing over time, change the existing assignment from Ephemeral to Static.

Step 4: Swap configuration on the VM

If we use the f1-micro instance, there’s a good chance the VM will run out of RAM and stop working. Configure a swap file to assist with this. This may not be necessary if using a larger VM.

To create the swap file and make it permanent, copy and paste the following commands into the SSH session to the VM.

  • 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

Use the following command to see how much RAM and swap memory is being used.

free -h

Step 5: Installing the Controller Software.

  1. Firstly, Select Menu>Compute Engine>VM Instances. Click the SSH button on the line with the controller VM. A new window with an SSH session to the VM will appear.
  2. Then, to add the Ubiquity repository and the GPG key, run the commands below. You can copy and paste these 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 PRXUJQL2AYMEZF85

  3. The source may be disabled after an upgrade to a new release. Make changes to the sources.list file to remove the # from the beginning of the ubnt line
  4. Then to start the Unifi installation, run the following commands to update the server’s repository:

    sudo apt-get update

    sudo apt-get install unifi

  5. If prompted, select Y to continue downloading and installing any required packages.
  6. Install haveged for faster entropy generation to speed up the VM’s initial startup time. When the VM boots with haveged, the first startup of Unifi will take 6-10 minutes. Without it, it could take 20 to 25 minutes.

    sudo apt-get install haveged

  7. When finished, type exit to end the SSH session.
  8. Then, take note of the VM’s External IP address in the VM Instances window.
  9. Then, navigate to https://External-IP:8443/ in the browser.
  10. Replace External-IP with the VM’s External IP.
  11. Finally, the controller setup is complete if a webpage appears.

[Looking for a solution to another query? We are just a click away.]

Conclusion

To sum up, our Support team explained the Unifi Controller on Google Cloud Platform.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.