How to Install SonarQube in Ubuntu 20.04 LTS
Introduction
SonarQube is an open source web based tool to manage code quality and code analysis. It is most widely used in continuous code inspection which performs reviews of code to detect bugs, code smells and vulnerability issues of programming languages such as PHP, C#, JavaScript, C/C++ and Java, also tracks statistics and creates charts that enable developers to quickly identify problems in their code.
Prerequisites
- Ubuntu 20.04 LTS with minimum 2GB RAM and 1 CPU.
- PostgreSQL Version 9.3 or higher.
- Apache Tomcat.
- SSH access with root privileges.
- Firewall Port: 9000.
- $ sudo apt-get update
- $ sudo apt install openjdk-11-jdk
- $ java -version
- $ sudo gedit /etc/profile
export PATH=$JAVA_HOME/bin:$PATH
- $source /etc/profile or source ~/.bashrc
- $echo $JAVA_HOME
Configure VM Map count & Security limit
- $ sudo sysctl -w vm.max_map_count=262144
- $ sudo sysctl -w fs.file-max=65536
- $ sudo vi /etc/security/limits.conf
#Add the below line end of the line and save the file.
sonarqube - nofile 65536
sonarqube - nproc 4096
Install and Setup PostgreSQL 10 Database for SonarQube
- Create the file “/etc/apt/sources.list.d/pgdg.list” and add the corresponding line for the repository in it:
$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
- Import the repository signing key and update the package lists:
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add –
- added the PostgreSQL official repository to our system
$ sudo apt-get update
- To install PostgreSQL on Ubuntu, use the apt-get (or other apt-driving) command:
$ sudo apt-get -y install postgresql
- Update Postgres account Password
$ sudo passwd postgres
$ su – postgres
- Create a user and database for Sonarqube
postgres@manikandan-VirtualBox: $ createuser sonar
postgres@manikandan-VirtualBox:~$ psql
postgres=# ALTER USER sonar WITH ENCRYPTED password 'sonar123';
postgres=# CREATE DATABASE sonarqube OWNER sonar;
postgres=# grant all privileges on DATABASE sonarqube to sonar;
postgres=# exit
postgres@manikandan-VirtualBox:~$ exit
Install and configure SonarQube
- $ sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-8.9.1.44547.zip
- $ sudo unzip sonarqube-8.9.1.44547.zip
- $ sudo mv sonarqube-8.9.1.44547 /opt
- $ cd /opt
- $ cd sonarqube-8.9.1.44547/
- $ sudo gedit sonar.properties
Remove the # symbol on the below line in sonar.properties
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar123
sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube
sonar.web.javaOpts=-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError
sonar.web.host=0.0.0.0
sonar.web.port=9000
sonar.web.javaAdditionalOpts=-server
sonar.path.logs=logs
sonar.log.level=INFO
- $ ./sonarqube-8.9.1.44547/bin/linux-x86-64/sonar.sh status
- $ sudo ./sonarqube-8.9.1.44547/bin/linux-x86-64/sonar.sh start
- Open http://localhost:9000 on web browser
Note: if the connection not established, check the Apache tomcat running status.
Default Login:
UserName : admin
Password : admin
PDF for Document available to Download
Happy learning and provide the valuable feedback as comments
Comments
Post a Comment