2

Is there any way to sync hardware clock periodically when server is syncing with NTP server? i am using Centos 6.7. Following is my ntp.conf file content

# File for including partners custom ntp configurations
leapfile "/etc/ntp/leap-seconds.list"


# Permit general access to this service.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1

# Replacement for the Undisciplined Local Clock. Allows a
# group of ntpds to autonomously select a leader in the
# event that all real time sources become unreachable.
tos orphan 10

# NTP Drift file.
# Put this in a directory to which the daemon can write.
# No symbolic links allowed, either, since daemon renames.
driftfile /var/lib/ntp/drift

# Key file containing the keys and key identifiers used
# when operating with symmetric key cryptography.
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8
server  127.127.1.0      # local clock
server x.x.x.x
HBruijn
  • 77,029
  • 24
  • 135
  • 201
Guru
  • 21
  • 1
  • 3
  • 1
    That's already the default kernel behavior when a NTP daemon is active, isn't it? – user1686 Feb 23 '16 at 16:24
  • Saving the clock to the hardware clock during suspend/shutdown should be sufficient -- nothing looks at the hardware clock anyway while the system is running. If your server typically resets without being shut down properly, that is something you need to address separately. – Simon Richter Feb 23 '16 at 17:01

2 Answers2

5

You could try the following in root's crontab:

1 0 * * *  /usr/sbin/hwclock --systohc

which will sync it daily, just after midnight; don't forget the --utc flag if your motherboard clock is in UTC. If your hardware clock is drifting so fast that it needs correction more than once a day, you may have bigger problems!

MadHatter
  • 79,770
  • 20
  • 184
  • 232
2

Typically RHEL and CentOS sync the hardware clock from the system time during graceful reboot and shutdown from the ntpdate init script already.

Nothing stops you from doing so slightly more often by calling /sbin/hwclock --systohc from a cron job.

HBruijn
  • 77,029
  • 24
  • 135
  • 201