Running Confluence on Azure VM – Creating Azure VM with custom Ubuntu image [2/4]

This is a multi-post guide on how to prepare and run Confluence in an Azure VM. While there are prebuilt images for Ubuntu available in Azure this guide will show how to deploy your own image.

Preparations

Requirements: Azure CLI, AzCopy

Visual Code with Azure extensions are recommended.

Create VM in Azure

# Prepare Powershell environment with setup configuration $cfg = @{ location='<azure location>' rg='<resourcegroup name>-rg' nsg='<networksecurity name>-nsg' vnet='<vnet name>-vnet' nic='<nic name>-vm-nic' subnet='10.0.0.0/24' publicIP='<ip name>-ip' publicDnsName='<your domainname, replace dots with dash>' publicAdminIP='<your public ip>' vm='<vm name>-vm' vmOsDisk='<vm name>-vm-disk_os' vmDataDisk='<vm name>-vm-disk_data' imagePath='<your image path>\az-ubuntu-20.vhd' azCopyPath='<your azcopy path>' }
Code language: PowerShell (powershell)
# Create resource group az group create --name $cfg.rg --location $cfg.location
Code language: PowerShell (powershell)
# Create network security group az network nsg create --resource-group $cfg.rg --name $cfg.nsg az network nsg rule create --resource-group $cfg.rg --nsg-name $cfg.nsg --name Ssh --protocol tcp --priority 1000 --source-address-prefixes $cfg.publicAdminIP --destination-port-range 22 --access allow az network nsg rule create --resource-group $cfg.rg --nsg-name $cfg.nsg --name Confluence --protocol tcp --priority 1020 --source-address-prefixes $cfg.publicAdminIP --destination-port-range 443 --access allow az network nsg rule create --resource-group $cfg.rg --nsg-name $cfg.nsg --name LetsEncrypt --protocol tcp --priority 1040 --destination-port-range 80 --access allow
Code language: PowerShell (powershell)
# Remove Network Watcher resource (optional) # az group delete --name NetworkWatcherRG
Code language: PowerShell (powershell)
# Create network interface az network vnet create --resource-group $cfg.rg --name $cfg.vnet --address-prefix $cfg.subnet --subnet-name server --subnet-prefix $cfg.subnet az network public-ip create --resource-group $cfg.rg --name $cfg.publicIP --dns-name $cfg.publicDnsName az network nic create --resource-group $cfg.rg --name $cfg.nic --vnet-name $cfg.vnet --subnet server --public-ip-address $cfg.publicIP --network-security-group $cfg.nsg
Code language: PowerShell (powershell)
# Create OS disk # See guide at https://docs.microsoft.com/en-us/azure/virtual-machines/linux/disks-upload-vhd-to-managed-disk-cli $imageSize = (Get-ChildItem $cfg.imagePath).Length az disk create --resource-group $cfg.rg --name $cfg.vmOsDisk -l $cfg.location --for-upload --upload-size-bytes $imageSize --sku StandardSSD_LRS $sas = (az disk grant-access --resource-group $cfg.rg --name $cfg.vmOsDisk --access-level Write --duration-in-seconds 3600) | Out-String | ConvertFrom-Json cd $cfg.azCopyPath .\AzCopy.exe copy $cfg.imagePath $sas.accessSas --blob-type PageBlob az disk revoke-access --resource-group $cfg.rg --name $cfg.vmOsDisk
Code language: PowerShell (powershell)
# Create data disk az disk create --resource-group $cfg.rg --name $cfg.vmDataDisk --size-gb 4 --sku StandardSSD_LRS --os-type Linux
Code language: PowerShell (powershell)
# Create vm # Manually specifying hostname. See https://docs.microsoft.com/en-us/azure/virtual-machines/linux/cloudinit-update-vm-hostname $cloudInit = @" #cloud-config hostname: $($cfg.vm) "@ New-Item -Name cloud-init.yaml -ItemType File -Value $cloudInit az vm create --resource-group $cfg.rg --location $cfg.location --name $cfg.vm --os-type linux --size Standard_B2S --attach-os-disk $cfg.vmOsDisk --nics $cfg.nic --attach-data-disks $cfg.vmDataDisk --custom-data cloud-init.yaml
Code language: PowerShell (powershell)

After the VM is created is it booted automatically and available for SSH login (which is restricted to your public IP). You can connect to the VM using the DNS name <your-domainname>.<azure-location>.cloudapp.azure.com.

In next step we’ll configure the running Azure VM:

Leave a comment

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