Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I installed Centos onto my server and I noticed that when I compared the date command's output to time.gov (same timezones, of course), the output was 4 minutes behind. This also affects my timestamps in MySQL so this is an annoying problem.

Is there some way to permanently fix this so that even after the server reboots, the current time is correct?

share|improve this question

migrated from stackoverflow.com Nov 25 '11 at 21:32

This question came from our site for professional and enthusiast programmers.

add comment

3 Answers

Yes, there is -- you need to sync your system time with the external time servers. A high-end solution is to run ntp, a simpler solution is to just call ntpclient, or ntpdate.

Watch out that because too many Linux machines were hitting the same time servers, there are now some per-distro wrappers. E.g. on an Ubuntu machine here I have this in /etc/crontab:

03,23,43 *    * * *   root    ntpdate-debian -s

where ntpdate-debian has this in its manual page:

ntpdate-debian is identical to ntpdate(8) except that it uses the configuration in /etc/default/ntpdate by default. ntpdate sets the local date and time by polling Network Time Protocol (NTP) servers.

and then in /etc/default/ntpdate we see

# List of NTP servers to use  (Separate multiple servers with spaces.)
# Not used if NTPDATE_USE_NTP_CONF is yes.
NTPSERVERS="ntp.ubuntu.com"

which points to the Ubuntu pool.

share|improve this answer
    
i followed this tutorial cyberciti.biz/faq/howto-install-ntp-to-synchronize-server-clock and got the service working. This the ntp installation already configure it so that ntp starts on boot? –  Andrew Park Nov 25 '11 at 21:31
    
I don't know, you have to check your package docs, or inquire with someone who knows RH/FC/CentOs better. Sometimes installing a package prepares everything yet you may to turn a toggle in a file such as /etc/default/ntpdate. –  Dirk Eddelbuettel Nov 25 '11 at 22:13
1  
I would never, ever suggesting running ntpdate on a schedule like that. If your clock is fast, you will be jumping your clock backwards three times an hour. If two events span such a jump and log to different files, it will be impossible to tell which happened first. –  David Schwartz Nov 25 '11 at 23:59
1  
Perhaps you just lucked out and your home system's clock isn't fast. In any event, the OP is specifically concerned about log files and this solution completely destroys the usefulness of log files and timestamps by not ensuring that the time always increases. –  David Schwartz Nov 26 '11 at 0:26
1  
You mentioned NTP, but you (at least implicitly) recommended against it. In fact, for his case, your preferred solution is a very bad solution, because it has a 50% chance of not providing monotonic time -- he's specifically concerned about timestamps. Non-monotonic time and timestamps don't mix. You steered the OP to a solution that has a 50% chance of appearing to work but actually creating much more serious problems for him. –  David Schwartz Nov 26 '11 at 3:10
show 2 more comments

Install ntp. Or as a temporary fix run ntpdate pool.ntp.org in a terminal.

share|improve this answer
add comment
yum install ntp
echo server 0.north-america.pool.ntp.org > /etc/ntp.conf
echo server 1.north-america.pool.ntp.org >> /etc/ntp.conf
echo server 2.north-america.pool.ntp.org >> /etc/ntp.conf
echo server 3.north-america.pool.ntp.org >> /etc/ntp.conf
chkconfig ntpd on
/etc/init.d/ntpd start

Just replace north-america with a more local region/country from the NTP pool

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.