NTPD does not sync time

Discussion in 'Installation/Configuration' started by smilem, Mar 8, 2008.

  1. smilem

    smilem New Member

    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?
     
  2. jnsc

    jnsc rotaredoM Moderator

    what is the output of
    Code:
    ntpq
    and then
    Code:
    peers
     
  3. smilem

    smilem New Member

    see attached file
     

    Attached Files:

    • ntpq.PNG
      ntpq.PNG
      File size:
      4.7 KB
      Views:
      1,819
  4. falko

    falko Super Moderator ISPConfig Developer

  5. jorizzzz

    jorizzzz New Member

    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.
     
  6. smilem

    smilem New Member

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

    jorizzzz New Member

    I've just created the script below to do this:

    Code:
    #!/bin/bash
    
    
    var0=0
    LIMIT=100000000000
    
    while [ "$var0" -lt "$LIMIT" ]
    do
    ntpdate ntp.xs4all.nl
    sleep 108000
    done
    
    echo
    
    exit 0
    
     
  8. smilem

    smilem New Member

    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.
     
  9. falko

    falko Super Moderator ISPConfig Developer

    The VMware Tools fix the time problem in the vm.
     
  10. smilem

    smilem New Member

  11. falko

    falko Super Moderator ISPConfig Developer

    Try the instructions for Fedora.
     
  12. smilem

    smilem New Member

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

    BTW any help on installing that script?
     
  13. smilem

    smilem New Member

    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.
     
  14. jorizzzz

    jorizzzz New Member

    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
    Code:
    cd /usr/bin
    touch ntpsync.sh
    joe ntpsync.sh (use your favorite editor)
    
    2. Paste the following code in the file
    Code:
    #!/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
    Code:
    chmod +x ntpsync.sh
    
    4. Run the file
    Code:
    ./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 :)
     
  15. smilem

    smilem New Member

    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?
     
  16. jorizzzz

    jorizzzz New Member

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

    smilem New Member

    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.
     
  18. jorizzzz

    jorizzzz New Member

    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
     
  19. smilem

    smilem New Member

    My time zone is GMT+2
     
  20. smilem

    smilem New Member

    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.
     

Share This Page