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.
First install the chrony
package with yum
.
# yum -y install chrony
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
# chkconfig chronyd on
# systemctl enable chronyd
# service chronyd start
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
$ chronyc tracking
$ chronyc tracking
And
$ timedatectl