Managing time

RHEL 7 comes preinstalled with Chrony. While everybody knows Ntpd, Chrony is a newcomer to the game of timekeeping.

Chrony is a set of programs that maintains the time on your computer using different time sources, such as NTP servers, your system's clock, and even custom-made scripts/programs. It also calculates the rate at which the computer loses or gains time to compensate while no external reference is present—for example, if your NTP server(s) is(are) down.

Chrony is a good solution for systems which are intermittently disconnected and reconnected to a network.

Ntpd should be considered for systems that are normally kept on permanently.

How to do it…

When talking about managing time in RHEL, it can be done through:

  • Chrony
  • Ntpd

We'll take a look at each of the methods separately.

Managing time through chrony

Ensure that chrony is installed and enabled, and perform the following steps:

  1. First, install chrony through the following command:
    ~]# yum install -y chrony
    
  2. Enable chrony, as follows:
    ~]# systemctl enable chrony
    ~]# systemctl start chrony
    
  3. Now, open /etc/chrony.conf with your favorite editor and look for lines starting with the server directive using the following commands:
    server 0.rhel.pool.ntp.org iburst
    server 1.rhel.pool.ntp.org iburst
    server 2.rhel.pool.ntp.org iburst
    server 3.rhel.pool.ntp.org iburst
  4. Next, replace these lines with NTP servers that are near you and save the file:
    server 0.pool.ntp.mydomain.lan iburst
    server 1.pool.ntp.mydomain.lan iburst

    The iburst option causes NTP to send a burst of eight packets at the next poll instead of just one if the time master is unavailable, causing the NTP daemon to speed up time synchronization.

  5. Finally, restart chrony by executing the following command:
    ~]# systemctl restart chrony
    

Managing time through ntpd

Ensure that ntpd is installed and enabled, and perform the following steps:

  1. First, install ntpd by running the following:
    ~]# yum install -y ntpd
    
  2. Enable ntpd through this command:
    ~]# systemctl enable ntpd
    
  3. Open /etc/ntp.conf with your favorite editor and look for the lines starting with the server directive. Run the following:
    server 0.rhel.pool.ntp.org iburst
    server 1.rhel.pool.ntp.org iburst
    server 2.rhel.pool.ntp.org iburst
    server 3.rhel.pool.ntp.org iburst
  4. Replace these lines with the NTP servers near you and save the file:
    server 0.pool.ntp.mydomain.lan iburst
    server 1.pool.ntp.mydomain.lan iburst
  5. Replace the contents of /etc/ntp/step-tickers with all your NTP servers, one per line:
    0.pool.ntp.mydomain.lan
    1.pool.ntp.mydomain.lan
  6. Now, restart ntpd by executing the following:
    ~]# systemctl restart ntpd
    

There's more…

While ntpd is the obvious choice for time synchronization, it doesn't fare well in environments where time masters are intermittently accessible (for whatever reason). In these environments, chronyd thrives. Also, ntpd can be quite complex to configure correctly, whereas chronyd is a little bit simpler.

The reason for modifying /etc/ntp/step-tickers when using the ntpd file is for the startup of the service. It uses ntpdate to synchronize time in one step before actually starting the NTP daemon itself, which is a lot slower in synchronizing time.

To figure out whether your system is synchronized, use the following command:

  • For chrony, use the following command:
    ~]# chronyc sources
    
  • For ntpd, run the following:
    ~]# ntpq -p
    

Your output will be similar to:

remote       refid      st t when poll reach   delay   offset  jitter
=====================================================================
 LOCAL(0)    .LOCL.      5 l  60m   64    0    0.000    0.000   0.000
*master.exam 178.32.44.208 3 u  35 128 377     0.214   -0.651  14.285

The asterisk (*) in front of an entry means that your system is synchronized to this remote system's clock.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset