7

I have a few dedicated servers and for some reason they are totally unable to mantain the time properly synchronized, every few days they start having differences of minutes in the clock. So I have to manually open Putty, connect, login, and run the ntpdate -u 0.ar.pool.ntp.org command on each of them.

Since there's no way I can do this every day because I'm quite busy, the question is exactly how can I create some kind of cron that auto-runs this command every day on each server. I have full root access to all servers, they have CentOs and DirectAdmin. Thanks.-

andreszs
  • 709
  • 1
  • 6
  • 16

2 Answers2

16

No need to use cron for this task. Much better to install and configure ntpd (special daemon for continuous time sync).

  1. sudo yum install ntp
  2. sudo chkconfig ntpd on
  3. sudo nano /etc/ntp.conf
  4. you are from Argentina, right? comment/remove all the default CentOS ntp servers, you can add your own time-servers for Argentina, for example

    server 0.ar.pool.ntp.org
    server 1.south-america.pool.ntp.org
    server 0.south-america.pool.ntp.org
    
  5. After you are done with the configuration, just start the ntp service: sudo service ntpd start

  6. To check if the NTP service is synchronizing:

    sudo ntpq -pn
    sudo tail -f /var/log/messages
    
cadmi
  • 6,858
  • 1
  • 16
  • 22
  • In fact, ntp-date is just a stripped-down version of NTPD, used for one-shot sync. – Alba Mendez Apr 01 '13 at 17:10
  • Thanks, but on one of the servers this didn't work, this is the tail result:Apr 1 21:46:37 v ntpd[3761]: Listening on interface eth1, 10.0.0.5#123 Enabled Apr 1 21:46:37 v ntpd[3761]: kernel time sync status 0040 Apr 1 21:46:37 v ntpd[3761]: getaddrinfo: "::1" invalid host address, ignored Apr 1 21:46:37 v kernel: megasr[ahci]: unable to retreive proper sense data Apr 1 21:47:56 v kernel: ip_conntrack: table full, dropping packet. Apr 1 21:47:58 v kernel: megasr[ahci]: unable to retreive proper sense data Apr 1 21:48:30 v last message repeated 105 times – andreszs Apr 02 '13 at 00:55
  • @Andrew, is was the 1st of April, nevermind – poige Apr 02 '13 at 05:34
  • The only caution I'd add is that I consider ntpd's access restriction behavior pretty obtuse. http://support.ntp.org/bin/view/Support/AccessRestrictions#Section_6.5.1.2 has flow chart documentation for locking it down. Nice if you have a firewall, a potential mandate if you don't. – astrostl Apr 02 '13 at 19:51
7

Instead of using ntpdate which resets time hardly at once, consider using NTP daemon (ntp packet). It slows down or fastens system clock to match NTP-server.

gevial
  • 1,264
  • 8
  • 13