Skip to content

Instantly share code, notes, and snippets.

@jdeathe
Last active May 21, 2019 19:02
Show Gist options
  • Save jdeathe/289af6ab1bc76e7a5cd097389d697989 to your computer and use it in GitHub Desktop.
Save jdeathe/289af6ab1bc76e7a5cd097389d697989 to your computer and use it in GitHub Desktop.
Keeping Time with Chrony on CentOS

CentOS - Keeping Time with Chrony

Both CentOS-6 and CentOS-7 provide chrony as an alternative to the traditional ntp service. Chrony is a good fit for virtualised guests - a Vagrant box using the VirtualBox provider where you don't have/want the VirtualBox Guest Additions installed on the guest.

Installation

First install the chrony package with yum.

# yum -y install chrony

Virtual Guest Configuration

For a Virtual Guest where the host can be powered off, hibernated or put into sleep mode (i.e a laptop) such that the virtual guest is suspended and resumed frequently it's necessary to configure chrony to allow it to make step changes at any time. Usually, you only want to make step changes during the initial few updates to correct large time drifts and then small corrections are made gradually to stop sudden changes in system time affecting running applications/services.

With the following command step changes can be made by chrony whenever the system time is off by more than 1 second.

# sed -r -i \
  -e 's~^(makestep )[0-9\.]+ (-)?[0-9]+$~\11 -1~' \
  /etc/chrony.conf

Set chronyd to Run on Startup

CentOS-6

# chkconfig chronyd on

CentOS-7

# systemctl enable chronyd

Start the chronyd Service

CentOS-6

# service chronyd start

CentOS-7

Note: If chronyd was running before making changes to the configuration, run the following to make the changes reflect in timedatectl.

# systemctl restart systemd-timedated

The chronyd service can be started by toggling the timedatectl set-ntp command.

# timedatectl set-ntp no \
  && timedatectl set-ntp yes

Verification

CentOS-6

$ chronyc tracking

CentOS-7

$ chronyc tracking

And

$ timedatectl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment