DevOps Project: Jenkins CI/CD for Kubernetes Deployments

  DevOps Tech Hub

116 Followers

SonarQube Installation Guide


Install & Configure PostgreSQL

1. Enable Install PostgreSQL

[root@~]#amazon-linux-extras install postgresql11
[root@~]#yum install postgresql-server postgresql-devel postgresql -y

2. Initialize PostgreSQL database

 [root@~]#/usr/bin/postgresql-setup  --initdb
* Initializing database in '/var/lib/pgsql/data'
* Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log
[root@~]#

3. Start PostgreSQL service

[root@~]#systemctl start postgresql
[root@~]#systemctl status postgresql
● postgresql.service - PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2020-09-12 09:17:34 UTC; 10s ago
Process: 24156 ExecStartPre=/usr/libexec/postgresql-check-db-dir %N (code=exited, status=0/SUCCESS)
 Main PID: 24158 (postmaster)

4. Create database user for Sonar


[root@~]#su - postgres
Last login: Sat Sep 12 09:19:14 UTC 2020 on pts/0
-bash-4.2$ psql
psql (11.5)
Type "help" for help.

postgres=# CREATE USER sonar WITH PASSWORD 'sonar';
CREATE ROLE
postgres=#\q

5. Grant SUPERUSER role to sonar user

 postgres=# ALTER USER sonar WITH SUPERUSER

6. Update "/var/lib/pgsql/data/pg_hba.conf” file for below - Edit the file from root user

NOTE: Need to run #pg_ctl reload to reload the config.

  1. Which hosts are allowed to connect
  2. How clients are authenticated
  3. Which PostgreSQL user names they can use
  4. Which databases they can access

sample file below:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all trust
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust

7. Create DATABSE for Sonar

 postgres=# CREATE DATABASE sonar;
CREATE DATABASE
postgres=#

8. Grant access to the DATABASE sonar to the user sonar and exit from database

 postgres=# GRANT ALL PRIVILEGES ON DATABASE sonar TO sonar;
GRANT
postgres=# \q
9. Restart database from root user
#service postgresql restart

SonarQube Installation

Note: SonarQube require Java JDK v8 or v11 as pre-requisite , hence first install Java JDK to proceed further SonarQube Scanner Installation

 1. Download SonarQube Package for here

[root@~]#wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.4.1.35646.zip
--2020-09-12 09:30:07-- https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.4.1.35646.zip
Resolving binaries.sonarsource.com (binaries.sonarsource.com)... 91.134.125.245
Connecting to binaries.sonarsource.com (binaries.sonarsource.com)|91.134.125.245|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 231722436 (221M) [application/zip]
Saving to: ‘sonarqube-8.4.1.35646.zip’

100%[=====================================================>] 231,722,436 10.2MB/s   in 23s

2020-09-12 09:30:30 (9.79 MB/s) - ‘sonarqube-8.4.1.35646.zip’ saved [231722436/231722436]

[root@~]#unzip sonarqube-8.4.1.35646.zip

2. Create normal user - sonar

[root@~]#useradd sonar
[root@~]#

3. Configure JDBC details in the "$SONARQUBE-HOME/conf/sonar.properties" file

[root@~]#tail -5 /opt/sonarqube-8.4.1.35646/conf/sonar.properties

sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:postgresql://localhost/sonar
sonar.path.data=/var/sonarqube/data
sonar.path.temp=/var/sonarqube/temp

[root@~]#

4. Update below parameters to the "/etc/sysctl.conf" file and run "#sysctl -p" command to load the parameters.

 vm.max_map_count=524288
fs.file-max=131072

5. Update below parameters to the /etc/security/limits.conf" file  - Edit from root user

 sonar hard nofile 65535
sonar soft nofile 65535

6. Create & Modify sonarQube folder permissions

mkdir /var/sonarqube
chown -R sonar /var/sonarqube
chown -R sonar /opt/sonarqube-8.4.1.35646

7. Start SonarQube service from sonar user

[root@~]# su - sonar
[root@~]#cd /opt/sonarqube-8.4.1.35646/bin/linux-x86-64
[root@~]#./sonar.sh start
Starting SonarQube...
Started SonarQube.
[root@~]# ./sonar.sh status
SonarQube is running (2540).

8. Access SonarQube Dashboard

Username: admin
Password: admin


Previous Next