SonarQube is one of the popular static code analysis tools. SonarQube enables developers to write cleaner, safer code. SonarQube is open-source, Java based tool. SonarQube uses database for storing analysis results. Database can be MS SQL, Oracle or PostgreSQL. We will use PostgreSQL as it is open source as well.
Instance should have at least 2 GB RAM. Make sure port 9000 is opened as port 9000 is default port for SonarQube.
Let us start with java install (skip java install if you already have it installed).
Change Host Name to SonarQube
sudo hostname SonarQube
Install Open JDK 11
sudo hostname SonarQube
Postgres DB Setup
sudo apt-get -y install postgresql postgresql-contrib
Ignore the message in red color below:
sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo su - postgres
9. Switch to sql shell by entering
psql
Execute the below three lines (one by one)
ALTER USER sonar WITH ENCRYPTED password 'password';
CREATE DATABASE sonarqube OWNER sonar;
GRANT ALL PRIVILEGES ON DATABASE sonarqube to sonar;
and then type exit to come out of postgres user.
3. Download SonarQube and Install
sudo apt-get -y install unzip
sudo unzip sonarqube*.zip -d /opt
sudo mv /opt/sonarqube-8.6.0.39681 /opt/sonarqube -v
sudo vi /opt/sonarqube/conf/sonar.prop
uncomment the below lines by removing # and add values highlighted yellow
sonar.jdbc.username=sonar
sonar.jdbc.password=password
sonar.jdbc.url=jdbc:postgresql
Now press escape button, and enter :wq! to come out of the above screen.
Execute the below command:
sudo vi /etc/systemd/system/sonar.serv
add the below code in green color:
[Unit]
Description=SonarQube service
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/opt/sonarqube/bin/l
ExecStop=/opt/sonarqube/bin/li
LimitNOFILE=131072
LimitNPROC=8192
User=sonar
Group=sonarGroup
Restart=always
[Install]
WantedBy=multi-user.target
Add the following lines to the bottom of that file:
vm.max_map_count=262144
fs.file-max=65536
Next, we're going to edit limits.conf. Open that file with the command:
sonar - nofile 65536
sonar - nproc 4096
sudo systemctl status sonar
type q now to come out of this mode.
Now execute the below command to see if Sonarqube is up and running. This may take a few minutes.
tail -f /opt/sonarqube/logs/sonar*.log
Make sure you get the below message that says sonarqube is up..
Now access sonarQube UI by going to browser and enter public dns name with port 9000
after setup when accessing with browser ip_address:9000 I got "The connection has timed out"
ReplyDelete