RHEL 7 install sonarqube server

This article will show you how to install sonarqube server on RHEL 7 with docker support.

Create database schema for sonarqube

# Create database role sonar
postgres=# create user sonar;

# Create database for sonarqube and assign newly created sonar user.
postgres=# create database sonar_db owner sonar;

# Grant all privileges to sonar user
postgres=# grant all privileges on database sonar_db to sonar;

# Update sonar user password
postgres=# ALTER USER sonar WITH ENCRYPTED password 'StrongPassword';

# Check newly created database 
postgres=# \l
# Output:
sonar_db  | sonar          | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/sonar            +
           |                |          |             |             | sonar=CTc/sonar

Deploy sonarqube server via docker

Create docker volumes for sonarqube
# sonarqube_data – contains data files, such as the embedded H2 database and Elasticsearch indexes
docker volume create --name sonarqube_data
# sonarqube_logs – contains SonarQube logs about access, web process, CE process, and Elasticsearch
docker volume create --name sonarqube_logs
# sonarqube_extensions – will contain any plugins you install and the Oracle JDBC driver if necessary.
docker volume create --name sonarqube_extensions

Deploy server with docker command
docker run -d \
  -p 9000:9000 \
  --name sonarqube \
  -e LETSENCRYPT_HOST=your-sonar-host \
  -e LETSENCRYPT_EMAIL=your-email-address \
  -e SONAR_JDBC_URL=jdbc:postgresql://youdb-url:5432/sonar_db \
  -e SONAR_JDBC_PASSWORD=StrongPassword \
  -v sonarqube_data:/opt/sonarqube/data \
  -v sonarqube_extensions:/opt/sonarqube/extensions \
  -v sonarqube_logs:/opt/sonarqube/logs \
# Example output:
$> docker ps -a
CONTAINER ID   IMAGE                     COMMAND                  CREATED         STATUS                    PORTS                                       NAMES
641f808ccbf2   sonarqube:lts-community   "bin/run.sh bin/sona…"   4 seconds ago   Up 3 seconds    >9000/tcp, :::9000->9000/tcp   sonarqube

Visit your host site to manage sonarqube projects

You may need to open 9000 port in firewall in order to access sonar server site: http(s)://yourhost:9000

Trouble shooting

In case you have below when start the sonarqube container:

ERROR: [1] bootstrap checks failed. You must address the points described in the following [1] lines before starting Elasticsearch.
bootstrap check failure [1] of [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

Run below command before run docker command:

sysctl -w vm.max_map_count=262144