LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can I permanently fix my clock synchronization problem? (http://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-permanently-fix-my-clock-synchronization-problem-797783/)

gr33d 03-25-2010 08:25 AM

How can I permanently fix my clock synchronization problem?
 
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.

Thanks in advance!

nuwen52 03-25-2010 08:39 AM

Try running an ntp server. It will keep your own clocked sync'd and you can set it to not serve any other computers. It can account for drift rates in your system clock by adjusting it's own update times and driftrate calculations. Also, the newer versions are fairly easy to configure.

gr33d 03-25-2010 08:41 AM

that sounds like a good idea. ill read up and let you know

nuwen52 03-25-2010 08:46 AM

Something I did forget to mention. If it's on a server which reboots often and may loose time in the time it's off, you can use ntpdate on boot to do the initial sync before starting the ntpd. This is a good idea since ntpd doesn't like to sync up if the time is too different from what it should be.

I do this on my home servers.

gr33d 03-25-2010 08:48 AM

this server is only reboot under extreme troubleshooting circumstances. thats why i was hoping to avoid the cmos battery since that has to be done when powered off, correct?

how can i run commands on boot?

catkin 03-25-2010 08:50 AM

Quote:

Originally Posted by gr33d (Post 3911646)
I have read about CMOS battery problems, but what if this does not fix it?

The CMOS battery is only used to keep the clock going when the system is powered down. While the system is running Linux keeps its own time (presumably in a hardware device). Boot and shutdown messages confirm this when they say something like "Setting time from hardware clock" and "Saving time to hardware clock"

If your time is changing while the system is running (more than a slight drift) then you either have a hardware problem or something is changing it.

sreeharsha.t 03-25-2010 08:53 AM

Quote:

Originally Posted by gr33d (Post 3911675)
how can i run commands on boot?

You have to modify the system initializing scripts. To run ntpdate before running the ntpd. Change the file (/etc/init.d/ntpd probably) to include a line to run ntpdate just before ntpd is acutally run.

nuwen52 03-25-2010 08:55 AM

Quote:

how can i run commands on boot?
This depends on the system that you run. There are a few different ways to run commands on boot. On redhat based systems, you could add a script into the /etc/rc.d/init.d/scripts and then call it from the various runtime directories. Gentoo is different from that. Ubuntu, I don't know, but that question can probably be easily searched from google or on the boards here.

sreeharsha.t 03-25-2010 08:58 AM

Ubuntu uses Upstream startup scripts which are slightly different from the Sys V Init Scripts.

catkin 03-25-2010 09:14 AM

Quote:

Originally Posted by nuwen52 (Post 3911683)
Ubuntu, I don't know, but that question can probably be easily searched from google or on the boards here.

On ubuntu 8.04 I had to install the ntp package (done via Synaptic) then used System->Admin->"Time + Date" to set time zone and enter time server names. Time server names are best chosen from the country lists at http://www.pool.ntp.org/en/use.html (or continent if you live in a country with inadequate time servers).

This didn't seem to work, though; inspecting /etc/ntp.conf showed ntp.ubuntu.com had gone but the new ones had not appeared.

After adding the missing servers manually to the end of /etc/ntp.conf like this
Code:

server in.pool.ntp.org
server asia.pool.ntp.org

and rebooting (not the fastest way but works and is easy) /var/log/daemon.log showed ntpdate and ntpd activity. It can take several minutes for ntpd to synchronise -- hey, it's got the time!

AFAIK NTP is started by the /etc/init.d/networking script and you don't need to do anything after installing and configuring it to have it stated at boot.

catkin 03-25-2010 09:17 AM

Quote:

Originally Posted by sreeharsha.t (Post 3911687)
Ubuntu uses Upstream startup scripts which are slightly different from the Sys V Init Scripts.

Do you mean Upstart? The SysVinit mechanism was still in use, parallel to the few bits of Upstart in 8.04; I imagine there was less Upstart in 7.10.

gr33d 03-29-2010 03:06 PM

the ntp server seems to be doing the trick. thanks for your help!


All times are GMT -5. The time now is 04:16 AM.