Install SonarQube on ECS instance on Ubuntu 16.04

In this tutorial, you will install and configure SonarQube on an Alibaba Cloud ** Elastic Compute Service ** (ECS) instance using Ubuntu 16.04.

Need for SonarQube

SonarQube can statically analyze your code to discover security vulnerabilities, detect bugs, and review your code. Performs automatic reviews to show the health of your application. SonarQube features a Quality Gate that can highlight recently introduced errors and fix leaks. You can analyze pull requests to perform analysis on feature branches before being pushed to SonarQube. This way, you have the opportunity to fix the issue before it reaches SonarQube.

Branch analysis is done to ensure that the code is clean and approved for merging into the master. SonarQube allows you to delve into the problem so that you can analyze and find it in your code. SonarQube visualizes the history of your project and explores all execution paths.

In short, SonarQube helps maintain your code by detecting issues, security vulnerabilities, and code odors and providing the results in a report format. In order to use SonarQube, it is necessary to install the analysis engine application on the developer's personal computer and install a server that centrally manages reports and records. This allows server applications to be accessed from multiple developers' computers, allowing centralized code quality reporting.

In this tutorial, SonarQube is installed on an Alibaba Cloud Elastic Compute Service (ECS) instance using Ubuntu 16.04. Set.

Prerequisites

  1. You need to enable Alibaba Cloud Elastic Compute Service (ECS) and check the valid payment method. .. For new users, get a free account with your Alibaba Cloud account (https://account-intl.aliyun.com/register/intl_register.htm?spm=a2c65.11461447.0.0.44ec591fyZ0TTr&biz_params=%7B%22intl%22 % 3A% 22% 7B% 5C% 22referralCode% 5C% 22% 3A% 5C% 22ffxt3q% 5C% 22% 7D% 22% 7D). If you don't know how to set up an ECS instance, [this tutorial](https://www.alibabacloud.com/blog/3-ways-to-set-up-a-linux-server-on-alibaba-cloud_572384?spm See = a2c65.11461447.0.0.44ec591fyZ0TTr) or the Quick Start Guide (https://www.alibabacloud.com/help/doc-detail/25422.htm?spm=a2c65.11461447.0.0.44ec591fyZ0TTr). The ECS instance must have at least 2GB of RAM and a 1-core processor.
  2. [Domain name] registered from Alibaba Cloud (https://www.alibabacloud.com/domain?spm=a2c65.11461447.0.0.44ec591fyZ0TTr). If you have already registered your domain from Alibaba Cloud or another host, you can update its domain name server record.
  3. The domain name must point to your Alibaba Cloud ECS IP address.
  4. Access the SSH client installed on Alibaba Cloud's VNC console or PC.
  5. Set the host name of the server and create a user with root privileges. 6, Follow this tutorial, Apache, MySQL, Install PHP.

ECS server setup

Update Ubuntu system

Please update your Ubuntu system with the following command before proceeding with the package installation. Remember to log in with sudo privileges as a non-root user to run this command.

# sudo apt update && sudo apt upgrade

Install add-apt-repository

You need to add a repository to install the Oracle JDK. However, in order to add that repository, you need to install add-apt-repository to add the repository to the apt package. To do this, run the following command.

# sudo apt-get install -y software-properties-common

Java JDK installation

Now you need to set up your Java JDK environment. SonarQube requires the Oracle JDK. To install the Oracle JDK, follow these steps:

Step 1: Run the following command to add the required repositories to the apt repository.

# sudo add-apt-repository ppa:webupd8team/java

Step 2: Run the following command to update the apt repository.

# sudo apt-get update

Step 3: Proceed with the JDK installation. At the time of writing, SonarQube only supports JDK 8, so don't forget to use this version only. Do not use any other version for now.

# sudo apt install oracle-java8-installer

unzip installation

You need to install unzip because you need to unzip the SonarQube compressed zip folder. To install, run the command.

# sudo apt-get install unzip

Install PostgreSQL

SonarQube supports PostgreSQL, MySQL, MSSQL and Oracle. For this tutorial, MySQL is not recommended for large instances, so we will use PostgreSQL. If you use MySQL, you have no choice but to use the bundled mysql-connector-java. The InnoDB engine is required for MySQL. To avoid such restrictions, we strongly recommend using PostgreSQL. Follow the steps below to install PostgreSQL.

Step 1: Install PostgreSQL repo

# sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
# wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -

Step 2: Install the PostgreSQL server by running the following command

# sudo apt-get -y install postgresql postgresql-contrib

Step 3: Run the following command to start the PostgreSQL server so that it can start automatically after a reboot

# sudo systemctl start postgresql
# sudo systemctl enable postgresql

Create directory and set permissions

To install SonarQube for continuous code quality inspection, follow these steps:

Step 1: Create a directory named sonar. You can name the directory whatever you like, but the next step in installing SonarQube will require you to follow your own directory path.

# sudo mkdir /opt/sonar

Step 2: Now, give permissions to the username in the directory you created so that you can make changes. To do so, execute the following command. Don't forget to replace aareez with your username.

# sudo chown -R aareez:aareez /opt/sonar

Install SonarQube

Now that you have set up your server and installed your PostgreSQL database, let's install SonarQube. Follow these steps to download and install SonarQube.

Step 1: Navigate to the directory / opt / sonar that you created for SonarQube.

# cd /opt/sonar

Step 2: Now you need to download a copy of SonarQube from the official website. To do this, run the following command.

# sudo wget https://sonarsource.bintray.com/Distribution/sonarqube/sonarqube-7.2.1.zip 

Step 3: You can now see the CLI compressed zip folder by running the command.

# ls -li

image.png

Unzip the compressed folder and unzip the file. To do this, run the following command.

# sudo unzip sonarqube-7.2.1.zip

Database creation and configuration

Follow the steps below to create and configure the database.

Step 1: Change the password for the postgres user and switch to the postgres user. To change the password, run the following command.

# sudo passwd postgres

Run the following command to switch to the postgres user.

# su - postgres

Step 2: Run the following command to create a new user.

# createuser sqube

Step 3: Now open the Postgres shell to execute the query. To open it, run the command.

# psql

Step 4: Run the following query. The first query creates the user's password, the second query creates the database, assigns database privileges to the user, and the third query terminates the MySQL server.

ALTER USER sqube WITH ENCRYPTED password '654321Ab'.
CREATE DATABASE sqube OWNER sqube.
\q

Step 5: Run the following command to return to the sudo user.

# exit

SonarQube settings

To get started with SonarQube, you need to make some basic settings such as database settings and running in server mode.

Open the sonar.properties file, set the database username and password, and describe the driver SonarQube uses to connect to the database. Run the following command to open the file.

# cd /opt/sonar
# sudo nano sonarquebe-7.2.1/conf/sonar.properties

The above command will open the document. The following area is displayed. Remove # from the beginning of both lines and write the MySQL user name and password that you set when you created the database.

image.png

Find the part of sonar.jdbc.url below and remove the # to uncomment it. This will cause SonarQube to use PostgreSQL, and Sonar will need to be changed with the database name sqube.

image.png

Find sonar.web.host here, remove the # and uncomment this line and change the IP to 127.0.0.0.1.

image.png

Find sonar.web.javaAdditionalOpts here, remove the #, uncomment the line and change the value to -server.

image.png

After making changes, press Ctrl + X, type Y, and press Enter to save your settings.

SonarQube reverse proxy settings

SonarQube listens on localhost port 9000 by default. A reverse proxy must be configured to access over the standard HTTP 80 port.

Follow the procedure below to make the settings.

Step 1: Run the command to enable proxy mode.

# sudo a2enmod proxy
# sudo a2enmod proxy_http

Step 2: Proceed to virtual host configuration Run the following command to proceed with the virtual host creation.

# sudo nano /etc/apache2/sites-available/softpedia.xyz.conf

Step 3: Add the following text to the opened file, press Ctrl + X, type Y and press Enter to save the file.



ProxyRequests Off
ProxyPreserveHost On
<VirtualHost *:80>
    ServerName www.softpedia.xyz
    ServerAdmin [email protected]
    ProxyPreserveHost On
    ProxyPass / http://localhost:9000/
    ProxyPassReverse / http://www.softpedia.xyz/

</VirtualHost>

Step 4: You need to enable the newly created virtual host and then start and enable the apache server. To do this, run the command.

# sudo a2ensite softpedia.xyz.conf
# sudo systemctl start apache2
# sudo systemctl enable apache2

Step 5: Add a non-root user named sonar.

# sudo adduser sonar

Assign sonar user privileges to the directory / opt / sonar.

# sudo chown -R sonar:sonar /opt/sonar

Now open the bash file to assign run_as_user.

# sudo nano /opt/sonar/sonarquebe-7.2.1/bin/linux-x86-64/sonar.sh

Find RUN_AS_USER in the open file, remove the # sign, uncomment it, and add the value as sonar.

image.png

To start SonarQube, run the following command.

# opt/sonar/sonarqube-7.2.1/bin/linux-x86-64/sonar.sh start

To start SonarQube, run the following command.

# /opt/sonar/sonarqube-7.2.1/bin/linux-x86-64/sonar.sh stop

Sorry I made you wait. This completes SonarQube installation and configuration. Easy to access using your domain name. In my case I am using www.softpedia.xyz.

image.png

Recommended Posts

Install SonarQube on ECS instance on Ubuntu 16.04
Install Ruby on Ubuntu 20.04
Install Homebrew on Ubuntu 20.04
Install OpenJDK7 (JAVA) on ubuntu 14.04
Install Cybozu Office 10 on Ubuntu 20.4
Install Docker on Ubuntu Server 20.04
Install zabbix agent (5.0) on Ubuntu 18.04
Install MAV Proxy on Ubuntu 18.04
Install Java on WSL Ubuntu 18.04
Install Ubuntu Desktop 20.10 on RaspberryPi4
Install Arduino IDE on Ubuntu 20.04
Install raspi-config on Ubuntu 20.04 (LTS)
Install PlantUML on Intellij on Ubuntu
Install Ubuntu Server 20.04 on Btrfs
Note: Install PostgreSQL 9.5 on Ubuntu 18.04
Install AWS IoT Greengrass on Ubuntu
Install JDK and JRE on Ubuntu 16.10
Install ngrok on ubuntu16.04 using Vagrant
Continuous integration on Alibaba Cloud ECS Ubuntu instance with Jenkins
How to install WildFly on Ubuntu 18.04
Install ruby on Ubuntu 20.04 with rbenv
Headless install of Ubuntu 20.10 on Raspberry Pi
Install OpenJDK (Java) on the latest Ubuntu
I want to install PHP 7.2 on Ubuntu 20.04.
Install Realtek network driver on Ubuntu Note
tmux on Ubuntu
Wine settings on Ubuntu 18.04 (install WOLF RPG Editor)
Install NextCloud on CentOS 7 with Alibaba Cloud ECS
Build and install Wireshark Development Release (3.3.1) on Ubuntu
How to install network drivers on standalone Ubuntu
How to install NVIDIA driver on Ubuntu 18.04 (Note)
Install SonarQube on Mac and challenge source analysis
How to install multiple JDKs on Ubuntu 18.04 LTS
Install and switch between multiple Javas on Ubuntu
Install the latest version of Jenkins on Ubuntu 16
Screen recording on Ubuntu 20.04
Web Bluetooth on Ubuntu20.04
Install gradle on mac
Install docker-compose on a Graviton 2 instance of AWS EC2
How to install Ruby on an EC2 instance on AWS
Install Corretto 8 on Windows
Install OpenJDK on macOS
Try DisplayLink on Ubuntu 20.04
Reinstall Kubernetes on Ubuntu 19.10
Install Java on Mac
Install Golang on CentOS 8
Use Flutter on Ubuntu
Install Neo4j 4.1.3 on centOS
Install ROS Noetic ubuntu20.04
Install Docker on Manjaro
How to install NVIDIA driver on Ubuntu ssh destination
Install Gradle with ubuntu16.04
Install PostgreSQL 12 on Centos8
Install nginx on centOS7
Install lombok on SpringToolSuite4
Install kuromoji on CentOS7
Setting JAVA_HOME on Ubuntu
Put JetBrains on Ubuntu
Install Mattermost on CentOS 7
Install PostGIS 2.5.5 on CentOS7
Use mkdir on ubuntu