How to setup Discourse in Azure


(Blake Erickson) #1

This guide is for those who are interested in self-hosting a Discourse site in Azure and will walk you through the initial Azure Portal details needed to get your Linux VM created so that you can then follow the regular cloud install guide that is web host agnostic. If you are not interested in self-hosting but would like us to host your Discourse forum for you please sign-up here.

1) Create a Resource Group

Before we create the VM, lets create a Resource Group. This is where everything related to your Discourse site will live like your VM storage disks, networking, security groups, blob storage, etc. To create a Resource Group click the green plus sign and select Resource Group, then fill out the “Resource group name” field, select your “Subscription”, and your “Resource group location”, then press “Create”.

image

2) Create the Linux VM

We are going to create an Ubuntu 16.04 LTS VM for this guide, to do that click the green plus sign again and then search for “Ubuntu Server 16.04 LTS” and it should show up as one of the available VM’s.

Select it, and then make sure the deployment model is on “Resource Manager” and then click “Create”

3) Configure basic settings

Now you should be on Step 1 of “Create virtual machine”. Fill out all the required fields to setup the VM. Give your VM a name like “discourse”, keep the disk type on “Premium SSD”, fill out the Linux username, and upload your ssh public key. Alternatively you can configure a password based login, but the ssh key based login is preferred. Then select the existing Resource Group we already created, make sure the location matches the Resource Group location, and then press OK.

4) Choose virtual machine size

For the bare minimum you will need to select the “B1ms” option with 2GB of ram. The “B1s” even though it is advertised with having 1GB you only get around 800MB of ram at the OS level and there just isn’t enough left over to run Discourse well. The “B1ms” will cost $17.11 per month.

5) Configure optional features

All of the optional features in this section are fine to leave at the default settings except for “Select public inbound ports”. You will need to check the HTTP, HTTPS, and SSH boxes. After setup is complete it is a good idea to limit ssh access to only your IP Address.

Select “OK”. Now verify everything is good on the Summary page and then let’s get this VM created.

6) SSH into the VM

Once the VM has been created you should be able to select it from the azure portal and on the Overview screen it will display the Public IP address. Open your terminal and ssh into the VM with the username we specified in step 3 of this guide.

7) Setting up Swap

Each azure VM comes with a temporary disk separate from your OS disk and is usually mounted at /dev/sdb1. You want to make sure your swap is setup on this temporary disk and not your OS disk because:

This temporary storage drive is present on the physical machine which is hosting your VM and hence can have higher IOPS and lower latency when compared to the persistent storage like data disk. - Understanding the temporary drive on Azure Virtual Machines

Edit the /etc/waagent.conf file and update the following lines:

ResourceDisk.Format=y
ResourceDisk.EnableSwap=y
ResourceDisk.SwapSizeMB=2048

Note: If you already have a swap setup on the OS drive (maybe because ./discourse-setup configured it for you) you can turn it off by commenting out the /swapfile line in /etc/fstab.

Then restart your vm with sudo shutdown -r now.

To verify that swap is working type swapon --show and you should see something like:

root@azure:~# swapon --show
NAME          TYPE SIZE USED PRIO
/mnt/swapfile file   2G 0B   -2

Notice that the swap file is located inside of /mnt this is good because this is our temporary drive.

You can also type free -h and see something like:

root@azure:~# free -h
              total        used        free      shared  buff/cache   available
Mem:           1.9G        174M        1.5G        3.0M        172M        1.5G
Swap:          2.0G          0B        2.0G

The swap should have something in the total column which means it has been setup.

8) Install Discourse

Now that our Linux VM has been created on Azure and we have a swap partition it is now time to follow the Official Cloud Install Guide.

9) Install the Azure Blob Storage Plugin (Optional)

Now that Discourse is installed you can follow the install instructions on the Azure Blob Storage Plugin topic. Installing and enabling this plugin will cause images that users upload to be stored in blob storage instead of on your Linux VM which should help with performance as well as keeping your OS disk from filling up.