How can I permanently fix my date synchronize problem in linux?

22,000

Solution 1

The advice about running ntpdate is good, but it'll only step your time. A better option is to install ntpd and use it to keep the local clock synchronised, avoiding skewed logs.

With Ubuntu you should just be able to do apt-get install ntp. That should install ntpdate and ntpd, configure them to use ntp.ubuntu.com as the only server and synchronise time. For completeness you'll want to add other NTP servers (eg 0.pool.ntp.org, 1.pool.ntp.org and 2.pool.ntp.org).

Solution 2

I had the same problem yesterday but under Slackware 8. To make a long story short, I read a lot on google to finally reimage the computer. My manager sent me that link but it did not fixed my issue.

I changed the local to UTC time. I changed the timezome to have the good one I ln both.

Hope this will help you!

Also, you can try this:

ntpdate 0.pool.ntp.org
hwclock --systohc

Solution 3

I had the same trouble on a Debian Lenny system (it was an ancient Ubuntu 7.04 install prior to that) due to some flaky chipset on the decade-old motherboard. Here's my cron solution; for my purposes, twice daily keeps it sufficiently sync'd, and then once weekly it syncs and saves to the hardware clock (which is rock solid on my system).

Put this in /etc/cron.d/ntpsync:

# /etc/cron.d/ntpsync: run ntpdate-debian twice daily, sync hwclock once weekly

# run at 11:23 (am & pm) (update system clock)
23 11,23        * * *   root    test -x /usr/sbin/ntpdate-debian && /usr/sbin/ntpdate-debian  2>&1 | logger -i

# run at 11:59pm fridays (update system clock & save to hwclock)
59 23   * * 5   root    test -x /usr/sbin/ntpdate-debian && test -x /etc/init.d/hwclock.sh && /usr/sbin/ntpdate-debian && /etc/init.d/hwclock.sh restart 2>&1 | logger -i

This uses the standard crontab syntax for setting times and days, so it can get minutely if you want it that fine-grained. The "logger -i" at the end of the command chain sends the output to syslog's cron logging facilities.

Share:
22,000
David Fox
Author by

David Fox

Updated on September 17, 2022

Comments

  • David Fox
    David Fox almost 2 years

    Ubuntu 7.10 server i386 clock/date/time won't stay in sync. Are their log files I can view to tell when the clock changes? For a temporary fix, I created a file in /etc/cron.hourly:

    #!/bin/sh
    ntpdate time.nist.gov
    

    However, this still leaves a potential hour of unchecked time. Is there a cron.minutely? That would still leave a potential minute of unchecked time. I have read about CMOS battery problems, but what if this does not fix it? I'd like to be able to troubleshoot this as a completely software problem.

    My squid logs are showing dates back in 2005 when the clock changes, and my time-sensitive access controls are skewed and end up allowing users to surf prohibited websites during business hours.

  • David Fox
    David Fox over 14 years
    can you explain how this would work?
  • Gnutt
    Gnutt over 14 years
    It's super-important to remember to use two (2) ">" sings before /etc/crontab, if you do like I did, and start with one... you overwrite the file /etc/crontab with just the new line, instead of adding it do the end.
  • Satanicpuppy
    Satanicpuppy over 14 years
    +1 Ntpd is what the pros use. Though you can run cron at any time down to the second. The benefit of ntpd is that the time change isn't instantaneous. It changes the time to match the real time over a short period, so things that were scheduled don't get skipped, or run erratically.
  • Satanicpuppy
    Satanicpuppy over 14 years
    Just do "crontab -e" to open it in an editor. Scripting stuff into your crontab isn't really something you want to do on a regular basis: it makes the file messy and hard to read (as well as potentially over-writing it if you miss your >).
  • Dennis Williamson
    Dennis Williamson over 14 years
    The package name for the ntp daemon and utilities on my Ubuntu 9.10 system is "ntp" rather than "ntpd".
  • DrColossos
    DrColossos over 14 years
    If the clock is wrong by "too much" (more than an hour?) then ntpd will give up and not sync the clock. It might still be a good idea to do ntpdate when the system boots up, and then ntpd will keep the clock correct from that point forward.
  • Cry Havok
    Cry Havok over 14 years
    The Ubuntu package uses the -g flag by default, which allows ntpd to accept any time difference at startup only. It will step the time if it's over 128 ms, slew otherwise.
  • David Fox
    David Fox about 14 years
    thanks, i monitored for about 5 hours this morning. seems to be working. had to upgrade to 8.04.4 LTS to install. system had not been maintained in awhile :)