Solved

Fixing time drift

Posted on 2004-10-20
9
820 Views
Last Modified: 2013-12-06
Our servers info:
Red Hat 9
[foxadm@xxx foxadm]$ uname -a
Linux xxx.xxx.com 2.4.21 #1 SMP Wed Jun 16 15:36:44 EDT 2004 i686 i686 i386 GNU/Linux

One of our servers has been experiancing some serious time drift (about 30 minutes a day). the hardware clock is fine, its the system clock that seems to be drifting.

Ex. /usr/sbin/hwclock --systohc was run less than 24 hours ago:

[foxadm@xxx foxadm]$ date;/usr/sbin/hwclock
Wed Oct 20 12:04:06 EDT 2004
Wed 20 Oct 2004 11:49:49 AM EDT  -0.346284 seconds

I have a cron job running every 10 minutes to sync the system clock, but Im not sure I like this arangement.

I understand ther is a utility (adjtimex) for adjusting the timing in the kernel. Could someone provide some examples of how to use it or does anyone have any other advice on how to fix this problem?

TIA
0
Comment
Question by:squatex
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 2

Expert Comment

by:ITG-SSNA
ID: 12360491
Install and use rdate.

crontab -e

0 * * * * /usr/sbin/rdate -s time.mit.edu

(Or wherever your path is, try 'which rdate' to see if it is already installed)

Regards,

~K Black
Irvine, Ca.
0
 
LVL 4

Author Comment

by:squatex
ID: 12361303
Thats not really what im looking for. I can get the same results with hwclock as the hardware clock is keeping time correctly. I already have a cron job which does this. Im looking for a more elegant solution.
0
 
LVL 2

Expert Comment

by:ITG-SSNA
ID: 12361409
Well linux likes to sync up system time with CMOS before it changes it's runlevel at reboot.
Therefore I'd suspect this "more elegant solution" you are looking for might come in the form
of a new CMOS battery :)

~K Black
0
 
LVL 4

Author Comment

by:squatex
ID: 12362180
The CMOS battery has been changed. Its not the hardware clock thats incorrect. The CMOS keeps perfect time.  It's the system clock. If i were to reboot (i have) right now the system time would be correct....for a few minutes. After 15 minutes the system clock would be several seconds faster than the hardware clock (which is still correct).

Like I said before, I can correct this (by running hwclock --systohc every few minutes from a cron job to sysnc the system clock to hardware - this happens during init at every boot) but I am hoping to find a better solution.

There is a utility called adjtimex that adjusts the tick frequency and latency in the kernel. Im just not sure how to get it to fix my problem. I was hoping someone could provide me with some examples.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 5

Expert Comment

by:paranoidcookie
ID: 12362598
What you need is network time protocol, its really clever syncing to an atomic clock from the internet calculating the cmos clock drift so the results get better over time. It also make minor adjustments at a time so dosnt bugger up services like cryptography

http://www.ntp.org/

0
 
LVL 6

Expert Comment

by:blkline
ID: 12362607
What I would do is reset the time again (rdate -s clock.psu.edu;hwclock --systohc), then rm /etc/adjtime.  It may be that your  time was so skewed initially that the drift adjustment is totally out of whack.  

I've had this same problem before and I fixed it using those steps.
0
 
LVL 5

Expert Comment

by:paranoidcookie
ID: 12362620
As an added bonus you can put it on all your server and keep them all sychronised. I used to have massive problems using dns tsig until I started using ntp
0
 
LVL 23

Accepted Solution

by:
Mysidia earned 250 total points
ID: 12367287
I think you have the right idea with adjtimex
http://www.togaware.com/linux/survivor/Using_adjtimex.shtml

Debian and possibly some other distributions provide an  adjtimexconfig  program
to automatically adjust it to within the accuracy of your hardware clock.

Running  a ntp  aka xntp or some other similar package would help keep
the clock synchronized hopefully to within a second with a time server,
but only if the system is networked.

But it may not solve the problem very well.   It's not ideal to be needing major corrections
to the system time.   If your clock is drifting _that_ much, then I wouldn't say that resyncing
with crontab is ideal.

One possible concern of "patching" a bad system clock timing is it could effect other timed things going on in the system.. i.e. if a program uses the system time during execution as reported by the kernel (registering a negative or errorful total time difference between two points if there was a huge clock drift between synchronization times causing a sudden "jump" in the current system time).

0
 
LVL 5

Expert Comment

by:paranoidcookie
ID: 12367394
ntp will use the drift statists to help keep the system clock inline even if you lose networking. Plus if you have it running on multiple ervers at least they will sync to each other and after all that is the most important thing on the network that the servers are in time sync with each other as a lot of updates use time as a frame of reference.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
docker invalid registry name 2 107
Edit linux file using python 4 40
AWS CLI - Instances, Volumes & Tagging 2 75
Help on running oracle SQL script in linux 3 36
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now