Time Synchronization in Centos 7

Time Synchronization in Centos 7

NTP (English Network Time Protocol) – a network protocol for synchronizing the internal clock of a computer using networks with variable latency. The protocol was developed by David L. Mills, professor at the University of Delaware, in 1985.

Consider 2 utilities for time synchronization in Centos:

  • ntp / ntpdate
  • chroony

Time synchronization via ntp

Install software from the standard repository

[[email protected] ~]# yum install ntp ntpdate

Let’s sync manually

[[email protected] ~]# ntpdate 1.ru.pool.ntp.org
20 Dec 12:07:40 ntpdate[20628]: adjust time server 85.21.78.91 offset -0.000150 sec

To simply request the server and not set the clock, execute the ntpdate command with the following flags

[[email protected] ~]# ntpdate -qu 1.ru.pool.ntp.org
server 80.240.216.155, stratum 2, offset 0.000983, delay 0.02901
server 85.21.78.8, stratum 2, offset -0.000851, delay 0.02788
server 89.175.20.7, stratum 1, offset 0.000247, delay 0.02930
server 195.210.189.106, stratum 1, offset 0.000085, delay 0.03043
20 Dec 12:12:03 ntpdate[20717]: adjust time server 89.175.20.7 offset 0.000247 sec

To install the necessary time synchronization servers, let’s edit the ntp.conf file, and instead of the default servers, you can write the necessary

[[email protected] ~]# nano /etc/ntp.conf
...
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
...

We activate the NTP client and check the status

[[email protected] ~]# timedatectl set-ntp true 
[[email protected] ~]# timedatectl status
      Local time: Чт 2018-12-20 12:19:23 MSK
  Universal time: Чт 2018-12-20 09:19:23 UTC
        RTC time: Чт 2018-12-20 09:19:23
       Time zone: Europe/Moscow (MSK, +0300)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

To check the system clock, enter the date command

[[email protected] ~]# date
Чт дек 20 12:20:29 MSK 2018

Time synchronization via chroony

By default, in Centos 7 minimal, time synchronization is not configured.

[[email protected] ~]# timedatectl
      Local time: Чт 2018-12-20 12:00:35 MSK
  Universal time: Чт 2018-12-20 09:00:35 UTC
        RTC time: Чт 2018-12-20 08:59:21
       Time zone: Europe/Moscow (MSK, +0300)
     NTP enabled: n/a
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

Install software from the standard repository

[[email protected] ~]# yum install chrony

To change the time synchronization servers, you need to edit the /etc/chrony.conf file

[[email protected] ntp]# nano /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst

We start the service and add it to startup

[[email protected] ~]# systemctl start chronyd
[[email protected] ~]# systemctl enable chronyd

We look at the status

[[email protected] ~]# chronyc sources
210 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample               
===============================================================================
^* bagnikita.com                 2   6    17     1   -401us[ -730us] +/-   26ms
^+ lhr1.m-d.net                  2   6    17     0   +600us[ +600us] +/-   64ms
^- tor-relais2.link38.eu         2   6    17     1   +392us[ +392us] +/-   34ms
^- ntp.truenetwork.ru            2   6    17     2   -228us[ -558us] +/-  104ms

Check if sync is activated

[[email protected] ~]# timedatectl
      Local time: Чт 2018-12-20 12:01:28 MSK
  Universal time: Чт 2018-12-20 09:01:28 UTC
        RTC time: Чт 2018-12-20 09:01:28
       Time zone: Europe/Moscow (MSK, +0300)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a
Sidebar