Deployment guide

SonarQube

Overview

SonarQube is the widely used continuous code-quality and static-analysis platform. It inspects your code for bugs, vulnerabilities, security hotspots and code smells across dozens of languages, tracks technical debt over time, and enforces a configurable Quality Gate in your CI pipeline.

The SecureAnyCloud image installs SonarQube Community Edition (the official SonarSource distribution) under a dedicated non-root sonarqube service user, on the OpenJDK 17 JRE, behind nginx as a reverse proxy. The SonarQube web server listens on 127.0.0.1:9000 and is reached through nginx on port 80. A local PostgreSQL is SonarQube's mandatory backing store and binds to the loopback interface only.

SonarQube embeds Elasticsearch for its search index, which requires the kernel settings vm.max_map_count=524288 and fs.file-max=131072. These are written to /etc/sysctl.d/99-sonarqube.conf so they persist across every reboot, and Elasticsearch runs as the non-root sonarqube user. SonarQube does not support its embedded H2 database for real use, so this image ships a local PostgreSQL as the backing store.

SonarQube's default admin account has its password rotated to a unique per-VM value on the first boot of every deployed VM. The password is written to /root/sonarqube-credentials.txt with mode 0600, so no two VMs share credentials.

What you get:

  • SonarQube Community Edition 10.7 (/opt/sonarqube) on the OpenJDK 17 JRE, run as the non-root sonarqube user
  • nginx reverse proxy on :80 in front of the SonarQube web server (bound to loopback :9000), with an unauthenticated /health endpoint
  • PostgreSQL as SonarQube's backing database, bound to loopback only
  • A dedicated 40 GiB Azure data disk at /var/lib/sonarqube that holds the SonarQube data/ and extensions/ directories and the PostgreSQL datadir, separate from the OS disk and re-provisioned with every VM
  • Elasticsearch kernel and ulimit requirements persisted in /etc/sysctl.d and /etc/security/limits.d
  • Per-VM admin password, rotated at first boot, in a root-only file
  • sonarqube.service, postgresql.service and nginx.service as systemd units, enabled and active
  • 24/7 SecureAnyCloud support

Prerequisites

You need an active Azure subscription, an SSH key pair, and a VNet and subnet in the target region.

Standard_B4ms (4 vCPU / 16 GiB RAM) is the recommended starting point. SonarQube runs a JVM web process, a JVM compute-engine process and an embedded Elasticsearch JVM alongside PostgreSQL, so it needs memory headroom.

On the NSG, allow inbound 22/tcp from your management network and 80/tcp from the networks your users and CI runners will reach SonarQube on. For public exposure, front port 80 with TLS (see Enabling HTTPS).

Step 1 - Deploy from the Azure Marketplace

Sign in to the Azure Portal, choose Create a resource, search the Marketplace for SonarQube by SecureAnyCloud, and select Create.

On Basics, pick your subscription, resource group, region and size. Under Administrator account, choose SSH public key and paste your key. Under Inbound port rules, allow SSH (22) and HTTP (80).

Review the dedicated data disk on the Disks tab, then select Review + create and Create.

First-boot initialisation takes approximately three to five minutes after the VM starts. SonarQube runs its database migrations, bootstraps Elasticsearch and rotates the admin password on first boot.

Step 2 - Deploy from the Azure CLI

Accept the Marketplace terms once per subscription, then create the VM and open port 80:

# Accept the Marketplace terms once per subscription (required before the first CLI deploy)
az vm image terms accept --urn sac1647283583153:sonarqube-ubuntu-24-04:default:latest
az vm create \
  --resource-group <your-rg> \
  --name sonarqube \
  --image sac1647283583153:sonarqube-ubuntu-24-04:default:latest \
  --size Standard_B4ms \
  --admin-username azureuser \
  --ssh-key-values ~/.ssh/id_ed25519.pub \
  --vnet-name <your-vnet> --subnet <your-subnet> \
  --public-ip-sku Standard
az vm open-port --resource-group <your-rg> --name sonarqube --port 80 --priority 1010

Step 3 - Connect to your VM

Connect to the VM over SSH:

ssh azureuser@<vm-public-ip>

Step 4 - Confirm the services are running

Check the three services and the health and status endpoints:

systemctl is-active sonarqube.service postgresql.service nginx.service curl -fsS http://127.0.0.1/health curl -fsS http://127.0.0.1/api/system/status

All three services report active, the open /health endpoint returns ok, and /api/system/status reports "status":"UP". This confirms that the full stack is serving: nginx, the SonarQube web server, the compute engine, Elasticsearch and PostgreSQL.

On the very first boot, allow a few minutes for migrations and the Elasticsearch bootstrap before the status reports UP.

Step 5 - Retrieve your administrator login

SonarQube's default admin password is rotated to a value unique to your VM on first boot and written to a root-only file. Print the file:

sudo cat /root/sonarqube-credentials.txt

The SONARQUBE_ADMIN_PASSWORD value is your sign-in password, and the username is admin.

To verify the credentials over the API without a browser, call the open /api/authentication/validate endpoint with basic auth. For example, curl -u admin:<SONARQUBE_ADMIN_PASSWORD> http://127.0.0.1/api/authentication/validate returns {"valid":true} for the correct password and {"valid":false} for a wrong one.

Step 6 - First sign-in

Open a web browser and navigate to http://<vm-public-ip>/. Sign in with the username admin and the password from /root/sonarqube-credentials.txt.

The sign-in page is served through nginx, and the per-VM administrator password has already been rotated at first boot.

Step 7 - Create a project and analyse code

After you sign in, choose Create a local project, or import from Azure DevOps, GitHub, GitLab or Bitbucket. Give the project a key and set up the analysis method.

For a local project, generate a project analysis token, then run the SonarScanner in your source tree, pointing at this server. SonarQube supports Maven, Gradle, .NET and the standalone SonarScanner CLI. The UI shows the exact command once you pick your build system.

Step 8 - Quality Gates

A Quality Gate is the set of conditions your code must meet to be marked as passing. For example: no new bugs, no new vulnerabilities, and coverage on new code above a threshold.

SonarQube ships the built-in Sonar way gate. Open Quality Gates in the top menu to review it or create your own, then assign a gate to your projects so that every analysis is enforced consistently in CI.

Step 9 - Confirm the runtime and system info

Confirm the SonarQube version, the Java runtime and the persisted Elasticsearch kernel requirements from the shell. The running server details are shown under Administration, then System:

curl -fsS http://127.0.0.1/api/server/version java -version sysctl vm.max_map_count fs.file-max

The System page shows the server ID, edition and version, and the health of the web, compute-engine and search components.

Step 10 - Confirm the data tiers

The SonarQube data/ and extensions/ directories and the PostgreSQL datadir all live on the dedicated 40 GiB Azure data disk mounted at /var/lib/sonarqube:

findmnt -no SOURCE,SIZE,FSTYPE,TARGET /var/lib/sonarqube
sudo -u postgres psql -tAc 'SHOW data_directory'

Enabling HTTPS

Serve SonarQube over HTTPS so that session tokens and analysis data cannot be intercepted. The image ships with nginx, which certbot can configure automatically. The following assumes a DNS record that points your fully qualified domain name at the VM's public IP:

sudo apt-get update && sudo apt-get install -y certbot python3-certbot-nginx
sudo certbot --nginx -d sonarqube.your-domain.example \
  --non-interactive --agree-tos -m you@your-domain.example \
  --redirect

After certbot finishes, set the Server base URL to your HTTPS URL under Administration, then Configuration, then General Settings. This makes SonarQube generate correct links in notifications and pull-request decorations.

Backup and maintenance

SonarQube keeps all of its state (projects, issues, measures, quality profiles, quality gates and users) in its PostgreSQL backing database on the dedicated data disk. Back it up regularly:

sudo -u postgres pg_dump sonarqube > /tmp/sonarqube-db-$(date +%F).sql

Ship the dump to Azure Blob Storage or another object store, or snapshot the data disk in Azure for a coordinated point-in-time backup.

Keep the OS patched with sudo apt update && sudo apt upgrade. To upgrade SonarQube itself, follow the official upgrade guide for your target version, and always take a database backup first. The compute engine migrates the schema on the next start. Elasticsearch's kernel requirements are already persisted, so they survive reboots and upgrades.

Support

This image is backed by 24/7 SecureAnyCloud support. Contact us by email and chat for help with deployment, project onboarding, CI integration, upgrades, TLS termination and database administration. Email sales@secureanycloud.com.

For general SonarQube questions, consult the documentation at https://docs.sonarsource.com/. SonarQube is a trademark of SonarSource SA. All product and company names are trademarks or registered trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.

Deploy on Azure

Launch SonarQube Community on Ubuntu 24.04 LTS on Azure with 24/7 support from SecureAnyCloud.

View this image

Need Help?

Our support team is available 24/7.

sales@secureanycloud.com

Deploy on Azure