Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I installed Centos onto my server and I noticed that when I compared the date command's output to (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 Nov 25 '11 at 21:32

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

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.

which points to the Ubuntu pool.

share|improve this answer
i followed this tutorial 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
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
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
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

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

share|improve this answer
yum install ntp
echo server > /etc/ntp.conf
echo server >> /etc/ntp.conf
echo server >> /etc/ntp.conf
echo server >> /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

You must log in to answer this question.