SonarQube on Azure Ubuntu 20.04 LTS

  • Static code analysis for 15 widely-used languages
  • Bug and vulnerability detection
  • Security hotspot review within your code
  • Code smell tracking
  • Technical debt fixing
  • Code quality metrics and history
  • CI/CD integration
  • Extensible, with 50+ community plugins

Prerequisites

  • Deploy a fully updated Ubuntu 20.04 LTS server with at least 2GB of RAM and 1 vCPU cores.
  • Create a non-root user with sudo access.

1. Install OpenJDK 11

  1. SSH to your Ubuntu server as a non-root user with sudo access.
  2. Install OpenJDK 11.
  • $ sudo apt-get install openjdk-11-jdk -y

2. Install and Configure PostgreSQL

  1. Add the PostgreSQL repository.
  • $ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
  • $ wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
  • $ sudo apt install postgresql postgresql-contrib -y
  • $ sudo systemctl enable postgresql
  • $ sudo systemctl start postgresql
  • $ sudo passwd postgres
  • $ su - postgres
  • $ createuser sonar
  • $ psql
  • ALTER USER sonar WITH ENCRYPTED password 'password';
  • CREATE DATABASE sonarqube OWNER sonar;
  • GRANT ALL PRIVILEGES ON DATABASE sonarqube to sonar;
  • \q
  • $ exit

3. Download and Install SonarQube

  1. Install the zip utility, which is needed to unzip the SonarQube files.
  • $ sudo apt-get install zip -y
  • $ sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-<VERSION_NUMBER>.zip
  • sudo unzip sonarqube-<VERSION_NUMBER>.zip
  • sudo mv sonarqube-<VERSION_NUMBER> /opt/sonarqube

4. Add SonarQube Group and User

  1. Create a sonar group.
  • $ sudo groupadd sonar
  • $ sudo useradd -d /opt/sonarqube -g sonar sonar
  • $ sudo chown sonar:sonar /opt/sonarqube -R

5. Configure SonarQube

  1. Edit the SonarQube configuration file.
  • $ sudo nano /opt/sonarqube/conf/sonar.properties
  • #sonar.jdbc.username= #sonar.jdbc.password=
  • sonar.jdbc.username=sonar sonar.jdbc.password=password
  • sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube
  • $ sudo nano /opt/sonarqube/bin/linux-x86-64/sonar.sh
  • #RUN_AS_USER=
  • RUN_AS_USER=sonar

6. Setup Systemd service

  1. Create a systemd service file to start SonarQube at system boot.
  • $ sudo nano /etc/systemd/system/sonar.service
  • [Unit]
  • Description=SonarQube service
  • After=syslog.target network.target
  • [Service]
  • Type=forking ExecStart=/opt/sonarqube/bin/linux-x86-64/sonar.sh start
  • ExecStop=/opt/sonarqube/bin/linux-x86-64/sonar.sh stop
  • User=sonar
  • Group=sonar
  • Restart=always
  • LimitNOFILE=65536
  • LimitNPROC=4096
  • [Install]
  • WantedBy=multi-user.target
  • $ sudo systemctl enable sonar
  • $ sudo systemctl start sonar
  • $ sudo systemctl status sonar

7. Modify Kernel System Limits

  1. Edit the sysctl configuration file.
  • $ sudo nano /etc/sysctl.conf
  • vm.max_map_count=262144 fs.file-max=65536 ulimit -n 65536 ulimit -u 4096
  • $ sudo reboot

8. Access SonarQube Web Interface

http://localhost:9000

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store