Linux Programmer | RHCE | RHCSA

Search This Blog

SonarQube installation ubuntu

1. Installation in ubuntu 22.04

System Requirements:

OS - Ubuntu 22.04 LTS

CPU - 2vCPU

RAM - 4 GB

Storage - 20G

Below are the ports:

SonarQube port - 9000


1) Login server and install packages:

sudo apt upgrade -y
sudo apt install -y openjdk-17-jdk
java --versionepo

2) Install postgres:

Add the postgresSQL 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'
Add signing key:
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
Install postgres:
sudo apt install postgresql postgresql-contrib -y
Enable service:
sudo systemctl enable postgresql
start database:
sudo systemctl start postgresql
check service:
sudo systemctl status postgresql
psql --version
switch to postgres user:
sudo -i -u postgres
Create database user:
createuser sonar
Login postgres:
psql
Create user and  set password:
ALTER USER ddsonar WITH ENCRYPTED password 'mwd#2%#!!#%rgs';
Create database:
CREATE DATABASE sonarqube OWNER sonar;
GRANT ALL PRIVILEGES ON DATABASE sonarqube to sonar;
Check created user and database:
\l
check created database user:
\du
exit postgres:
\q
exit

3) Download and install sonarqube:
sudo apt install zip -y
sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-10.0.0.68432.zip
sudo unzip sonarqube-10.0.0.68432.zip
sudo mv sonarqube-10.0.0.68432 sonarqube
sudo mv sonarqube /opt/
Add sonar group and user:
sudo groupadd sonar
sudo useradd -d /opt/sonarqube -g sonar sonar
sudo chown ddsonar:ddsonar /opt/sonarqube -R
4) Make configuration changes:
sudo nano /opt/sonarqube/conf/sonar.properties

sonar.jdbc.username=sonar

sonar.jdbc.password=mwd#2%#!!#%rgs


sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube

sudo nano /opt/sonarqube/bin/linux-x86-64/sonar.sh
RUN_AS_USER=sonar
5) Setup service:
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
Restart sonar service:
sudo systemctl enable sonar
sudo systemctl start sonar
sudo systemctl status sonar

6) Modify kernal system limits:
sudo nano /etc/sysctl.conf
Add below lines.
vm.max_map_count=262144
fs.file-max=65536
ulimit -n 65536
ulimit -u 4096
Reboot system:
reboot

7) Access Sonarqube with web interface:
http://server-ip:9000

Confiugure reverse proxy if wanted to open sonarqube with domain name:
Now we want a domain name to take over the IP of the server so that 
instead of hitting the IP we can use the domain name that is TLS 
enabled. 
Let's see how to do so.
Install Nginx:
apt-get install nginx
Add DNS Record:
A record for the server IP in domain provider.
Create Nginx configuration file.
sudo nano /etc/nginx/sites-enabled/sonarqube
server {
listen 80;
server_name sonarqube.blogspot.com;
location / {
proxy_pass http://127.0.0.1:9000;
}
}
verify nginx configuration:
sudo nginx -t
Restart service:
sudo systemctl enable nginx
sudo systemctl restart nginx
sudo systemctl status nginx
Now we can open sonarqube with domain name.

And there you go.



No comments:

Post a Comment

SSH not working with password after upgrade ubuntu 22.04 or above

In recent upgrade of ubuntu 22.04 and above we are not able to login server with SSH password. but when we try to login with key then it all...