So we'll start looking at some of our common services now,
including our time services,
how we keep our service clocks synchronized with network time
using the NTP or the network time protocol and through services
such as chronyd or our systemd‑timesyncd.
Now we have got a choice between chronyd or our systemd‑timesync daemon.
The timesync daemon is going to use less overhead but is more simple.
But as we go through and take a look,
chronyd is both a network time server and a client but
then giving a more complex configuration.
Whereas when we look at the systemd‑timesyncd,
it's a client only, making for a more simple configuration.
And very often,
we only need the network time client; we don't need the network time server.
We're going to move out to our command line nos,
and working with AlmaLinux,
we're going to see how we can configure time synchronization,
the use of the timedatectl command, and chronyd and systemd‑timesyncd.
So here we are working on our AlmaLinux system,
and we can start comparing our different time services.
So looking at the timedatectl command,
it will show us some of the very basic information.
What's key to us here is the NTP service, and we can see that it's active.
Now it doesn't tell us which NTP service is running,
but by default in Red Hat Enterprise Linux 8, this should be our
chronyd time service. So we can always go into the background and start
checking what is holding open our NTP service.
If I use the systemctl and status and take a look at my
chronyd service, we should see that it's active and see the
basic information for the service.
So we can see then that this is enabled,
it's running, and it's been running for 19 hours.
So this is good.
We can take a little bit more of a look. Using our chronyc client,
we can go through and look at our time sources.
The asterisk is shown against the server that is selected as our
time source, so we're synchronizing with the ntp1.wirehive.net, as
shown by the output of this command.
The configuration file is found in etc and chrony.conf, and
we can see that it's heavily commented,
which is good but also doesn't show us what the effective settings are.
And this is where we can get really powerful with the grep command. ‑v
reverses our search. The uppercase E allows for an enhanced regular
expression, and we can really start seeing the power of what we can use
with grep now, because we're going to specify that we're going to look
for lines beginning with and then a group. The grouping is required to
put items together and it's why we're using an enhanced regular
expression.
We're looking for lines beginning with a comment or the
end‑of‑line marker, so commented or empty lines. We're going to be
reversing that so we don't show it from our chrony.conf, and now
we can see the effective settings.
This is both then a time server and a time client. But where we want
perhaps a more simple configuration, we can go through and take a look
at installing and using an NTP client only.
This is going to give us a more simple configuration, as well as lighter
weight in memory. I'm going to use then sudo and yum install and then a
repository package, epel‑release. This is going to add in an extra software
repository for us to download it, as the systemd‑timesyncd isn't provided by
default in Red Hat Enterprise Linux is 8 and hence, AlmaLinux. Having added
in that extra repository,
we can go ahead and install, then, the systemd‑timesyncd.
systemd‑timesyncd is the client‑only NTP client and is installed by
default on Ubuntu 2004 but not on our AlmaLinux system. So we can go
ahead and install the package and accept the key for the signing of
packages. Now then that it is installed, we can make sure that we enable
and start our service, and in doing so, we're going to stop the chronyd
service automatically.
So with the systemd‑timesync daemon running,
we no longer have our old time service running, and we can check this
by taking a look at systemctl and status chronyd.
So that's now not active and it's been shut down for 19 seconds.
But if we go through and take a look at the status of our systemd and timesyncd,
we can see then that now is up and running, and we can see the
server that we should be synchronizing with.
Now this is the client only, so the configuration is far
more simple, and we're going to find that configuration in
etc/systemd and timesyncd.conf.
And when we look, there are only a couple of settings that we would normally
need to be able to make towards the bottom of the screen.
If we wanted to set our own NTP server, we'd set it in the NTP field. Otherwise, we fall back to the default time service.