Database Server (Demo)

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
21 hours 25 minutes
Difficulty
Intermediate
CEU/CPE
21
Video Transcription
00:00
>> Hey, Cybrarians. Welcome back to
00:00
the Linux+ course here at Cybrary.
00:00
I'm your instructor, Rob Gils.
00:00
In today's lesson, we're going to
00:00
be discussing database servers.
00:00
Upon completion of today's lesson,
00:00
you are going to be able to talk about
00:00
the importance of database servers.
00:00
We're also going to explain at a high level how
00:00
SQL and NoSQL database servers work,
00:00
and then we're going to install
00:00
PostgreSQL on both CentOS and Ubuntu.
00:00
Storing and retrieving data is really at the heart
00:00
of most applications that you're going to run in Linux.
00:00
While some data can be stored
00:00
>> just in a plain text file,
00:00
>> most modern applications require
00:00
advanced data storage techniques.
00:00
This is where a database,
00:00
a DB server comes in.
00:00
It's stores and retrieves data upon request.
00:00
Now, relational databases are used pretty commonly.
00:00
They allow multiple clients to access data.
00:00
That data is stored in tables,
00:00
so it's a structured way to store data.
00:00
Therefore, we use something called the
00:00
Structured Query Language or
00:00
SQL to get the data that we need out of the database.
00:00
SQL provides the method for clients to send
00:00
requests and retrieve data from the database.
00:00
SQL is so ubiquitous though that
00:00
there are a ton of database packages for it.
00:00
Some just include, for instance, PostgreSQL,
00:00
which is a complete relational
00:00
database management system.
00:00
>> We're going to use that here.
00:00
>> We're going to show that off in the demo later.
00:00
PostgreSQL uses port 5432.
00:00
Then there's also MySQL. It's actually been
00:00
replaced more commonly now by something called MariaDB,
00:00
and this is a simple and fast database system.
00:00
It's used by a lot of web applications,
00:00
It's part of what's called the LAMP stack.
00:00
The letters in there stand for Linux, Apache,
00:00
MySQL or MariaDB and PHP.
00:00
This uses the port 3306 by default.
00:00
It's just nothing to keep in mind, PostgreSQL 5432,
00:00
MySQL and MariaDB port 3306.
00:00
Then on the other side of the coin, there are things
00:00
that are called NoSQL databases.
00:00
A popular NoSQL package is called MongoDB.
00:00
MongoDB stores data without tables.
00:00
There's no tables. There's no structure.
00:00
Instead, what happens is each and every record has
00:00
a JSON element that contains information
00:00
about that record inside of the database.
00:00
MongoDB uses port 27017,
00:00
but with that, let's go ahead and
00:00
take a look at installing some of
00:00
these database servers with some demo time.
00:00
Here we are over in
00:00
our CentOS environment to start, and let's first of all
00:00
take a look at the available PostgreSQL packages.
00:00
We can do that by doing a dnf module list on
00:00
postgresql, and what we'll see here when this
00:00
returns is there are a few different versions
00:00
of PostgreSQL that you can install in CentOS.
00:00
We have hints down here at the bottom.
00:00
We can see, for instance, that this is default.
00:00
>> That means that version 10 is default,
00:00
>> but what happens if we want to install
00:00
version 12? Let's do that.
00:00
Let's install the newest version.
00:00
The way that we can do this, we can specify dnf module
00:00
enable postgresql version 12.
00:00
We just do colon 12.
00:00
Now that's going to enable it and make it default.
00:00
We say yes to that.
00:00
Now if we run this list command again,
00:00
we'll see that PostgreSQL 12
00:00
is enabled, and we're good to go.
00:00
Now that that has been enabled,
00:00
what we can do is we can do
00:00
the install of that by just using a simple
00:00
>> dnf install postgresql-server.
00:00
>> We'll see that it is installing version 12.
00:00
You can see the version information
00:00
over here. Let's hit Y.
00:00
This is going to go ahead and download and
00:00
install all the packages and dependencies,
00:00
the libraries, so on and
00:00
so forth that we need on the system.
00:00
We're back to our command prompts.
00:00
Let's clear our screen and get
00:00
our real state back. There we go.
00:00
Now the thing that we need to
00:00
know about PostgreSQL is that
00:00
every PostgreSQL database server
00:00
exists as part of a database cluster
00:00
even if it's just a single server.
00:00
We have to initialize a database instance.
00:00
In order to do that,
00:00
what we can do is we can use
00:00
>> a built-in Postgres command,
00:00
>> so postgresql-setup
00:00
>> and what we're going to do is initdb.
00:00
>> This is going to initialize everything for us.
00:00
What we do is it's initializing the database.
00:00
We can see that that's created in
00:00
var/lib/pgsql/data and a log file
00:00
that's kept in var/lib/pgsql/initdb_postgresql.log.
00:00
Now once this is done, we can also enable
00:00
Postgres to start using system CTL.
00:00
We'll do a systemctl enable dash dash now,
00:00
>> our favorite command, on Postgres.
00:00
>> We're running, and we're off to the races.
00:00
We can see that with a status on here,
00:00
but that's all we really need to do in
00:00
order to get Postgres running in CentOS.
00:00
Let's take a look at the same thing over in Ubuntu.
00:00
We're over here in our Ubuntu system,
00:00
>> and over in Ubuntu, PostgreSQL 12 is the default.
00:00
>> We can see this if we do an apt list on PostgreSQL.
00:00
We can just do a dash a.
00:00
We can see that we're running version
00:00
12 here, so we're good to go.
00:00
Now all we need to do is just do an apt
00:00
install on it, apt install postgresql,
00:00
slightly different command though. We're
00:00
also going to include
00:00
>> postgresql dash contrib.
00:00
>> There we go.
00:00
>> These are actually already installed on
00:00
this system because I've been going ahead
00:00
>> and done this,
00:00
>> but that's basically the command
00:00
that we would run to do this.
00:00
What we can also see is that this install is
00:00
going to take care of everything for us.
00:00
It's going to set up all of
00:00
everything it's going to install, and
00:00
it's going to configure PostgreSQL.
00:00
If we do a status on this,
00:00
we do a systemctl status postgresql.
00:00
We're going to see that everything is actually
00:00
already installed and running, and it is.
00:00
It's loaded. It's active.
00:00
It's enabled, so on and so forth.
00:00
Again, that's one thing that you got to keep in
00:00
mind about Ubuntu is it'll take
00:00
care of that for you automatically.
00:00
If you don't want it to do so,
00:00
you may have to go back in and
00:00
turn it off after the fact.
00:00
One thing to keep in mind is that
00:00
the paths are slightly different.
00:00
For instance, the database
00:00
for Postgres is stored at
00:00
>> var/lib/postgresql/12/main.
00:00
>> That's the database location on an Ubuntu system,
00:00
and then the log itself is going to be
00:00
stored at
00:00
>> var/log/postgresql/postgresql-12/main.log.
00:00
>> That's really the only difference between
00:00
CentOS and Ubuntu.
00:00
With that, we've reached the end of this lesson.
00:00
In this lesson we covered the importance of
00:00
databases for application data storage.
00:00
We had a high-level overview of
00:00
>> SQL versus NoSQL databases,
00:00
>> and then we installed PostgreSQL on CentOS and Ubuntu.
00:00
Thanks so much for being here. and I look
00:00
forward to seeing you in the next lesson.
Up Next