Wednesday, December 11, 2019

Maintain Time in RHEL 7 using chronyd

Setting time zone using timedatectl

The timedatectl command shows time related setting like current time,time zone and NTP synchronization setting of the system

[student@ServerX ~]$ timedatectl
      Local time: Thu 2019-12-12 06:11:34 AEDT
  Universal time: Wed 2019-12-11 19:11:34 UTC
        RTC time: Wed 2019-12-11 19:11:34
       Time zone: Australia/Sydney (AEDT, +1100)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2019-10-06 01:59:59 AEST
                  Sun 2019-10-06 03:00:00 AEDT
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2020-04-05 02:59:59 AEDT
                  Sun 2020-04-05 02:00:00 AEST

List time zones using the command "timedatectl list-timezones"
[student@ServerX ~]$ timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau

Set Time Zone using the command "timedatectl set-timezone Asia/Kolkata"

[root@ServerX ~]$ timedatectl set-timezone Asia/Kolkata


tzselect command is useful for identifying correct time zone names.It interactively prompts the user with question about the system's location and output the name of the correct time zone.
It doesn't make any changes to the time zone setting of the system.

[student@ServerX ~]$ tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
 1) Africa
 2) Americas
 3) Antarctica
 4) Arctic Ocean
 5) Asia
 6) Atlantic Ocean
 7) Australia
 8) Europe
 9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#? 5
Please select a country.
 1) Afghanistan           18) Israel                35) Palestine
 2) Armenia               19) Japan                 36) Philippines
 3) Azerbaijan            20) Jordan                37) Qatar
 4) Bahrain               21) Kazakhstan            38) Russia
 5) Bangladesh            22) Korea (North)         39) Saudi Arabia
 6) Bhutan                23) Korea (South)         40) Singapore
 7) Brunei                24) Kuwait                41) Sri Lanka
 8) Cambodia              25) Kyrgyzstan            42) Syria
 9) China                 26) Laos                  43) Taiwan
10) Cyprus                27) Lebanon               44) Tajikistan
11) East Timor            28) Macau                 45) Thailand
12) Georgia               29) Malaysia              46) Turkmenistan
13) Hong Kong             30) Mongolia              47) United Arab Emirates
14) India                 31) Myanmar (Burma)       48) Uzbekistan
15) Indonesia             32) Nepal                 49) Vietnam
16) Iran                  33) Oman                  50) Yemen
17) Iraq                  34) Pakistan
#? 14

The following information has been given:

        India

Therefore TZ='Asia/Kolkata' will be used.
Local time is now:      Thu Dec 12 00:50:32 IST 2019.
Universal Time is now:  Wed Dec 11 19:20:32 UTC 2019.
Is the above information OK?
1) Yes
2) No
#? 1

You can make this change permanent for yourself by appending the line
        TZ='Asia/Kolkata'; 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:
Asia/Kolkata

Setting date and time using timedatectl

set-time option of timedatectl is used to set the time manually.
The time may be specified in the format "2012-10-30 18:17:16"

[root@ServerX ~]# timedatectl set-time 2012-10-30 18:17:16

Enabling NTP Synchronization 

The set-ntp option enabled or disables NTP Synchronization for automatic time adjustment.

[root@ServerX ~]# timedatectl set-ntp true

chronyd daemon

chronyd daemon is used to synchronize time from the NTP pool project in RHEL7. 
ntpd daemon is used to  synchronize time in RHEL 5 and RHEL 6 and older version.

The quality of NTP time source is determined by the stratum value reported by the time source.
The stratum determines the number of hops the machine is away from the high performance reference clock.

High performance reference clock. - stratum 0
NTP server sync time from high performance reference clock - stratum 1
Machine sync time from NTP serverstratum 2

There are 2 category of time sources can be configured
server - one stratum above the local NTP server
peer - At the same stratum level of local NTP server

/etc/chrony.conf file is used to configure chronyd  daemon .

#Sync time from local server
server ntp.example.com iburst

It is recommended to use iburst option , because after service start , four measurement are taken in a short time period for a more accurate initial clock synchronization.

After changing the configuration reset the chronyd

[root@ServerX ]#systemcctl restart chronyd

The chronyc command acts as a client to the chronyd service.
We can use the command chronyc sources -v to verify server is syncing with which NTP server

[root@ServerX ~]# chronyc sources -v
210 Number of sources = 6

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- 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
===============================================================================
^* ntp.example.com              3   6   377    51   +102us[ +242us] +/-  636ms



No comments: