1

The time on my server is about 19 hours behind and I cannot for the life of me figure out how to synchronize it. I did follow the steps here, and this is the output:

[root@ip-72-167-39-231 ~]# /sbin/service ntpd stop
Shutting down ntpd:                                        [  OK  ]
[root@ip-72-167-39-231 ~]# /usr/sbin/ntpdate 0.pool.ntp.org
25 Oct 08:42:32 ntpdate[22173]: adjust time server 199.4.29.166 offset 0.034126 sec
[root@ip-72-167-39-231 ~]# clock
Mon 24 Oct 2011 01:43:18 PM MST  -0.344112 seconds
[root@ip-72-167-39-231 ~]# /usr/sbin/ntpdate nist1-ny.ustiming.org
25 Oct 08:44:41 ntpdate[22180]: adjust time server 64.90.182.55 offset -0.002749 sec
[root@ip-72-167-39-231 ~]# clock
Mon 24 Oct 2011 01:45:24 PM MST  -0.593604 seconds

In response to suggestions in the comments:

[root@ip-72-167-39-231 ~]# ntpdate -u tick.usno.navy.mil
25 Oct 09:00:40 ntpdate[22294]: adjust time server 192.5.41.40 offset 0.111328 sec

[root@ip-72-167-39-231 ~]# clock
Mon 24 Oct 2011 02:00:46 PM MST  -0.140884 seconds
[root@ip-72-167-39-231 ~]# date
Tue Oct 25 09:01:10 MST 2011

[root@ip-72-167-39-231 ~]# TZ=Z date
Tue Oct 25 16:01:20  2011
[root@ip-72-167-39-231 ~]#

Yet more...

[root@ip-72-167-39-231 zoneinfo]# ln -s /usr/share/zoneinfo/America/New_York /etc/localtime
[root@ip-72-167-39-231 zoneinfo]# clock
Mon 24 Oct 2011 05:17:24 PM EDT  -0.270220 seconds

[root@ip-72-167-39-231 zoneinfo]# export TZ=America/New_York
[root@ip-72-167-39-231 zoneinfo]# clock
Mon 24 Oct 2011 05:21:42 PM EDT  -0.656424 seconds

I wouldn't care, but email that is sent right now is showing up on clients as if it was sent yesterday afternoon...

Thomas Thorogood
  • 211
  • 2
  • 13

2 Answers2

4

On any normal *nix system, ntpdate -u tick.usno.navy.mil should set the clock correctly.

If your timezone settings are off, the date command will still return the wrong "local time".

Chris S
  • 77,337
  • 11
  • 120
  • 212
  • 25 Oct 09:00:40 ntpdate[22294]: adjust time server 192.5.41.40 offset 0.111328 sec [root@ip-72-167-39-231 ~]# clock Mon 24 Oct 2011 02:00:46 PM MST -0.140884 seconds – Thomas Thorogood Oct 25 '11 at 16:00
  • Your timezone settings are off, but the server has the correct UTC time. Running `date -u` should confirm this. It should return "Tue Oct 25 16:03:14 UTC 2011" as of a few seconds ago. – Chris S Oct 25 '11 at 16:02
  • Okay. But I still do not know how to update it. – Thomas Thorogood Oct 25 '11 at 16:08
  • date -u returns the correct time; how do I update "clock" so that it's accurate? – Thomas Thorogood Oct 25 '11 at 16:08
  • 1
    http://www.cyberciti.biz/faq/howto-linux-unix-change-setup-timezone-tz-variable/ basically `ln /usr/share/zoneinfo/[TZ_Code] /etc/localtime` (Note: /etc/localtime probably already exists and is linked to something wrong). – Chris S Oct 25 '11 at 16:08
  • That did not solve the issue, either. Tried changing it to NY (so it would be the same time zone as me). Output is above. – Thomas Thorogood Oct 25 '11 at 16:18
  • @ChrisS Why not pool.ntp.org? Just curious ... – Joseph Kern Oct 25 '11 at 16:25
  • 1
    @JosephKern They're quite reliable, but the Navy is more; for one off syncs I commonly use tick. For any recurring polling I would always recommend using several of the pool servers. – Chris S Oct 25 '11 at 17:30
2

Try the following:

ntpdate -u pool.ntp.org
hwclock --adjust
hwclock --systohc

This will update your time settings from pool.ntp.org, adjust your hwclock for systematic drift, and then sync your hardware clock to your system clock. man page for hwclock

If you run these commands on a VM host this may adversely affect all of the VM guests and their ability to display the correct time. Plan accordingly.

Although I don't know if the hwclock -s will do anything on the VM guest ... I am going to guess no.

Joseph Kern
  • 9,809
  • 3
  • 31
  • 55