PDA

View Full Version : NTPD does not sync time


smilem
8th March 2008, 14:55
I'm running centos 5.1

My problem is that ntpd does not sync time. After I leave server running for a few days it starts to fall behind. IF I leave it for a week it a few days behind.

I fix it now by running

/etc/init.d/ntpd stop

ntpdate pool.ntp.org

/etc/init.d/ntpd start

I'm running this on vmware virtual system

How do I fix this?

jnsc
8th March 2008, 20:00
what is the output of ntpq and then peers

smilem
9th March 2008, 00:11
what is the output of ntpq and then peers

see attached file

falko
9th March 2008, 16:02
Please install the VMware Tools: http://www.howtoforge.com/vmware_tools_on_linux

jorizzzz
10th March 2008, 10:43
Falko,

Why should you install the vmware tools for this problem?! Aren't the vmware tools just enhancements for the GUI?

I've got the exact same problem and i've resolved it (temporarily) with a script that runs: ntpdate ntp.xs4all.nl every half hour. Not the best solution but it works for now.

smilem
10th March 2008, 15:38
Falko,

Why should you install the vmware tools for this problem?! Aren't the vmware tools just enhancements for the GUI?

I've got the exact same problem and i've resolved it (temporarily) with a script that runs: ntpdate ntp.xs4all.nl every half hour. Not the best solution but it works for now.

How can schedule it to do the same? Perhaps it is possible within ISPconfig admin interface

jorizzzz
10th March 2008, 15:44
I've just created the script below to do this:


#!/bin/bash


var0=0
LIMIT=100000000000

while [ "$var0" -lt "$LIMIT" ]
do
ntpdate ntp.xs4all.nl
sleep 108000
done

echo

exit 0

smilem
10th March 2008, 18:45
sorry if it sounds stupid but unless you can tell me where I need to put this file and how to make it run on schedule it makes no sense to me as I'm new to linux systems.

falko
11th March 2008, 21:33
Why should you install the vmware tools for this problem?! Aren't the vmware tools just enhancements for the GUI?

The VMware Tools fix the time problem in the vm.

smilem
14th March 2008, 22:58
Please install the VMware Tools: http://www.howtoforge.com/vmware_tools_on_linux

I use Centos 5.1 it is not in your guide.

falko
15th March 2008, 19:26
Try the instructions for Fedora.

smilem
18th March 2008, 13:28
Try the instructions for Fedora.

Are you sure it will work? Is a production server?

BTW any help on installing that script?

smilem
19th March 2008, 03:19
Using google I found that I need to save the script as text file and remove file extension.

Then I need to put it in my server (I use WinSCP for that)
/etc/cron.hourly

Then I need to set permissions to
0755

And that the script will run next time cron executes?
Is this right. Any help here would be great.

jorizzzz
19th March 2008, 09:36
OK, here is a small guide how to use the script. But if you are using Vmware, you should install the vmware tools.

1. Create and edit a file called ntpsync.sh

cd /usr/bin
touch ntpsync.sh
joe ntpsync.sh (use your favorite editor)


2. Paste the following code in the file

#!/bin/bash


var0=0
LIMIT=100000000000

while [ "$var0" -lt "$LIMIT" ]
do
ntpdate ntp.xs4all.nl
sleep 108000
done

echo

exit 0


3. Give the file executable flags

chmod +x ntpsync.sh


4. Run the file

./ntpsync.sh &



You don't have to put this file in crontab. There is a counter in the file that goed one up every time it runs, but the limit is so high that it won't ever stop. You can remove this counter, but i was too lazy :)

smilem
19th March 2008, 15:25
Is there a reason to run it every 30mins?

If I put it in /etc/cron.hourly and remove the counter it will run every hour right?

jorizzzz
19th March 2008, 15:27
Is there a reason to run it every 30mins?

If I put it in /etc/cron.hourly and remove the counter it will run every hour right?

Nope, not a particulair reason, and you can put it in your cron.hourly, that should work.

smilem
20th March 2008, 12:50
I created the script called ntpfix.sh

with code:


#!/bin/bash
ntpdate ntp.xs4all.nl

placed it in my /etc/cron.hourly

Then restearted the server and turned off ntpd with /etc/init.d/ntpd stop
To allow the script to run and when I after 6 hours or more do a manual
command ntpdate pool.ntp.org I get 10000 or 15000 sec that is not normal if the command is execuded automatically every hour like it shoud have.

jorizzzz
20th March 2008, 12:53
I created the script called ntpfix.sh

with code:


#!/bin/bash
ntpdate ntp.xs4all.nl

placed it in my /etc/cron.hourly

Then restearted the server and turned off ntpd with /etc/init.d/ntpd stop
To allow the script to run and when I after 6 hours or more do a manual
command ntpdate pool.ntp.org I get 10000 or 15000 sec that is not normal if the command is execuded automatically every hour like it shoud have.

In what timezone are you living? I'm using ntp.xs4all.nl because i live in the Netherlands... You can replace ntp.xs4all.nl with pool.ntp.org

smilem
20th March 2008, 21:55
My time zone is GMT+2

smilem
22nd March 2008, 21:37
I changed my script to pool.ntp.org and now it is working fine.
However how to I turn off autostart of ntpd so the script can run?

Now I have to stop it manually.

falko
23rd March 2008, 19:31
However how to I turn off autostart of ntpd so the script can run?

Try
chkconfig ntpd off