Is it possible to install the sonaqube server under linux while making the necessary settings including sonar-scanner and access the server from a windows system?
If this is possible then how to do this, please?
Hey there.
No matter where a SonarQube server is hosted, a scanner on any machine (mac, windows, linux) can target the server.
hello, thank you
Installing WSL is now easier than ever. Search for Windows PowerShell in your Windows search bar, then select Run as administrator.
At the command prompt type:
install wsl
wsl --install
Install Ubuntu on WSL2 on Windows 10
There is a single command that will install both WSL and Ubuntu at the same time.
When opening PowerShell for the first time, simply modify the initial instruction to:
wsl --install -d ubuntu
This will install both WSL and Ubuntu! Don’t forget to restart your machine before continuing.
search for Ubuntu in your Windows search bar
Configure Ubuntu
Finally, it’s always good practice to install the latest updates with the following commands, entering your password when prompted.
sudo apt update
Then
sudo apt upgrade
How to Use SonarQube on Ubuntu 22.04 LTS
1. Configure Firewall
SonarQube web tool needs HTTP and HTTPS ports to work.
Open them using the Uncomplicated Firewall (UFW).
sudo ufw allow http
sudo ufw allow https
Check the firewall status.
sudo ufw status
2. Install OpenJDK
sudo apt install openjdk-11-jdk
3. Install PostgreSQL
Check the status of the PostgreSQL service.
Configure PostgreSQL
Log in to the PostgreSQL shell.
sudo -u postgres psql
Create the sonar role.
postgres=# CREATE ROLE sonar WITH LOGIN ENCRYPTED PASSWORD 'your_password';
Create the sonarqube database.
postgres=# CREATE DATABASE sonarqube;
Grant all privileges on the sonarqube database to the sonar role.
postgres=# GRANT ALL PRIVILEGES ON DATABASE sonarqube to sonar;
Exit the shell.
postgres=# \q
Return to your default user account.
5. Install Sonarqube
Copy the URL of the latest version of the community edition from the SonarQube downloads page.
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-10.0.0.68432.zip
Unzip the downloaded archive.
unzip -q sonarqube-10.0.0.68432.zip
Move the files to the /opt/sonarqube directory.
sudo mv sonarqube-10.0.0.68432.zip /opt/sonarqube
Delete the downloaded archive.
rm sonarqube-10.0.0.68432.zip
6. Create SonarQube User
Create a system user along with the group for SonarQube.
sudo adduser --system --no-create-home --group --disabled-login sonarqube
Give Sonar user permissions to the /opt/sonarqube directory.
sudo chown sonarqube:sonarqube /opt/sonarqube -R
7. Configure SonarQube Server
Open the SonarQube configuration file for editing.
sudo nano /opt/sonarqube/conf/sonar.properties
Find the following lines.
#sonar.jdbc.username=
#sonar.jdbc.password=
Uncomment them by removing the hash in front of them and adding the database credentials created in step 4.
sonar.jdbc.username=sonar
sonar.jdbc.password= your_password
Find the following line.
#sonar.jdbc.url=jdbc:postgresql://localhost/sonarqube?currentSchema=my_schema
replace the existing value with the following.
sonar.jdbc.url=jdbc:postgresql://localhost:5432/sonarqube
Increase the virtual memory on the system for Elasticsearch to function. Open the sysctl.conf file for editing.
sudo nano /etc/sysctl.conf
Paste the following lines at the end of the file.
vm.max_map_count=524288
fs.file-max=131072
Create the file /etc/security/limits.d/99-sonarqube.conf and open it for editing.
sudo nano /etc/security/limits.d/99-sonarqube.conf
Paste the following lines to increase the file descriptors and threads that the sonarqube user can open.
sonarqube - nofile 131072
sonarqube - nproc 8192
Reboot the system to apply the changes.
sudo reboot
8. Setup Sonar Service
Create the systemd service file for Sonar and open it for editing.
sudo nano /etc/systemd/system/sonarqube.service
Paste the following code in it.
[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=sonarqube
Group=sonarqube
PermissionsStartOnly=true
Restart=always
StandardOutput=syslog
LimitNOFILE=131072
LimitNPROC=8192
TimeoutStartSec=5
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
Save the file by pressing CTRL+X, then Y.
Start the SonarQube service.
sudo systemctl start sonarqube
Check the status of the service.
sudo systemctl status sonarqube
Enable the service to start automatically at boot.
sudo systemctl enable sonarqube
13. Install SonarQube’s Code Scanner
SonarQube provides various scanners depending on the programming language. Install the Command line version of the Sonarscanner.
Download the scanner.
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-4.7.0.2747-linux.zip
Extract the archive.
sudo unzip sonar-scanner-cli-4.8.0.2856-linux.zip
Move the directory to /opt/sonarscanner.
sudo mv sonar-scanner-cli-4.8.0.2856-linux.zip /opt/sonarscanner
start sonarque server under linux and you can access it from windows
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.