Hi, habrozhiteli!
In this guide I want to set out a step-by-step setup for deploying a platform for continuous analysis and measurement of code quality. There are a lot of similar articles on the network, but I want to highlight only the main thing so that all newcomers can deal with it the first time.
You already learned the wiki, right?
And before we get started
I want you to decide which version to implement, because with each update more and more plugins become paid, which, of course, will affect financial costs or functionality.
In general - follow this link and see for yourself: plugin version matrix
According to the documentation, it is recommended to keep the server and database on different machines.
But in the sandbox you can also train on one.
So. I work with virtual machines. Prepared 2 pieces, or rather raised one and made a duplicate of it.
Ubuntu server 18.04.3 LTS was at my fingertips.
You can change the name and ip easily and simply using these commands:
::: change hostname :::
$ hostnamectl set-hostname sonarapp sudo nano /etc/hostname sudo nano /etc/hosts
::: change ip ubuntu :::
sudo nano /etc/netplan/01-eth0.yaml
There, find the familiar lines and change the parameters of the machine name and IP address.
And what should happen:
Sonar app server [SonarApp]
user: admin
IP: 192.168.0.15
Platform: Ubuntu server 18.04.3 LTS [8 cores, 16GB of RAM, 20Gb + 50Gb (/ opt) disk space]
Sonar database [SonarDB]
user: admin
IP: 192.168.0.16
Platform: Ubuntu server 18.04.3 LTS [8 cores, 16GB of RAM, 20Gb + 100Gb disk space]
Directly start work.
We go to the first wheelbarrow - 192.168.0.15 (SonarApp) NOT under root, but under our own admin account. Those lines that begin with the $ character are terminal input, and the rest is what we’ll edit in the files or what should be received on the output (information output)
- need java. Take OpenJDK
::: Install open-jdk11 :::
$ sudo apt-get install openjdk-11-jdk
::: change java PATH :::
$ nano ~/.bash_profile export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/bin/java export PATH=/usr/lib/jvm/java-11-openjdk-amd64/bin:$PATH
::: Download and configure SonarQube :::
Download the SonarQube installer files archive.
$ wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.9.1.zip
Install unzip by running:
# apt-get -y install unzip
Unzip the archive using the following command
$ sudo unzip sonarqube-7.9.1.zip -d /opt
Rename the directory
$ sudo mv /opt/sonarqube-7.9.1 /opt/sonarqube
Add Sonar User and Privileges
Create a user named sonar and make it the owner of the /opt/sonarqubedirectory
$ sudo adduser sonar $ sudo passwd sonar $ sudo chown -R sonar:sonar /opt/sonarqube
Continuation configure SonarQube
$ sudo nano /opt/sonarqube/conf/sonar.properties sonar.web.host=192.168.0.15 sonar.jdbc.username=sonar sonar.jdbc.password=sonar # sonar.jdbc.url=jdbc:postgresql://localhost/username sonar.jdbc.url=jdbc:postgresql://192.168.0.16/sonar sonar.web.javaAdditionalOpts=-server
Create a file /etc/systemd/system/sonarqube.service
and past the following content on to the file
[Unit] Description=SonarQube service After=syslog.target network.target [Service] Type=simple User=sonar Group=sonar PermissionsStartOnly=true ExecStart=/bin/nohup java -Xms32m -Xmx32m -Djava.net.preferIPv4Stack=true -jar /opt/sonarqube/lib/sonar-application-7.9.1.jar StandardOutput=syslog LimitNOFILE=65536 LimitNPROC=8192 TimeoutStartSec=5 Restart=always [Install] WantedBy=multi-user.target
Start and enable sonarqube
$ sudo systemctl start sonarqube $ sudo systemctl enable sonarqube
To check if the service is running, run:
$ sudo systemctl status sonarqube
Log:
tail -f /opt/sonarqube/logs/sonar.log
Now connect to the second car
192.168.0.16 (SonarDB) under our good admin.
::: Installing the Database :::
Install the PostgreSQL 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' $ wget -q https://www.postgresql.org/media/keys/ACCC4CF8.asc -O - | sudo apt-key add -
Install the PostgreSQL database server by running:
$ sudo apt-get -y install postgresql postgresql-contrib
Start PostgreSQL server and enable it to start automatically at boot time by running:
$ sudo systemctl start postgresql $ sudo systemctl enable postgresql
Change the password for the default PostgreSQL user
$ sudo passwd postgres
Switch to the postgres user.
$ su - postgres
Switch to the PostgreSQL shell.
$ psql
::: Configure PostgreSQL :::
Set a password for the newly created user for SonarQube database.
CREATE ROLE sonar WITH PASSWORD 'sonar'; SELECT rolname FROM pg_roles; alter role sonar login; SELECT pg_reload_conf(); Create a new database for PostgreSQL database by running: create database sonar owner sonar;
Exit from the psql shell:
'\q'
::: Move Databases PostgreSQL :::
Stop PostgreSQL service
$ service postgresql stop # or $ /usr/lib/postgresql/10/bin/pg_ctl stop -D /var/lib/postgresql/10/main
Change data directory.
$ psql
# show data_directory; /var/lib/postgresql/10/main
$ sudo rsync -av /var/lib/postgresql /opt/sonardb $ sudo mv /var/lib/postgresql/*/main /var/lib/postgresql/*/main.bak $ sudo nano /etc/postgresql/*/main/postgresql.conf # change location for new data_directory. data_directory = '/opt/sonardb/postgresql/10/main' listen_addresses = '*'
Change check
$ sudo -u postgres psql
# show data_directory; ______________________ /opt/sonardb/postgresql/10/main # \q
And also need to check system parameters. They can be added to the /etc/sysctl.conf
file or entered in the terminal:
sysctl -w vm.max_map_count=262144 sysctl -w fs.file-max=65536 ulimit -n 65536 ulimit -u 4096
To check the availability of the database, connect to 192.168.0.15 and type:
$ psql -h 192.168.0.16 -p 5432 -U sonar
That's all. To make sure that everything works, go to the browser (make sure that the 192.168.XX network is accessible from yours or use links).
We’ll dial 192.168.0.15:9000 and you should be greeted with an authorization window.
Login: admin
Password: admin
This is the default admin account.