Category Archives: Database

How to install PostgreSQL 15 Beta on Ubuntu 22.04

In this guide, we are going to walk through installing PostgreSQL 15 Beta on Ubuntu 22.04.

PostgreSQL is a powerful, open-source object-relational database system that uses and extends the SQL language combined with many features that safely store and scale the most complicated data workloads. It was designed to handle a range of workloads from single machines to data warehousing.

Every single database must conform to ACID properties i.e Atomicity, Consistency, Isolation, and Durability. This is true for PostgreSQL as well, it must conform to those features for transactions to pass the tests.

1. Update the Ubuntu repository

The first thing to do is to update the ubuntu repository in order to make them up to date.

$ sudo apt update && apt upgrade -y

2. Install PostgreSQL 15 on Ubuntu 22.04

In order to run PostgreSQL 15 on Ubuntu 22.04, we are supposed to add 15 component to /etc/apt/sources.list.d/pgdg.list entry so that version 15 will be available for installation.

In order to add 15 to sources.list file, use the following command.

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main 15" > /etc/apt/sources.list.d/pgdg.list'

Next, we need to import the repository signing key.

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

The next thing is to update the system again for the changes to take effect.

sudo apt update 

Lastly, install PostgreSQL with the following command.

apt-get install postgresql-15

You will get the following as the output

The following additional packages will be installed:
  libcommon-sense-perl libjson-perl libjson-xs-perl libllvm14 libpq5
  libtypes-serialiser-perl pgdg-keyring postgresql-client-15
  postgresql-client-common postgresql-common ssl-cert
Suggested packages:
  postgresql-doc-15
The following NEW packages will be installed:
  libcommon-sense-perl libjson-perl libjson-xs-perl libllvm14 libpq5
  libtypes-serialiser-perl pgdg-keyring postgresql-15 postgresql-client-15
  postgresql-client-common postgresql-common ssl-cert
0 upgraded, 12 newly installed, 0 to remove and 9 not upgraded.
Need to get 44.1 MB of archives.
After this operation, 176 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

3. Setting up password for Postgres role

Local connections on Posgtresql use peer to check the authenticated users. That is Postgresql instead of asking for the user password, it only checks on the logged-in user to ascertain if the user has credentials to get access to the resources.

Let’s change the way we log in and use a more strong password instead. Let’s set the password for the Postgres user first.

Open psql as the Postgres user with this command sudo -u postgres psql

$ sudo -u postgres psql

You will get output like this.

could not change directory to "/root": Permission denied
psql (15beta3 (Ubuntu 15~beta3-1.pgdg22.04+1))
Type "help" for help.

postgres=# 

The reason we are getting could not change directory to "/root": Permission denied psql is because of the Postgres authentication, we need to set the password first.

To change the Postgres password use the following command inside of the Postgres interface.

postgres=# ALTER USER POSTGRES WITH ENCRYPTED PASSWORD 'strgpasswd';

After we have set the password, we now need to tell Postgres to use this password. To do that we need to change pg_hba.conf file. I am using vim as my text editor here, you are free to use your preferred editor as well.

Look for this line of code and change peer to md5

local  all  postgres  peer
local  all  postgres  md5

To edit the configuration file use the following command.

sudo vi /etc/postgresql/15/main/pg_hba.conf

Restart PostgreSQL for the changes to take effect.

sudo systemctl restart postgresql

We can also ascertain whether PostgreSQL is running on our system with the following command.

sudo systemctl status postgresql

If you get the status active then we are good to go.

 ● postgresql.service - PostgreSQL RDBMS
     Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor pr>
     Active: active (exited) since Fri 2022-08-12 06:48:04 UTC; 1min 57s ago
    Process: 25558 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
   Main PID: 25558 (code=exited, status=0/SUCCESS)
        CPU: 2ms

Aug 12 06:48:04 localhost systemd[1]: Starting PostgreSQL RDBMS...
Aug 12 06:48:04 localhost systemd[1]: Finished PostgreSQL RDBMS.
lines 1-9/9 (END)

After this, we can log in again to the Postgres

psql -U postgres
psql (15beta3 (Ubuntu 15~beta3-1.pgdg22.04+1))
Type "help" for help.

postgres=# 

We have successfully changed Postgres to use password authentication.

Conclusion

Congratulations, we have successfully installed PostgreSQL 15 on Ubuntu 22.04 and also set the password for the default user Postgres. For more information get the latest from PostgreSQL documentation.

For user disclaimer, this is the beta version so it’s not suitable to use in production because it’s still very unstable.

How to install Redis on Ubuntu 22.04

Welcome to this tutorial where we will learn how to install the Redis server o Ubuntu 22.04.

Redis server is an open source in-memory data store used by many developers as a database, cache, streaming engine, and message broker.

Redis as a real-time data store means Redis’ versatile in-memory data structures let you build data infrastructure for real-time applications requiring low latency and high throughput

Caching and session storage. Redis speed is ideal for caching database queries, complex computations, API calls, and session states.

Streaming and messaging. Streamed data type enables high-speed data ingestion, messaging, event sourcing, and notifications.

Install Redis on Ubuntu 22.04

1. Update system repositories

Before we begin the installation, we need to update our system repositories in order to make system repositories up to date.

$ sudo apt update && apt upgrade -y

2. Add Redis to the apt repository

To install the stable version of Redis we need to install it from the official Redis packages and to do so we need to add an apt repository .

$ curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

Add the downloaded package to the repository by using echo.

$ echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

What follows is to update the system repositories once more for the changes to take effect.

sudo apt update

Lastly is to install Redis with the following command.

sudo apt install redis 

You should get the output something like this.

The following additional packages will be installed:
  redis-server redis-tools
Suggested packages:
  ruby-redis
The following NEW packages will be installed:
  redis redis-server redis-tools
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 1642 kB of archives.
After this operation, 9437 kB of additional disk space will be used.
Do you want to continue? [Y/n] 

3. Testing Redis

If your installation was successful, you can test Redis with the following command.

sudo systemctl status redis-server 

You must see the following output.

● redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; disabled; vendor>
     Active: active (running) since Tue 2022-07-26 07:41:00 UTC; 7min ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
   Main PID: 24426 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 1033)
     Memory: 2.8M
        CPU: 385ms
     CGroup: /system.slice/redis-server.service
             └─24426 "/usr/bin/redis-server 127.0.0.1:6379" "" "" "" "" "" "" ""

Jul 26 07:41:00 localhost systemd[1]: Starting Advanced key-value store...
Jul 26 07:41:00 localhost systemd[1]: Started Advanced key-value store.
lines 1-15/15 (END)

We can also leverage Redis-cli whenever we want to test whether Redis is working correctly. To use Redis-cli use the following command to ping the connection.

$ redis-cli

root@localhost:~# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> 

To know that Redis is establishing communication, you will get an output as pong

4. Configuring Redis

By default Redis is accessible from the localhost. it doesn’t allow remote connections. So to enable Redis to accept remote connections, we need to edit the following configuration file.

$ sudo vi /etc/redis/redis.conf

Check the line that begins with bind 127.0.0.1 : : 1 and uncomment it.

bind 127.0.0.1 ::1

Save and exit and make sure you restart the Redis server again for the changes to take effect.

sudo systemctl restart redis-server

To check that the service has actually taken effect, let’s test it with the netstat command

$ sudo netstat -lnp | grep redis

If you find an error that netstat is not installed you can do an install with the following command.

sudo apt install net-tools 

You will see the output like this.

tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      24735/redis-server  
tcp6       0      0 ::1:6379                :::*                    LISTEN      24735/redis-server 

5. Securing Redis

By default, Redis binds to all interfaces and has no authentication systems in place. To make Redis more secure, use the following steps to harden your Redis.

  • Make sure the port Redis uses to listen for connections (by default 6379 and additionally 16379 if you run Redis in cluster mode, plus 26379 for Sentinel) is firewalled so that it is not possible to contact Redis from the outside world.
  • Use the requirepass option in order to add an additional layer of security so that clients will require to authenticate using the AUTH command.
  • Use a configuration file where the bind directive is set in order to guarantee that Redis listens on only the network interfaces you are using.

In Redis password is configured directly by changing the following configuration file.

$ sudo vi /etc/redis/redis.conf

Scroll down to the security section and change the following and uncomment it and place a very strong password

# requirepass foobared

Save the file and exit and make sure you restart the Redis server again.

sudo systemctl restart redis-server

Conclusion

Congratulations, you have installed and configured the Redis server accordingly. For more information, check its rich documentation.

How to install Apache Cassandra 4 on Ubuntu 22.04

In this tutorial, we are going to explore how to install Apache Cassandra 4 on our Ubuntu 22.04 server. Apache Cassandra is an open-source, free, NoSQL database used to store large data. Its linear scalability and proven fault tolerance on commodity hardware or cloud infrastructure make it the perfect platform for mission-critical data.

NoSQL databases are lightweight, open-source, non-relational, and largely distributed. It has the following strengths:

  • It has horizontal scalability. Cassandra allows for the seamless addition of nodes. A node represents an instance of Cassandra. These nodes do communicate with each other through a protocol called gossip. Gossip is a peer-to-peer communication protocol in which nodes periodically exchange communication about themselves and other nodes they know about.
  • It contains distributed architecture. Distributed means that Cassandra can run on multiple machines while appearing to users as a unified whole. Cassandra databases easily scale when an application is under stress, this prevents data loss from any given data center’s hardware failure.
  • It has a flexible approach to the schema definition. A schema once defined its columns for a table while inserting data in every row, all columns must at least be filled with null value but for Cassandra column families are defined the columns are not. You can add any column to any column family at any time.

Apache Cassandra is suitable for high-volume data types. With the advent of Big data, Cassandra has become the solution to issues that SQL databases were not able to solve.

Install Cassandra 4 on Ubuntu 22.04

1. Run system updates

Before beginning the installation of Cassandra 4, update your system repositories in order to make them up to date.

sudo apt update && apt upgrade -y

2. Install Java

Ensure java 8 or above is installed because Cassandra depends on Java to run. So let us check if we have java in our system with the following command on our terminal.

$ java version

You should the following output if Java is not installed.

Command 'java' not found, but can be installed with:
apt install openjdk-11-jre-headless  # version 11.0.15+10-0ubuntu0.22.04.1, or
apt install default-jre              # version 2:1.11-72build2
apt install openjdk-17-jre-headless  # version 17.0.3+7-0ubuntu0.22.04.1
apt install openjdk-18-jre-headless  # version 18~36ea-1
apt install openjdk-8-jre-headless   # version 8u312-b07-0ubuntu1

If Java 8 is not installed in your system, Let’s go ahead and install it. The following command can install Java 8 on your system.

$ sudo apt install openjdk-8-jre-headless

It will start installing many dependencies as you can from the output shown below

#output
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  ca-certificates-java fontconfig-config fonts-dejavu-core java-common
  libavahi-client3 libavahi-common-data libavahi-common3 libcups2
  libfontconfig1 libjpeg-turbo8 libjpeg8 liblcms2-2 libpcsclite1 libxi6
  libxrender1 libxtst6 x11-common
Suggested packages:
  default-jre cups-common liblcms2-utils pcscd libnss-mdns fonts-dejavu-extra
  fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei
  fonts-wqy-zenhei fonts-indic
The following NEW packages will be installed:
  ca-certificates-java fontconfig-config fonts-dejavu-core java-common
  libavahi-client3 libavahi-common-data libavahi-common3 libcups2
  libfontconfig1 libjpeg-turbo8 libjpeg8 liblcms2-2 libpcsclite1 libxi6
  libxrender1 libxtst6 openjdk-8-jre-headless x11-common
0 upgraded, 18 newly installed, 0 to remove and 0 not upgraded.
Need to get 32.7 MB of archives.
After this operation, 110 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

Now we can check if Java 8 was installed successfully installed.

$ java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-8u312-b07-0ubuntu1-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)

3. Install Apache Cassandra.

To ensure packages are accessible via HTTPS, the apt-transport-HTTPS Package should be installed. This APT transport allows the use of repositories accessed via HTTP Secure protocol. Use the following command to do so

$ sudo apt install apt-transport-https

From the output below apt-transport-HTTPS is there by default.

4. Add Public GPG key for Apache Cassandra

To communicate with other protocols you must exchange public keys. Add the Apache Cassandra repository keys to the list of trusted keys on the server:

$ wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -

We can now go ahead and add Cassandra’s repository to Cassandra.sources.list files with the following command. You will realize we are using 40x. This is a corresponding distribution name.

$ sudo sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 40x main" > /etc/apt/sources.list.d/cassandra.list'

Before we can install Apache Cassandra, run an update to update all the repositories first.

$ sudo apt update
$ sudo apt install cassandra

You should in a position to see the following output.

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  cassandra-tools
The following NEW packages will be installed:
  cassandra
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 47.5 MB of archives.
After this operation, 58.8 MB of additional disk space will be used.
Get:1 https://downloads.apache.org/cassandra/debian 40x/main amd64 cassandra all 4.0.4 [47.5 MB]
Fetched 47.5 MB in 4s (13.3 MB/s)    
Selecting previously unselected package cassandra.
(Reading database ... 73903 files and directories currently installed.)
Preparing to unpack .../cassandra_4.0.4_all.deb ...
Unpacking cassandra (4.0.4) ...
Setting up cassandra (4.0.4) ...
Adding group `cassandra' (GID 117) ...
Done.

Monitor the progress of Cassandras startup with the following command.

tail -f logs/system.log

Cassandra is ready when you see the following output.

You can also check the status of Cassandra with the following command.

$ sudo systemctl status cassandra
● cassandra.service - LSB: distributed storage system for structured data
     Loaded: loaded (/etc/init.d/cassandra; generated)
     Active: active (running) since Thu 2022-07-07 09:33:52 UTC; 3min 12s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 5294 ExecStart=/etc/init.d/cassandra start (code=exited, status=0/>
      Tasks: 44 (limit: 1033)
     Memory: 714.0M
        CPU: 21.527s
     CGroup: /system.slice/cassandra.service
             └─5405 /usr/bin/java -ea -da:net.openhft... -XX:+UseThreadPrioriti>

Jul 07 09:33:52 localhost systemd[1]: Starting LSB: distributed storage system >
Jul 07 09:33:52 localhost systemd[1]: Started LSB: distributed storage system f>
lines 1-13/13 (END)

The status bar should show UN meaning Up and Normal.

Connect to the database with the following command:

$ cqlsh
Connected to Test Cluster at 127.0.0.1:9042
[cqlsh 6.0.0 | Cassandra 4.0.4 | CQL spec 3.4.5 | Native protocol v5]
Use HELP for help.
cqlsh> 

You can read more on these related articles

How to install MariaDB 10 on OpenSuse 15.4

In this guide we are going to install MariaDB 10 on Opensuse, but first what is MariaDB?

MariaDB Server is one of the most popular open-source relational databases. It’s made by the original developers of MySQL and guaranteed to stay open source. It is part of most cloud offerings and the default in most Linux distributions.

It is built upon the values of performance, stability, and openness, and MariaDB Foundation ensures contributions will be accepted on technical merit. Recent new functionality includes advanced clustering with Galera Cluster 4compatibility features with Oracle Database and Temporal Data Tables, allowing one to query the data as it stood at any point in the past.

Install MariaDB on OpenSuse 15.4

1. Update system repositories

To begin the installation, lets first update the repositories in order to make them up to date.

$ sudo zypper ref
$ sudo zypper update -y

2. Install MariaDB 10 on OpenSuse 15.4

To install MariaDB, we are going to configure zypper so that we can use to make the installation. Use the following command to add MariaDB to zypper.

sudo zypper addrepo --gpgcheck --refresh https://yum.mariadb.org/10.6/sles/15/x86_64 mariadb

Import Keys to sign the MariaDB on OpenSuse repositories.

sudo rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
sudo zypper --gpg-auto-import-keys refresh

To install MariaDB use the following command.

sudo zypper install MariaDB-server

To install commonly used packages use the following command.

sudo zypper install galera MariaDB-shared MariaDB-backup MariaDB-common

3. Initial MariaDB configuration

The installation process will not ask you to set a password and this leaves MariaDB insecure. We will use a script that the MariaDB-server package provides strict access to the server and remove unused accounts. Read more about the security script here.

To ensure that our database is secure we need to run the mysql_secure_installation command to remove all remote root login, remove anonymous users, etc.

$ sudo mysql_secure_installation

Following the prompts to secure your MariaDB

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Next is to enable MariaDB database

$ sudo systemctl enable mariadb

Start MariaDB database

$ sudo systemctl start mariadb

Check the status of the MariaDB database

$ sudo systemctl status mariadb

You will see the following as the output.

● mariadb.service - MariaDB 10.3.35 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor p>
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: active (running) since Wed 2022-07-06 13:58:41 UTC; 8s ago
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 7810 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_ST>
    Process: 7813 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && >
    Process: 7936 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_S>
   Main PID: 7836 (mysqld)
     Status: "Taking your SQL requests now..."
      Tasks: 30 (limit: 1129)
     CGroup: /system.slice/mariadb.service
             └─7836 /usr/sbin/mysqld

Jul 06 13:58:41 localhost mysqld[7836]: 2022-07-06 13:58:41 0 [Note] InnoDB: 10>
Jul 06 13:58:41 localhost mysqld[7836]: 2022-07-06 13:58:41 0 [Note] InnoDB: Lo>
Jul 06 13:58:41 localhost mysqld[7836]: 2022-07-06 13:58:41 0 [Note] Plugin 'FE>
Jul 06 13:58:41 localhost mysqld[7836]: 2022-07-06 13:58:41 0 [Note] InnoDB: Bu>
Jul 06 13:58:41 localhost mysqld[7836]: 2022-07-06 13:58:41 0 [Note] Server soc>
Jul 06 13:58:41 localhost mysqld[7836]: 2022-07-06 13:58:41 0 [Note] Reading of>
lines 1-22

To test MariaDB we can create a database. Login to MariaDB console with the following command.

$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.3.35-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SELECT VERSION();
+-----------------+
| VERSION()       |
+-----------------+
| 10.3.35-MariaDB |
+-----------------+
1 row in set (0.000 sec)

MariaDB [(none)]> 

Conclusion

We have learned how to install MariaDB on Ubuntu 21.04 server and secured it using the mysql_secure_installation script. You can now practice running SQL queries to learn more. I hope you enjoyed it and you have learned something new.

How to install MariaDB 10 in Ubuntu 22.04

In this guide we are going to install MariaDB 10 development version, but first what is MariaDB?

MariaDB Server is one of the most popular open-source relational databases. It’s made by the original developers of MySQL and guaranteed to stay open source. It is part of most cloud offerings and the default in most Linux distributions.

It is built upon the values of performance, stability, and openness, and MariaDB Foundation ensures contributions will be accepted on technical merit. Recent new functionality includes advanced clustering with Galera Cluster 4compatibility features with Oracle Database and Temporal Data Tables, allowing one to query the data as it stood at any point in the past.

You need to have Ubuntu 22.04 server with non-root administrative privileges and a firewall configured with UFW. Check out this for initial server setup guide for Ubuntu 20.04.

Installing MariaDB 10

1. Run system updates

Begin by updating your apt repository with the following command on your terminal

$ sudo apt update && apt upgrade -y

2. Install Mariadb 10 on Ubuntu 22.04

Install MariaDB with the following command

$ sudo apt install mariadb-server mariadb-client

The output will look like this

The following additional packages will be installed:
  galera-4 libcgi-fast-perl libcgi-pm-perl libclone-perl
  libconfig-inifiles-perl libdaxctl1 libdbd-mysql-perl libdbi-perl
  libencode-locale-perl libfcgi-bin libfcgi-perl libfcgi0ldbl
  libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
  libhttp-date-perl libhttp-message-perl libio-html-perl
  liblwp-mediatypes-perl libmariadb3 libmysqlclient21 libndctl6 libpmem1
  libsnappy1v5 libtimedate-perl liburi-perl liburing2 mariadb-client-10.6
  mariadb-client-core-10.6 mariadb-common mariadb-server-10.6
  mariadb-server-core-10.6 mysql-common socat
Suggested packages:
  libmldbm-perl libnet-daemon-perl libsql-statement-perl libdata-dump-perl
  libipc-sharedcache-perl libbusiness-isbn-perl libwww-perl mailx mariadb-test
The following NEW packages will be installed:
  galera-4 libcgi-fast-perl libcgi-pm-perl libclone-perl
  libconfig-inifiles-perl libdaxctl1 libdbd-mysql-perl libdbi-perl
  libencode-locale-perl libfcgi-bin libfcgi-perl libfcgi0ldbl
  libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
  libhttp-date-perl libhttp-message-perl libio-html-perl
  liblwp-mediatypes-perl libmariadb3 libmysqlclient21 libndctl6 libpmem1
  libsnappy1v5 libtimedate-perl liburi-perl liburing2 mariadb-client
  mariadb-client-10.6 mariadb-client-core-10.6 mariadb-common mariadb-server
  mariadb-server-10.6 mariadb-server-core-10.6 mysql-common socat
0 upgraded, 36 newly installed, 0 to remove and 7 not upgraded.
Need to get 16.8 MB of archives.
After this operation, 104 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

You check the version of installed MariaDB with the following command:

$ mariadb --version
mariadb  Ver 15.1 Distrib 10.6.7-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper

3. Initial MariaDB configuration

The installation process will not ask you to set a password and this leaves MariaDB insecure. We will use a script that the MariaDB-server package provides strict access to the server and remove unused accounts. Read more about the security script here.

To ensure that our database is secure we need to run the mysql_secure_installation command to remove all remote root login, remove anonymous users, etc.

$ sudo mysql_secure_installation

The following sample output will be displayed.

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Next is to enable MariaDB database

$ sudo systemctl enable mariadb

Start MariaDB database

$ sudo systemctl start mariadb

Check the status of the MariaDB database

$ sudo systemctl status mariadb
● mariadb.service - MariaDB 10.6.7 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor prese>
     Active: active (running) since Wed 2022-07-06 13:03:40 UTC; 8min ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 2941 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 8 (limit: 1033)
     Memory: 57.1M
        CPU: 336ms
     CGroup: /system.slice/mariadb.service
             └─2941 /usr/sbin/mariadbd

Test MariaDB 10

To test MariaDB we can create a database. Login to MariaDB console with the following command.

$ mysql -u root -p
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 37
Server version: 10.6.7-MariaDB-2ubuntu1 Ubuntu 22.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 

Conclusion

We have learned how to install MariaDB on Ubuntu 22.04 server and secured it using the mysql_secure_installation script. You can now practice running SQL queries to learn more. I hope you enjoyed it and you have learned something new.

How to install PostgreSQL 14 on Ubuntu 20.04 from the source

In this article, we are going to learn how to install and get PostgreSQL 14 up and running on an Ubuntu 20.04 server. PostgreSQL is a powerful, open-source object-relational database system that uses and extends the SQL language combined with many features that safely store and scale the most complicated data workloads.

Install PostgreSQL 14 on Ubuntu 20.04

Ubuntu comes with a default PosgreSQL in its APT repositories. To check the default in the repositories, we can use the following command.

$ sudo apt-cache search postgresql | grep postgresql

postgresql - object-relational SQL database (supported version)
postgresql-12 - object-relational SQL database, version 12 server
postgresql-client - front-end programs for PostgreSQL (supported version)
postgresql-client-12 - front-end programs for PostgreSQL 12
postgresql-client-common - manager for multiple PostgreSQL client versions
postgresql-common - PostgreSQL database-cluster manager
postgresql-contrib - additional facilities for PostgreSQL (supported version)
postgresql-doc - documentation for the PostgreSQL database management system
postgresql-doc-12 - documentation for the PostgreSQL database management system

As you can see, Ubuntu 20.04 comes with a default PostgreSQL 12.

Update system repositories

Let’s first update our repositories in order to make them up to date.

$ sudo apt update && apt upgrade -y

Install PostgreSQL dependencies

We need to have the following dependencies installed first before we can proceed to install from the source.

$ sudo apt install build-essential zlib1g-dev libreadline-dev -y

Download PostgreSQL 14 from source

Head over to postgresql ftp server to download the latest version

$ wget https://ftp.postgresql.org/pub/source/v14.2/postgresql-14.2.tar.gz

Next, we need to extarct this downloaded content.

$ tar xvfz postgresql-14.2.tar.gz

Then next we are going to cd into it then do configuration and do make and lastly sudo make install.

cd postgresql-14.2
./configure 
make
make install

Add a Postgres user

To allow us run administrative jobs we need to add a postgres user and also because we didnt install from the APT repository, its ncessary to install Postgresql-contrib first.

$ sudo apt install postgresql-contrib

Add a postgres user password with this command.

$ sudo passwd postgres 

and to switch to the postgres user use this command

$ su postgres
$ psql
psql (14.2 (Ubuntu 14.2-1ubuntu1))
Type "help" for help.

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)
                    

To check the version of the PostgreSQL installed use this command.

postgres=# SELECT version();
 version                                                      
 PostgreSQL 14.2 (Ubuntu 14.2-1ubuntu1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, 64-bit
(1 row)

postgres=# 

Conclusion

Congratulations you have installed PostgreSQL 14 from the source.

How to install MySQL 8 on Ubuntu 22.04

MySQL is an open-source relational database management system. Relational databases organize data into one or more data tables in which data types may be related to each other. Relations help structure data. MySQL has stand-alone clients that allow users to interact directly with a MySQL database using SQL.

MySQL is part of the LAMP stack component which stands for Linux, Apache/Nginx, MySQL/MariaDB, and PHP/Python/Perl. In this tutorial, I will show you how to install MySQL 8 on Ubuntu 22.04.

Installing MySQL 8 on Ubuntu 22.04

1. Update system repositories

Ensure that your repositories are up to date in order to avoid running into unwarranted errors during the installation.

sudo apt update && apt upgrade -y

2. Set MySQL repository

Ubuntu comes with default MySQL packages. So to install the latest version we are going to download the packages with the following command.

curl -LO https://dev.mysql.com/get/mysql-apt-config_0.8.20-1_all.deb

Now that the download is complete, we need to install the .deb file in our system. Use the following command to install. To check the downloaded file, do an ls

sudo dpkg -i mysql-apt-config_0.8.20-1_all.deb

It will open a configuration window where you will be required to choose the version of MySQL to install.

Nextgentips-MySQL config window

Choose Ubuntu focal and press ok. Next you will see the something like the below screenshot.

Nextgentips-MySQL apt config

Choose MySQL Server and cluster and press enter to move to the next step. The next step choose MySQL 8.0

We can check if MySQL 8.0 is available with the following command

$ sudo apt-cache policy mysql-server
mysql-server:
  Installed: (none)
  Candidate: 8.0.28-0ubuntu4
  Version table:
     8.0.28-0ubuntu4 500
        500 http://mirrors.digitalocean.com/ubuntu jammy/main amd64 Packages

3. Install MySQL 8.0 on Ubuntu 22.04

Let’s now proceed to install MySQL 8 on our system using the following command.

sudo apt install mysql-server -y

You will see the following sample output.

The following additional packages will be installed:
  libcgi-fast-perl libcgi-pm-perl libclone-perl libencode-locale-perl libevent-pthreads-2.1-7 libfcgi-bin libfcgi-perl libfcgi0ldbl
  libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl
  liblwp-mediatypes-perl libmecab2 libprotobuf-lite23 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils
  mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server-8.0 mysql-server-core-8.0
Suggested packages:
  libdata-dump-perl libipc-sharedcache-perl libbusiness-isbn-perl libwww-perl mailx tinyca
The following NEW packages will be installed:
  libcgi-fast-perl libcgi-pm-perl libclone-perl libencode-locale-perl libevent-pthreads-2.1-7 libfcgi-bin libfcgi-perl libfcgi0ldbl
  libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl
  liblwp-mediatypes-perl libmecab2 libprotobuf-lite23 libtimedate-perl liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils
  mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server mysql-server-8.0 mysql-server-core-8.0
0 upgraded, 28 newly installed, 0 to remove and 0 not upgraded.
Need to get 29.0 MB of archives.

You can check if MySQL have been installed again.

$ apt-cache policy mysql-server
mysql-server:
  Installed: 8.0.28-0ubuntu4
  Candidate: 8.0.28-0ubuntu4
  Version table:
 *** 8.0.28-0ubuntu4 500
        500 http://mirrors.digitalocean.com/ubuntu jammy/main amd64 Packages
        100 /var/lib/dpkg/status

4. Secure MySQL installation

We need to secure installed MySQL by running the following command.

$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y 

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

5. Configuring MySQL services

We can enable MySQL to start automatically whenever we reboot our server. We do so with the following command.

sudo systemctl enable mysql

To check the status of MySQL we use the following command.

$ sudo systemctl status mysql 
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-04-30 06:36:22 UTC; 18min ago
   Main PID: 2327 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 1119)
     Memory: 353.1M
        CPU: 2.956s
     CGroup: /system.slice/mysql.service
             └─2327 /usr/sbin/mysqld

Apr 30 06:36:21 ubuntu systemd[1]: Starting MySQL Community Server...
Apr 30 06:36:22 ubuntu systemd[1]: Started MySQL Community Server.

To start MySQL use the following command.

sudo systemctl start mysql

To stop the MySQL service use:

sudo systemctl stop mysql

And to restart MySQL again use.

sudo systemctl restart mysql

To login to MySQL we type the following

mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.28-0ubuntu4 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

Conclusion

We have successfully installed MySQL 8.0 on Ubuntu 22.04.

How to install InfluxDB 2 on Debian 11

InfluxDB is an open-source time-series database. It is used for storage and retrieval of time series data in fields such as operation monitoring, operations metrics, internet of things sensor data, and real-time analytics. In this tutorial, we are going to learn how to install InfluxDB on Debian 11.

By default, InfluxDB uses the following network ports for communication.

  • TCP port 8086 for client-server communication.
  • TCP port 8088 for RPC service to perform backup and restore operations.

Why InfluxDB?

  • It provides deep insight and analytics
  • InfluxDB is optimized for developer productivity
  • It has best UI which features dashboard, explorer and script editor.
  • It has faster time to market. That is production is faster while usin influxDB.
  • It is easy to build and easy to share templates.

Prerequisites

  • You need to be root to perform tasks
  • Have basic knowledge of terminal.
  • Have Debian 11 server up and running.

Installing InfluxDB on Debian 11

1. Update system repositories

The first thing to do is to make sure that repositories are up to date. Updating repositories will enable you to avoid running into errors later.

$ sudo apt update && apt upgrade -y

2. Add InfluxDB repository to Ubuntu Repository

To install the stable latest version using apt, run the following command using curl.

Add key

$ wget -qO- https://repos.influxdata.com/influxdb.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdb.gpg > /dev/null
$ export DISTRIB_ID=$(lsb_release -si); export DISTRIB_CODENAME=$(lsb_release -sc)

3. Add Repository

$ echo "deb [signed-by=/etc/apt/trusted.gpg.d/influxdb.gpg] https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list > /dev/null

Then update the system repositories again

$ sudo apt update
Get:5 https://repos.influxdata.com/debian bullseye InRelease [4739 B]                                                         
Hit:6 https://repos-droplet.digitalocean.com/apt/droplet-agent main InRelease                                       
Get:7 http://deb.debian.org/debian bullseye-backports/main Sources.diff/Index [63.3 kB]
Get:8 http://deb.debian.org/debian bullseye-backports/main amd64 Packages.diff/Index [63.3 kB]
Get:9 http://deb.debian.org/debian bullseye-backports/main Translation-en.diff/Index [60.0 kB]

4. Install influxDB on Ubuntu 20.04

To install the latest stable version of InfluxDB we use the following command:

$ sudo apt install influxdb2

The following is the output you will get from the terminal.

Output.
The following NEW packages will be installed:
  influxdb2 influxdb2-cli
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 114 MB of archives.
After this operation, 195 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://repos.influxdata.com/debian bullseye/stable amd64 influxdb2 amd64 2.1.1 [108 MB]
Get:2 https://repos.influxdata.com/debian bullseye/stable amd64 influxdb2-cli amd64 2.2.1 [5325 kB]
Fetched 114 MB in 2s (68.9 MB/s)    
Selecting previously unselected package influxdb2.
(Reading database ... 25056 files and directories currently installed.)
Preparing to unpack .../influxdb2_2.1.1_amd64.deb ...
Unpacking influxdb2 (2.1.1) ...
Selecting previously unselected package influxdb2-cli.
Preparing to unpack .../influxdb2-cli_2.2.1_amd64.deb ...
Unpacking influxdb2-cli (2.2.1) ...
Setting up influxdb2 (2.1.1) ...
Created symlink /etc/systemd/system/influxd.service → /lib/systemd/system/influxdb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/influxdb.service → /lib/systemd/system/influxdb.service.
Setting up influxdb2-cli (2.2.1) ...

5. Configuring InfluxDB

In order to start using InfluxDB, we need to start and enable it.

# start InfluxDB
$ sudo systemctl start influxdb
# enable
$ sudo systemctl enable --now influxdb
# status
$ sudo systemctl status influxdb
# Status 
● influxdb.service - InfluxDB is an open-source, distributed, time series database
     Loaded: loaded (/lib/systemd/system/influxdb.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-02-09 17:52:45 UTC; 43s ago
       Docs: https://docs.influxdata.com/influxdb/
    Process: 550 ExecStart=/usr/lib/influxdb/scripts/influxd-systemd-start.sh (code=exited, status=0/SUCCESS)
   Main PID: 555 (influxd)
      Tasks: 7 (limit: 1132)
     Memory: 111.2M
        CPU: 735ms
     CGroup: /system.slice/influxdb.service
             └─555 /usr/bin/influxd

Feb 09 17:52:44 debian influxd-systemd-start.sh[555]: ts=2022-02-09T17:52:44.761167Z lvl=info msg="Open store (end)" log_id=0Z>
Feb 09 17:52:44 debian influxd-systemd-start.sh[555]: ts=2022-02-09T17:52:44.761210Z lvl=info msg="Starting retention policy e>
Feb 09 17:52:44 debian influxd-systemd-start.sh[555]: ts=2022-02-09T17:52:44.761247Z lvl=info msg="Starting precreation servic>
Feb 09 17:52:44 debian influxd-systemd-start.sh[555]: ts=2022-02-09T17:52:44.761304Z lvl=info msg="Starting query controller" >
Feb 09 17:52:44 debian influxd-systemd-start.sh[555]: ts=2022-02-09T17:52:44.766154Z lvl=info msg="Configuring InfluxQL statem>
Feb 09 17:52:44 debian influxd-systemd-start.sh[550]: InfluxDB API at http://localhost:8086/ready unavailable after 1 attempts>
Feb 09 17:52:45 debian influxd-systemd-start.sh[555]: ts=2022-02-09T17:52:45.084183Z lvl=info msg=Listening log_id=0ZZuh_gW000>
Feb 09 17:52:45 debian influxd-systemd-start.sh[555]: ts=2022-02-09T17:52:45.085334Z lvl=info msg=Starting log_id=0ZZuh_gW000 >
Feb 09 17:52:45 debian influxd-systemd-start.sh[550]: InfluxDB started
Feb 09 17:52:45 debian systemd[1]: Started InfluxDB is an open-source, distributed, time series database.
lines 1-22/22 (END)

Enable –now InfluxDB will ensure that InfluxDB starts every time the server is reloaded. We don’t need to reenable every time.

6. Enable Firewall settings

To ensure that we can access InfluxDB from outside, we need to enable TCP 8086 on the firewall.

To know more about how to enable firewall, read this article How to setup Ubuntu 20.04 Server for the first time

$ sudo ufw allow 8086/tcp

To check the status we use ufw enable and status command

$ sudo ufw enable
$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
8086/tcp                   ALLOW       Anywhere                  
8086/tcp (v6)              ALLOW       Anywhere (v6)  

We can verify the version installed with the following command.

$ influx version
Influx CLI 2.2.1 (git: 31ac783) build_date: 2021-11-09T21:24:22Z

7. Setting up InfluxDB

Initial InfluxDB setup entails creating a default organization, user, bucket, and operator API token.

Setup InfluxDB through UI

  • With InfluxDB running visit localhost:8086.
  • Click get started

Set up initial user

  • Enter a Username for your initial user.
  • Enter a Password and Confirm Password for your user.
  • Enter your initial Organization Name.
  • Enter your initial Bucket Name.
  • Click Continue.

Set up InfluxDB through Influx CLI

Begin CLI setup with the following command.

$ influx setup
  • Enter a primary username.
  • Enter a password for your user.
  • Confirm your password by entering it again.
  • Enter a name for your primary organization.
  • Enter a name for your primary bucket.
  • Enter a retention period for your primary bucket—valid units are nanoseconds (ns), microseconds (us or µs), milliseconds (ms), seconds (s), minutes (m), hours (h), days (d), and weeks (w). Enter nothing for an infinite retention period.
  • Confirm the details for your primary user, organization, and bucket.
> Welcome to InfluxDB 2.0!
? Please type your primary username nextgentips
? Please type your password **********
? Please type your password again **********
? Please type your primary organization name nextgen
? Please type your primary bucket name example
? Please type your retention period in hours, or 0 for infinite 0
? Setup with these parameters?
  Username:          nextgentips
  Organization:      nextgen
  Bucket:            example
  Retention Period:  infinite
 Yes
User            Organization    Bucket
nextgentips     nextgen         example

Conclusion

We have successfully installed InfluxDB on Debian 11. In case of any issue head over to InfluxDB documentation for clarification.

How to install InfluxDB on Ubuntu 20.04

InfluxDB is an open-source time-series database. It is used for storage and retrieval of time series data in fields such as operation monitoring, operations metrics, internet of things sensor data, and real-time analytics. In this tutorial, we are going to learn how to install InfluxDB on Ubuntu 20.04.

By default, InfluxDB uses the following network ports for communication. If you need to change any port configuration head over to /etc/influxdb/influxdb.conf.

  • TCP port 8086 for client-server communication.
  • TCP port 8088 for RPC service to perform backup and restore operations.

Why InfluxDB?

  • It provides deep insight and analytics
  • InfluxDB is optimized for developer productivity
  • It has best UI which features dashboard, explorer and script editor.
  • It has faster time to market. That is production is faster while usin influxDB.
  • It is easy to build and easy to share templates.

Prerequisites

  • You need to be root to perform tasks
  • Have basic knowledge of terminal.
  • Have Ubuntu 20.04 server up and running.

Installing InfluxDB on Ubuntu 20.04

1. Update system repositories

In order to make our system repositories up to date, use the following command in your terminal.

$ sudo apt update && apt upgrade 

2. Add InfluxDB repository to Ubuntu Repository

To install the stable latest version using apt, run the following command using curl.

Add key

$ curl -s https://repos.influxdata.com/influxdb.key | gpg --dearmor > /etc/apt/trusted.gpg.d/influxdb.gpg
$ export DISTRIB_ID=$(lsb_release -si); export DISTRIB_CODENAME=$(lsb_release -sc)

3. Add Repository

$ echo "deb [signed-by=/etc/apt/trusted.gpg.d/influxdb.gpg] https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" > /etc/apt/sources.list.d/influxdb.list

Then update the system repositories again

$ sudo apt update
Get:1 https://repos.influxdata.com/ubuntu focal InRelease [4736 B]
Hit:2 https://repos-droplet.digitalocean.com/apt/droplet-agent main InRelease                                                 
Hit:3 http://mirrors.digitalocean.com/ubuntu focal InRelease                                                                  
Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:5 http://mirrors.digitalocean.com/ubuntu focal-updates InRelease
Get:6 https://repos.influxdata.com/ubuntu focal/stable amd64 Packages [1263 B]
Hit:7 http://mirrors.digitalocean.com/ubuntu focal-backports InRelease   

4. Install influxDB on Ubuntu 20.04

To install the latest stable version of InfluxDB we use the following command:

$ sudo apt install influxdb

The following is the output you will get from the terminal.

Output.
The following NEW packages will be installed:
  influxdb
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 54.4 MB of archives.
After this operation, 153 MB of additional disk space will be used.
Get:1 https://repos.influxdata.com/ubuntu focal/stable amd64 influxdb amd64 1.8.10-1 [54.4 MB]
Fetched 54.4 MB in 1s (41.5 MB/s)   
Selecting previously unselected package influxdb.
(Reading database ... 94672 files and directories currently installed.)
Preparing to unpack .../influxdb_1.8.10-1_amd64.deb ...
Unpacking influxdb (1.8.10-1) ...
Setting up influxdb (1.8.10-1) ...
Created symlink /etc/systemd/system/influxd.service → /lib/systemd/system/influxdb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/influxdb.service → /lib/systemd/system/influxdb.service.
Processing triggers for man-db (2.9.1-1) ...

5. Configuring InfluxDB

In order to start using InfluxDB, we need to start and enable it.

# start InfluxDB
$ sudo systemctl start influxdb
# enable
$ sudo systemctl enable --now influxdb
# status
$ sudo systemctl status influxdb
Status 
● influxdb.service - InfluxDB is an open-source, distributed, time series database
     Loaded: loaded (/lib/systemd/system/influxdb.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-02-08 13:04:23 UTC; 1min 21s ago
       Docs: https://docs.influxdata.com/influxdb/
   Main PID: 1616 (influxd)
      Tasks: 8 (limit: 1131)
     Memory: 14.7M
     CGroup: /system.slice/influxdb.service
             └─1616 /usr/bin/influxd -config /etc/influxdb/influxdb.conf

Feb 08 13:04:23 ubuntu influxd-systemd-start.sh[1616]: ts=2022-02-08T13:04:23.805189Z lvl=info msg="Starting HTTP service" log>
Feb 08 13:04:23 ubuntu influxd-systemd-start.sh[1616]: ts=2022-02-08T13:04:23.805868Z lvl=info msg="opened HTTP access log" lo>
Feb 08 13:04:23 ubuntu influxd-systemd-start.sh[1616]: ts=2022-02-08T13:04:23.810007Z lvl=info msg="Storing statistics" log_id>
Feb 08 13:04:23 ubuntu influxd-systemd-start.sh[1616]: ts=2022-02-08T13:04:23.812489Z lvl=info msg="Listening on HTTP" log_id=>
Feb 08 13:04:23 ubuntu influxd-systemd-start.sh[1616]: ts=2022-02-08T13:04:23.812998Z lvl=info msg="Starting retention policy >
Feb 08 13:04:23 ubuntu influxd-systemd-start.sh[1616]: ts=2022-02-08T13:04:23.813507Z lvl=info msg="Listening for signals" log>
Feb 08 13:04:23 ubuntu influxd-systemd-start.sh[1616]: ts=2022-02-08T13:04:23.814335Z lvl=info msg="Sending usage statistics t>
Feb 08 13:04:23 ubuntu influxd-systemd-start.sh[1616]: [httpd] ::1 - - [08/Feb/2022:13:04:23 +0000] "GET /health HTTP/1.1" 200>
Feb 08 13:04:23 ubuntu influxd-systemd-start.sh[1612]: InfluxDB started
Feb 08 13:04:23 ubuntu systemd[1]: Started InfluxDB is an open-source, distributed, time series database.

Enable –now InfluxDB will ensure that InfluxDB starts every time the server is reloaded. We don’t need to reenable every time.

Whenever you need to enable a certain configuration, head over to /etc/influxdb/influxdb.conf. Lets see an example.

$ sudo vi /etc/influxdb/influxdb.conf

Let’s enabled HTTP on our server, just comment out enabled = true save changes and exit.

To apply the changes stop the server and restart back again.

# stop
$ sudo systemctl stop influxdb
# restart
$ sudo systemctl start influxdb

6. Enable Firewall settings

To ensure that we can access InfluxDB from outside, we need to enable TCP 8086 on the firewall.

To know more about how to enable firewall read this article How to setup Ubuntu 20.04 Server for the first time

$ sudo ufw allow 8086/tcp

To check the status we use ufw enable and status command

$ sudo ufw enable
$ sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
8086/tcp                   ALLOW       Anywhere                  
8086/tcp (v6)              ALLOW       Anywhere (v6)  

7. Launching InfluxDB

To launch InfluxDB we need to point the process to the correct configuration file by using -config flag. Lets see how we can do this.

$ influxd -config /etc/influxdb/influxdb.conf

This is what we get when we invoke the above command.

8888888           .d888 888                   8888888b.  888888b.
   888            d88P"  888                   888  "Y88b 888  "88b
   888            888    888                   888    888 888  .88P
   888   88888b.  888888 888 888  888 888  888 888    888 8888888K.
   888   888 "88b 888    888 888  888  Y8bd8P' 888    888 888  "Y88b
   888   888  888 888    888 888  888   X88K   888    888 888    888
   888   888  888 888    888 Y88b 888 .d8""8b. 888  .d88P 888   d88P
 8888888 888  888 888    888  "Y88888 888  888 8888888P"  8888888P"

2022-02-08T13:34:41.401402Z     info    InfluxDB starting       {"log_id": "0ZYOY6yW000", "version": "1.8.10", "branch": "1.8", "commit": "688e697c51fd"}
2022-02-08T13:34:41.402018Z     info    Go runtime      {"log_id": "0ZYOY6yW000", "version": "go1.13.8", "maxprocs": 1}
run: open server: listen: listen tcp 127.0.0.1:8088: bind: address already in use

Conclusion

We have successfully installed InfluxDB on Ubuntu 20.04. In case of any issue head over to InfluxDB documentation for clarification.

How to install MongoDB 5 on Rocky Linux

In this tutorial guide, we are going to learn how to install MongoDB 5.0 on Rocky Linux.

MongoDB is an open-source NoSQL database that provides high throughput for data-driven applications. Unlike relational databases such as MySQL, Oracle, and SQL servers which store data in tables according to a rigid schema, MongoDB stores data in documents with flexible schema.

Why do we need MongoDB?

  • MongoDB makes it easy for developers to store structured or unstructured data, it uses JSON-like format to store documents. This format directly maps to native objects in most programming languages, making natural database for most developers.
  • MongoDB is built on a scale-out architecture making popular for developers developing scalable applications with evolving data schemas.
  • MongoDB is available in every major public cloud provider such as Azure, AWS, GCP making it easy for developers to deploy to any cloud provider of choice.
  • MongoDB supports rapid iterative development where developers collaborate with larger teams.
  • In MongoDB records are stored as documents in compressed BSON files.

MongoDB documents can be retrieved in JSON formats which has many benefits such as:

  • It is human readable, makes it easy to be read
  • It is a natural form to store data
  • You can nest JSON to store complex data objects.
  • Documents maps to objects in most popular programming languages.
  • Structured and unstructured information can be stored in the same document
  • JSON has a flexible and dynamic schema, so adding fields or leaving a field out is not a problem.

Prerequisites

  • Have Rocky Linux server running
  • Have a user with sudo priviliges
  • MongoDB only supports 64 bits version of Linux, so make sure you are running x64.

Install MongoDB 5 on Rocky Linux

1. Run system updates

To begin with we need to make our system repositories up to date. This will help avoid running into errors while doing the installations.

$ sudo dnf update -y 

2. Configure package management (yum)

The easy way to install Mongo is to create /etc/yum.repos.d/mongodb-org-5.0.repo file so that we can easily install using the yum repository.

$ sudo vi /etc/yum.repos.d/mongodb-org-5.0.repo

Add the following content ;

[mongodb-org-5.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/5.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc

3. Install MongoDB 5 on Rocky Linux

Now we can install the latest version of MongoDB with the following

$ sudo dnf install mongodb-org -y

We will see the following output

MongoDB Repository                                                                              42 kB/s |  16 kB     00:00    
Dependencies resolved.
===============================================================================================================================
 Package                                Architecture Version                                       Repository             Size
===============================================================================================================================
Installing:
 mongodb-org                            x86_64       5.0.5-1.el8                                   mongodb-org-5.0        11 k
Installing dependencies:
 cyrus-sasl                             x86_64       2.1.27-5.el8                                  baseos                 95 k
 cyrus-sasl-gssapi                      x86_64       2.1.27-5.el8                                  baseos                 49 k
 cyrus-sasl-plain                       x86_64       2.1.27-5.el8                                  baseos                 46 k
 mongodb-database-tools                 x86_64       100.5.1-1                                     mongodb-org-5.0        47 M
 mongodb-mongosh                        x86_64       1.1.9-1.el7                                   mongodb-org-5.0        44 M
 mongodb-org-database                   x86_64       5.0.5-1.el8                                   mongodb-org-5.0        11 k
 mongodb-org-database-tools-extra       x86_64       5.0.5-1.el8                                   mongodb-org-5.0        16 k
 mongodb-org-mongos                     x86_64       5.0.5-1.el8                                   mongodb-org-5.0        19 M
 mongodb-org-server                     x86_64       5.0.5-1.el8                                   mongodb-org-5.0        28 M
 mongodb-org-shell                      x86_64       5.0.5-1.el8                                   mongodb-org-5.0        15 M
 mongodb-org-tools                      x86_64       5.0.5-1.el8                                   mongodb-org-5.0        11 k
 python3-pip                            noarch       9.0.3-20.el8.rocky.0                          appstream              19 k
 python3-setuptools                     noarch       39.2.0-6.el8                                  baseos                162 k
 python36                               x86_64       3.6.8-38.module+el8.5.0+671+195e4563          appstream              18 k
Enabling module streams:
 python36                                            3.6                                                                      

Transaction Summary
===============================================================================================================================
Install  15 Packages

Total download size: 153 M
Installed size: 565 M
Is this ok [y/N]: 
.....
Installed:
  cyrus-sasl-2.1.27-5.el8.x86_64                                
  cyrus-sasl-gssapi-2.1.27-5.el8.x86_64                        
  cyrus-sasl-plain-2.1.27-5.el8.x86_64                           
  mongodb-database-tools-100.5.1-1.x86_64                      
  mongodb-mongosh-1.1.9-1.el7.x86_64                             
  mongodb-org-5.0.5-1.el8.x86_64                               
  mongodb-org-database-5.0.5-1.el8.x86_64                        
  mongodb-org-database-tools-extra-5.0.5-1.el8.x86_64          
  mongodb-org-mongos-5.0.5-1.el8.x86_64                          
  mongodb-org-server-5.0.5-1.el8.x86_64                        
  mongodb-org-shell-5.0.5-1.el8.x86_64                           
  mongodb-org-tools-5.0.5-1.el8.x86_64                         
  python3-pip-9.0.3-20.el8.rocky.0.noarch                        
  python3-setuptools-39.2.0-6.el8.noarch                       
  python36-3.6.8-38.module+el8.5.0+671+195e4563.x86_64   

Lets check the version of MongoDB we have just installed.

$ mongod --version
db version v5.0.5
Build Info: {
    "version": "5.0.5",
    "gitVersion": "d65fd89df3fc039b5c55933c0f71d647a54510ae",
    "openSSLVersion": "OpenSSL 1.1.1k  FIPS 25 Mar 2021",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "rhel80",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

5. Configure MongoDB 5

To start using MongoDB we need to start the MongoDB.service, to do that run the following command;

$ sudo systemctl start mongod

Then after starting you need to enable it to start every time you boot up your device.

$ sudo systemctl enable mongod

Lastly, you can check the status of our MongoDB service if it is running as expected.

$ sudo systemctl status mongod
Output
● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2022-01-30 18:15:31 UTC; 38s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 38404 (mongod)
   Memory: 66.2M
   CGroup: /system.slice/mongod.service
           └─38404 /usr/bin/mongod -f /etc/mongod.conf

Jan 30 18:15:29 rockylinux systemd[1]: Starting MongoDB Database Server...
Jan 30 18:15:29 rockylinux mongod[38401]: about to fork child process, waiting until server is ready for connections.
Jan 30 18:15:29 rockylinux mongod[38401]: forked process: 38404
Jan 30 18:15:31 rockylinux mongod[38401]: child process started successfully, parent exiting
Jan 30 18:15:31 rockylinux systemd[1]: Started MongoDB Database Server.

Our MongoDB service is now running as expected.

To start using MongoDB type on your terminal mongosh, it will show something like this output;

$ mongosh 
Current Mongosh Log ID: 61f6d61a8cda0cc1b432fec6
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.1.9
Using MongoDB:          5.0.5
Using Mongosh:          1.1.9

For mongosh info see: https://docs.mongodb.com/mongodb-shell/


To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy).
You can opt-out by running the disableTelemetry() command.

------
   The server generated these startup warnings when booting:
   2022-01-30T18:15:30.984+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2022-01-30T18:15:30.984+00:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
------

test> 

6. MongoDB crud operations

Crud operations include creating, reading, updating, and deleting.

To check the current database you are operating on type db

$ db 
test

Here am working on the test database.

To switch database you just say use db_name and it will create and switch to the database automatically.

$ use nextgentips

Insert into MongoDB database

MongoDB provides the following methods to insert documents into a collection.

# insert one 
$ db.collection.insertOne()
# insert many
$ db.collection.insertMany()

Example

nextgen> db.nextgen.insertOne([ { Name: 'Nextgentips', Niche: 'Linux Tech Blog' }])
{
  acknowledged: true,
  insertedId: ObjectId("61f6d75e80b3d76dd79c1018")
}

In order to select documents you can use the find statement like this

db.collection.find()

Example

db.nexgen.find()

7. Uninstall MongoDB 5

If you want to uninstall MongoDB, first you will have to stop the MongoDB running instance and then remove the packages

Stop MongoDB instance

$ sudo systemctl stop mongod

Remove MongoDB packages

To completely remove the packages run the following command;

$ sudo dnf erase $(rpm -qa | grep mongodb-org)

Lastly, remove data directories

# log
$ sudo rm -r /var/log/mongodb
# lib
$ sudo rm -r /var/lib/mongodb

Conclusion.

We have learned how to install MongoDB on Rocky Linux. I am glad you have enjoyed the tutorial. Feel free to comment in case you are faced with a challenge.