Setup SonarQube on Ubuntu 18.04
Reading Time:
Reading Time:
Source : https://docs.sonarqube.org/latest/requirements/requirements/
Current setup requires following tools
Create 'sonarqube' user on Ubuntu 18.04 and copy all root user ssh keys to sonarqube user account
adduser sonarqube
usermod -aG sudo sonarqube
rsync --archive --chown=sonarqube:sonarqube ~/.ssh /home/sonarqube
sudo apt install openjdk-8-jdk
We shall install sonarqube under /opt folder
su - sonarqube
sudo mkdir /opt/sonarqube
We shall download the latest SonarQube 7.7 version from this link
cd /opt/sonarqube
sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.7.zip
sudo apt-get install unzip
sudo unzip sonarqube-7.7.zip
sudo chown -R sonarqube:sonarqube /opt/sonarqube
Lets install Mysql 5.7 and set it up for Sonarqube
sudo apt install mysql-server
sudo mysql -u root -p
Create Mysql user and database for SonarQube
mysql> CREATE DATABASE sonarqube77;
mysql> CREATE USER sonarqube77@'localhost' IDENTIFIED BY 'tough_password';
mysql> GRANT ALL ON sonarqube77.* to sonarqube77@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
Edit the following file : /opt/sonarqube/sonarqube-7.7/conf/sonar.properties
Add Mysql Username and password to sonar.properties
Finally lets configure the JDBC url information for Mysql under Mysql section in sonar.properties file
We will be running sonarqube on localhost port 9011 and nginx running on https will be the proxy server that will redirect traffic to port 9011
Full sonar.properties on Github gist
Lets make Sonarqube a service using systemd
Create a file 'sonarqube.service' under directory '/etc/systemd/system'
[Unit]
Description=SonarQube v7-7 service
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/opt/sonarqube/sonarqube-7.7/bin/linux-x86-64/sonar.sh start
ExecStop=/opt/sonarqube/sonarqube-7.7/bin/linux-x86-64/sonar.sh stop
User=sonarqube
Group=sonarqube
Restart=always
[Install]
WantedBy=multi-user.target
Lets configure SonarQube to auto start on reboot
sudo systemctl enable sonarqube
Start SonarQube server
sudo service sonarqube start
sudo service sonarqube status
sudo apt install nginx
sudo ufw allow 'Nginx HTTP'
sudo ufw allow 'Nginx HTTPS'
To Action From
-- ------ ----
Nginx HTTP ALLOW Anywhere
Nginx HTTPS ALLOW Anywhere
22/tcp ALLOW Anywhere
Nginx HTTP (v6) ALLOW Anywhere (v6)
Nginx HTTPS (v6) ALLOW Anywhere (v6)
22/tcp (v6) ALLOW Anywhere (v6)
Create configuration called 'sonarqube' for sonarqube port 80 redirect
Create file '/etc/nginx/sites-enabled/sonarqube'
server {
listen 80;
server_name sonarqube.website.com;
location / {
proxy_pass http://127.0.0.1:9011;
}
}
Increase large file size upload capability to Nginx by adding the given property to '/etc/nginx/nginx.conf ' . Note : This property is important as the analysis report files will be uploaded from Jenkins to SonarQube and we need to make sure we don't get 'Nginx: 413 – Request Entity Too Large Error'
Add the following line to http or server or location context to increase the size limit in nginx.conf,
client_max_body_size 10M;
Test the configuration
sudo nginx -t
sudo service nginx restart
Lets test the URL , point your browser to http://sonarqube.website.com
The server is running on HTTP so lets enable HTTPS using Lets encrypt certificate
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx
Run certbot
sudo certbot --nginx -d sonarqube.website.com
Cerbot will ask a few questions , please answer those questions and choose rediect all http to https using option 2
Lets test the URL , point your browser to http://sonarqube.website.com , the url should get auto redirected to https://sonarqube.website.com
We have SonarQube 7.7 running on Ubuntu 18.04 with Mysql 5.7 and Nginx