Bookmark this page

Guided Exercise: Maintain Accurate Time

Adjust the time zone on a server and ensure that its system clock is synchronized with an NTP time source.

Outcomes

  • Change the time zone on a server.

  • Configure the server to synchronize its time with an NTP time source.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command prepares your environment and ensures that all required resources are available.

[student@workstation ~]$ lab start logs-maintain

Instructions

  1. Log in to the servera machine as the student user.

    [student@workstation ~]$ ssh student@servera
    ...output omitted...
    [student@servera ~]$
  2. For this exercise, pretend that the servera machine is relocated to Haiti and that you need to update the time zone. Elevate the privileges of the student user to run the timedatectl command to update the time zone.

    1. Select the appropriate time zone for Haiti.

      [student@servera ~]$ tzselect
      Please identify a location so that time zone rules can be set correctly.
      Please select a continent, ocean, "coord", or "TZ".
       1) Africa
       2) Americas
       3) Antarctica
       4) Asia
       5) Atlantic Ocean
       6) Australia
       7) Europe
       8) Indian Ocean
       9) Pacific Ocean
      10) coord - I want to use geographical coordinates.
      11) TZ - I want to specify the timezone using the Posix TZ format.
      #? 2
      Please select a country whose clocks agree with yours.
       1) Anguilla		  19) Dominican Republic    37) Peru
       2) Antigua & Barbuda	  20) Ecuador		    38) Puerto Rico
       3) Argentina		  21) El Salvador	    39) St Barthelemy
       4) Aruba		  22) French Guiana	    40) St Kitts & Nevis
       5) Bahamas		  23) Greenland		    41) St Lucia
       6) Barbados		  24) Grenada		    42) St Maarten (Dutch)
       7) Belize		  25) Guadeloupe	    43) St Martin (French)
       8) Bolivia		  26) Guatemala		    44) St Pierre & Miquelon
       9) Brazil		  27) Guyana		    45) St Vincent
      10) Canada		  28) Haiti		    46) Suriname
      11) Caribbean NL	  29) Honduras		    47) Trinidad & Tobago
      12) Cayman Islands	  30) Jamaica		    48) Turks & Caicos Is
      13) Chile		  31) Martinique	    49) United States
      14) Colombia		  32) Mexico		    50) Uruguay
      15) Costa Rica		  33) Montserrat	    51) Venezuela
      16) Cuba		  34) Nicaragua		    52) Virgin Islands (UK)
      17) Curaçao		  35) Panama		    53) Virgin Islands (US)
      18) Dominica		  36) Paraguay
      #? 28
      
      The following information has been given:
      
      	Haiti
      
      Therefore TZ='America/Port-au-Prince' will be used.
      Selected time is now:	Wed Mar 16 07:10:35 EDT 2022.
      Universal Time is now:	Wed Mar 16 11:10:35 UTC 2022.
      Is the above information OK?
      1) Yes
      2) No
      #? 1
      
      You can make this change permanent for yourself by appending the line
      	TZ='America/Port-au-Prince'; export TZ
      to the file '.profile' in your home directory; then log out and log in again.
      
      Here is that TZ value again, this time on standard output so that you
      can use the /usr/bin/tzselect command in shell scripts:
      America/Port-au-Prince
    2. Update the time zone on the servera machine to America/Port-au-Prince.

      [student@servera ~]$ sudo timedatectl set-timezone \
      America/Port-au-Prince
      [sudo] password for student: student
    3. Verify that you correctly set the time zone to America/Port-au-Prince.

      [student@servera ~]$ timedatectl
                     Local time: Wed 2022-03-16 07:13:25 EDT
                 Universal time: Wed 2022-03-16 11:13:25 UTC
                       RTC time: Wed 2022-03-16 11:13:24
                      Time zone: America/Port-au-Prince (EDT, -0400)
      System clock synchronized: no
                    NTP service: inactive
                RTC in local TZ: no
  3. Configure the chronyd service on the servera machine to synchronize the system time with the classroom.example.com server as the NTP time source.

    1. Edit the /etc/chrony.conf configuration file to specify the classroom.example.com server as the NTP time source. The following output shows the configuration line to add to the configuration file, which includes the iburst option to speed up initial time synchronization:

      ...output omitted...
      server classroom.example.com iburst
      ...output omitted...
    2. Enable time synchronization on the servera machine. The command activates the NTP server with the settings from the /etc/chrony.conf configuration file. That command might activate either the chronyd or the ntpd service, depending on which service is currently installed on the system.

      [student@servera ~]$ sudo timedatectl set-ntp true
  4. Verify that the servera machine configuration synchronizes with the classroom.example.com time source in the classroom environment.

    1. Verify that time synchronization is enabled on the servera machine.

      Note

      If the output shows that the clock is not synchronized, then wait for a few seconds and rerun the timedatectl command. It takes a few seconds to successfully synchronize the time settings with the time source.

      [student@servera ~]$ timedatectl
                     Local time: Wed 2022-03-16 07:24:13 EDT
                 Universal time: Wed 2022-03-16 11:24:13 UTC
                       RTC time: Wed 2022-03-16 11:24:13
                      Time zone: America/Port-au-Prince (EDT, -0400)
      System clock synchronized: yes
                    NTP service: active
                RTC in local TZ: no
    2. Verify that the servera machine currently synchronizes its time settings with the classroom.example.com time source.

      The output shows an asterisk character (*) in the source state (S) field for the classroom.example.com NTP time source. The asterisk indicates that the local system time successfully synchronizes with the NTP time source.

      [student@servera ~]$ chronyc sources -v
      
        .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
       / .- Source state '*' = current best, '+' = combined, '-' = not combined,
      | /             'x' = may be in error, '~' = too variable, '?' = unusable.
      ||                                                 .- xxxx [ yyyy ] +/- zzzz
      ||      Reachability register (octal) -.           |  xxxx = adjusted offset,
      ||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
      ||                                \     |          |  zzzz = estimated error.
      ||                                 |    |           \
      MS Name/IP address         Stratum Poll Reach LastRx Last sample
      ===============================================================================
      ^* 172.25.254.254                2   6   377    33    +84us[ +248us] +/-   21ms
    3. Return to the workstation system as the student user.

      [student@servera ~]$ exit
      logout
      Connection to servera closed.
      [student@workstation ~]$

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish logs-maintain

Revision: rh199-9.3-8dd73db