====== Install SonarQube======
SonarQube is a free and open source quality management software that can be used to automate code quality inspections.
Make sure that all of the latest patches are installed.
sudo apt update
sudo apt dist-upgrade
sudo reboot
Install [[linux:install:java]]
Install PostgreSQL and configure:
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee /tmp/postgresql.list
sudo mv /tmp/postgresql.list /etc/apt/sources.list.d/
wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
sudo apt update
sudo apt install postgresql postgresql-contrib -y
sudo systemctl start postgresql
sudo systemctl enable postgresql
sudo su - postgres
psql
CREATE USER sonar WITH ENCRYPTED password 'P@ssword';
CREATE DATABASE sonar OWNER sonar;
\q
exit
Download, install, and configure SonarQube:
sudo apt install unzip -y
cd /tmp
VERSION=7.5
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-$VERSION.zip
sudo unzip sonarqube-$VERSION.zip -d /opt
if [ -d "/opt/sonarqube" ]; then
sudo rm /opt/sonarqube
fi
sudo ln -s /opt/sonarqube-$VERSION /opt/sonarqube
sudo sed -i 's/#sonar.jdbc.username=/sonar.jdbc.username=sonar/g' /opt/sonarqube/conf/sonar.properties
sudo sed -i 's/#sonar.jdbc.password=/sonar.jdbc.password=P@ssword/g' /opt/sonarqube/conf/sonar.properties
sudo sed -i 's/#sonar.jdbc.url=jdbc:postgresql:\/\/localhost\/sonar/sonar.jdbc.url=jdbc:postgresql:\/\/localhost\/sonar/g' \
/opt/sonarqube/conf/sonar.properties
sudo sed -i 's/#sonar.search.javaOpts=-Xms512m -Xmx512m/sonar.search.javaOpts=-Xms512m -Xmx512m/g' \
/opt/sonarqube/conf/sonar.properties
sudo sed -i 's/#sonar.web.host=0.0.0.0/sonar.web.host=127.0.0.1/g' /opt/sonarqube/conf/sonar.properties
sudo groupadd sonar
sudo useradd -c "Sonar System User" -d /opt/sonarqube -g sonar -s /bin/bash sonar
sudo chown -R sonar:sonar /opt/sonarqube-$VERSION
sudo sed -i 's/#RUN_AS_USER=/RUN_AS_USER=sonar/g' /opt/sonarqube/bin/linux-x86-64/sonar.sh
sudo sysctl -w vm.max_map_count=262144
Configure the service:
cat > /tmp/sonar.service << EOF
[Unit]
Description=SonarQube Server
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
[Install]
WantedBy=multi-user.target
EOF
sudo mv /tmp/sonar.service /etc/systemd/system/
sudo chown root:root /etc/systemd/system/sonar.service
sudo systemctl enable sonar.service
sudo systemctl start sonar.service
Install [[linux:install:webserver|NGINX web server]]
Configure NGINX to proxy web traffic to SonarQube:
cat > /tmp/sonar-proxy<< EOF
server {
listen 80;
location / {
proxy_pass http://127.0.0.1:9000;
}
}
EOF
sudo mv /tmp/sonar-proxy /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/sonar-proxy /etc/nginx/sites-enabled/sonar-proxy
sudo service nginx reload
SonarQube is now installed and configured. Open a web browser and navigate to the URL. Click on the Log In button and provide the default administrator account username and password as **admin/admin** and click on the Log In button. You should see the SonarQube default dashboard.
====== ======
----
\\
Last Updated: January 28, 2019