본문 바로가기

Security/SonarQube

Install SonarQube

Instance components

SonarQube instance components

  • The SonarQube server running processes
    • a web server that servers the SonarQube user interface.
    • a search server based on Elasticsearch
    • the compute engine in charge of processing code analysis reports and saving them in the SonarQube database.
  • The database to store the following
    • Metrics and issues for code quality and security generated during code scans.
    • The SonarQube instance configuration

Prerequisite

Hardware Requirements

  • A small-scale
    • RAM: 2GB
  • Enterprise scale
    • Core: 8Core
    • RAM: 16GB

Supported Platforms

  • Java: OpenJDK 11
  • Database: PostgreSQL 13

https://docs.sonarqube.org/latest/requirements/requirements/

 

Prerequisites and Overview | SonarQube Docs

You must be able to install Java (Oracle JRE or OpenJDK) on the machine where you plan to run SonarQube. A small-scale (individual or small team) instance of the SonarQube server requires at least 2GB of RAM to run efficiently and 1GB of free RAM for the O

docs.sonarqube.org


Installing the databse

https://www.postgresql.org/download/linux/ubuntu/

 

PostgreSQL: Linux downloads (Ubuntu)

Linux downloads (Ubuntu) PostgreSQL is available in all Ubuntu versions by default. However, Ubuntu "snapshots" a specific version of PostgreSQL that is then supported throughout the lifetime of that Ubuntu version. Other versions of PostgreSQL are availab

www.postgresql.org

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 --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql
sudo apt intall postgresql-contrib

Check PostgreSQL status

ubuntu@dintvmsonar01:~$ service postgresql status
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: active (exited) since Thu 2022-05-05 05:39:40 UTC; 2min 42s ago
   Main PID: 57997 (code=exited, status=0/SUCCESS)
      Tasks: 0 (limit: 19175)
     Memory: 0B
     CGroup: /system.slice/postgresql.service

May 05 05:39:40 dintvmsonar01 systemd[1]: Starting PostgreSQL RDBMS...
May 05 05:39:40 dintvmsonar01 systemd[1]: Finished PostgreSQL RDBMS.

Start Using PostgreSQL Connand LIne Tool

  • Check the details of the connection by typing \conninfo
  • database "postgres" as user "postgres"
ubuntu@dintvmsonar01:~$ sudo -u postgres psql
psql (14.2 (Ubuntu 14.2-1.pgdg20.04+1+b1))
Type "help" for help.

postgres=# \conninfo
You are connected to database "postgres" as user "postgres" via socket in "/var/run/postgresql" at port "5432".
postgres=#
  • Check a list of all the databases that are available on a server
postgres=# \l
                              List of databases
   Name    |  Owner   | Encoding | Collate |  Ctype  |   Access privileges
-----------+----------+----------+---------+---------+-----------------------
 postgres  | postgres | UTF8     | C.UTF-8 | C.UTF-8 |
 template0 | postgres | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
           |          |          |         |         | postgres=CTc/postgres
 template1 | postgres | UTF8     | C.UTF-8 | C.UTF-8 | =c/postgres          +
           |          |          |         |         | postgres=CTc/postgres
(3 rows)
  • Check a list of all the users with their privileges
postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

postgres=#
  • Set the default "postgres" user password
postgres=# \password postgres
Enter new password for user "postgres":
Enter it again:
postgres=#

Setup PostgreSQL server

  • su - postgres
  • vi /etc/postgresql/14/main/postgresql.conf
listen_addresses = '*'                  # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
  • vi /etc/postgresql/14/main/pg_hba.conf
# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            scram-sha-256
# IPv6 local connections:
host    all             all             ::1/128                 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            scram-sha-256
host    replication     all             ::1/128                 scram-sha-256
host    all             all             0.0.0.0/0               md5
  • systemctl restart postgresql
ubuntu@dintvmsonar01:~$ sudo su
root@dintvmsonar01:/home/ubuntu# systemctl restart postgresql
  • check the listening port
root@dintvmsonar01:/home/ubuntu# ss -nlt | grep 5432
LISTEN   0        244              0.0.0.0:5432          0.0.0.0:*
LISTEN   0        244                 [::]:5432             [::]:*

Moving a PostgreSQL data directory to a new location

Step1 - Moving the PostgreSQL Data Directory

  • Verifying the current location. This output confirms that PostgreSQL is configured to use the default data directory, /var/lib/postgresql/14/main.
  • This is the directory we need to move.
ubuntu@dintvmsonar01:~$ sudo -u postgres psql
psql (14.2 (Ubuntu 14.2-1.pgdg20.04+1+b1))
Type "help" for help.

postgres=# show data_directory;
       data_directory
-----------------------------
 /var/lib/postgresql/14/main
(1 row)

postgres=#
  • shut down PostgreSQL before we actually make changes to the data directory
  • confirm it's shut down if the final line of the output tells you the server is stopped
ubuntu@dintvmsonar01:~$ sudo systemctl stop postgresql
ubuntu@dintvmsonar01:~$ sudo systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Fri 2022-05-06 02:07:35 UTC; 16s ago
    Process: 948 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 948 (code=exited, status=0/SUCCESS)

May 05 16:20:48 dintvmsonar01 systemd[1]: Starting PostgreSQL RDBMS...
May 05 16:20:48 dintvmsonar01 systemd[1]: Finished PostgreSQL RDBMS.
May 06 02:07:35 dintvmsonar01 systemd[1]: postgresql.service: Succeeded.
May 06 02:07:35 dintvmsonar01 systemd[1]: Stopped PostgreSQL RDBMS.
  • Make a directory which PostgreSQL data directory is moved in
root@dintvmsonar01:/# cd /data/
root@dintvmsonar01:/data# ll
total 24
drwxr-xr-x  3 root root  4096 May  5 02:49 ./
drwxr-xr-x 20 root root  4096 May  5 16:20 ../
drwx------  2 root root 16384 May  5 02:49 lost+found/
root@dintvmsonar01:/data# mkdir -p postgresql/14/main
root@dintvmsonar01:/data# chown -R postgres:postgres postgresql/
  • starting rsync from the postgresql directory in order to mimic the original directory sturucture in our new location
ubuntu@dintvmsonar01:~$ sudo rsync -av /var/lib/postgresql/ /data/volume-nyc1-01
  • Renaming the current folder with a.bak extension and keep it until we've confirmed the move was successful.
ubuntu@dintvmsonar01:~$ sudo mv /var/lib/postgresql/14/main/ /var/lib/postgresql/14/main.bak

Step 2 - Pointing to the new data location

  • Edit the file in the /etc/postgresql/14/main/postgresql.conf to reflect the new data directory
data_directory = '/data/volume-nyc1-01/14/main'         # use data in another directory
  • Start PostgreSQL
ubuntu@dintvmsonar01:~$ sudo systemctl start postgresql
ubuntu@dintvmsonar01:~$ sudo systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: active (exited) since Fri 2022-05-06 02:51:51 UTC; 23s ago
    Process: 36897 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 36897 (code=exited, status=0/SUCCESS)

May 06 02:51:51 dintvmsonar01 systemd[1]: Starting PostgreSQL RDBMS...
May 06 02:51:51 dintvmsonar01 systemd[1]: Finished PostgreSQL RDBMS.
  • Look at the value for the data directory again
postgres=# show data_directory;
        data_directory
------------------------------
 /data/volume-nyc1-01/14/main
(1 row)
  • Remove the backup data directory
root@dintvmsonar01:~# sudo rm -Rf /var/lib/postgresql/14/main.bak/
  • Restart PostgreSQL on final time to be sure that is works as expected.
ubuntu@dintvmsonar01:~$ sudo systemctl restart postgresql
ubuntu@dintvmsonar01:~$ sudo systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
     Active: active (exited) since Fri 2022-05-06 02:56:39 UTC; 8s ago
    Process: 38952 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 38952 (code=exited, status=0/SUCCESS)

May 06 02:56:39 dintvmsonar01 systemd[1]: Starting PostgreSQL RDBMS...
May 06 02:56:39 dintvmsonar01 systemd[1]: Finished PostgreSQL RDBMS.

Ref

For installation PostgreSQL

https://www.postgresql.org/download/linux/ubuntu/

 

PostgreSQL: Linux downloads (Ubuntu)

Linux downloads (Ubuntu) PostgreSQL is available in all Ubuntu versions by default. However, Ubuntu "snapshots" a specific version of PostgreSQL that is then supported throughout the lifetime of that Ubuntu version. Other versions of PostgreSQL are availab

www.postgresql.org

https://www.enterprisedb.com/downloads/postgres-postgresql-downloads

 

Download PostgreSQL

PostgreSQL Database Download

www.enterprisedb.com

https://www.cherryservers.com/blog/how-to-install-and-setup-postgresql-server-on-ubuntu-20-04

 

How to Install and Setup PostgreSQL server on Ubuntu 20.04 - Cherry Servers

#Introduction PostgreSQL is a fully featured database management system (DBMS) with a strong emphasis on extensibility and SQL compliance. It is backed by 20 years of open-source development, and supports both SQL (relational) and JSON (non-relational) que

www.cherryservers.com

For PostgreSQL data directory migration

https://www.digitalocean.com/community/tutorials/how-to-move-a-postgresql-data-directory-to-a-new-location-on-ubuntu-16-04

 

How To Move a PostgreSQL Data Directory to a New Location on Ubuntu 16.04 | DigitalOcean

 

www.digitalocean.com

 

'Security > SonarQube' 카테고리의 다른 글

Integration with jenkins  (0) 2022.05.09
Install SonarQube#2  (0) 2022.05.06