Tuesday, July 2, 2013

NTP synchronization in linux

NTP time synchronization failed

[root@server1 ~]# /etc/init.d/ntpd status                                                        
ntpd (pid 32243) is running...                                                                  

[root@server1 ~]# chkconfig --list ntpd
ntpd            0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@server1 ~]# ntpdc
ntpdc> loopinfo      
offset:               0.000000 s
frequency:            -497.501 ppm
poll adjust:          30        
watchdog timer:       13 s      
ntpdc> exit                    

System peer seems to be local ntp didnot sync with the ntp server.

[root@server1 ~]# ntpdc -c sysinfo
system peer:          LOCAL(0)
system peer mode:     client
leap indicator:       00
stratum:              11
precision:            -20
root distance:        0.00000 s
root dispersion:      0.01141 s
reference ID:         [127.127.1.0]
reference time:       d563fabb.55ff4a47  Thu, Jun 13 2013  9:00:59.335
system flags:         auth monitor ntp kernel stats
jitter:               0.000000 s
stability:            0.000 ppm
broadcastdelay:       0.003998 s
authdelay:            0.000000 s


[root@server1 ~]# grep server /etc/ntp.conf
# Use public servers from the pool.ntp.org project.
#server 0.centos.pool.ntp.org
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org
server 107.22.5.68
#broadcast 192.168.1.255 key 42         # broadcast server
#broadcast 224.0.1.1 key 42             # multicast server
#manycastserver 239.255.254.254         # manycast server
server  127.127.1.0     # local clock

Edit the configuration file and change the contents like below

[root@server1 ~]# vi /etc/ntp.conf
You have new mail in /var/spool/mail/root

[root@server1 ~]# grep server /etc/ntp.conf
# Use public servers from the pool.ntp.org project.
server 0.centos.pool.ntp.org
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org
#server 107.22.5.68
#broadcast 192.168.1.255 key 42         # broadcast server
#broadcast 224.0.1.1 key 42             # multicast server
#manycastserver 239.255.254.254         # manycast server
server  127.127.1.0     # local clock

[root@server1 ~]# /etc/init.d/ntpd restart
Shutting down ntpd:                                        [  OK  ]
Starting ntpd:                                             [  OK  ]

[root@server1 ~]# ntpdate -u pool.ntp.org
13 Jun 09:05:34 ntpdate[20593]: adjust time server 128.113.28.67 offset -0.089041 sec

[root@server1 ~]# ntpdate -b pool.ntp.org                                          
13 Jun 09:05:42 ntpdate[20600]: the NTP socket is in use, exiting                

Synced only to the LOCAL

[root@server1 ~]# grep ntp /var/log/messages
Jun 13 09:06:03 server1 ntpd[20516]: synchronized to LOCAL(0), stratum 10
Jun 13 09:06:03 server1 ntpd[20516]: kernel time sync enabled 0001

[root@server1 ~]#

[root@server1 ~]# ntpdc
ntpdc> loopinfo
offset:               0.000000 s
frequency:            -497.501 ppm
poll adjust:          6
watchdog timer:       37 s
ntpdc> loopinfo
offset:               0.000000 s
frequency:            -497.501 ppm
poll adjust:          6
watchdog timer:       42 s
ntpdc> loopinfo
offset:               0.000000 s
frequency:            -497.501 ppm
poll adjust:          6
watchdog timer:       45 s
ntpdc> loopinfo
offset:               0.000000 s
frequency:            -497.501 ppm
poll adjust:          6
watchdog timer:       46 s
ntpdc> exit


Check the port 123 is opened . Since port 123 is a UDP , you can check it with nc command.

nc -zu destination ip 123

Here the * shows , it is now synced to the ntp server

[root@server1 ~]# ntpq

ntpq> pe

     remote           refid      st t when poll reach   delay   offset  jitter

==============================================================================

 lasvegas-nv-dat 72.8.140.240     3 u  11h 1024    0  140.810   -1.350   0.000

 38.117.195.101  .STEP.          16 u 505d 1024    0    0.000    0.000   0.000

*bindcat.fhsu.ed 128.138.140.44   2 u  361 1024  377  107.537    0.016   0.296

 LOCAL(0)        .LOCL.          10 l    1   64  377    0.000    0.000   0.001


ntpq> as


ind assID status  conf reach auth condition  last_event cnt

===========================================================

  1 25892  8053   yes   yes  none    reject  lost reach  5

  2 25893  8063   yes   yes  none    reject  lost reach  6

  3 25894  96f4   yes   yes  none  sys.peer   reachable 15

  4 25895  9044   yes   yes  none    reject   reachable  4

ntpq> rv

assID=0 status=06f4 leap_none, sync_ntp, 15 events, event_peer/strat_chg,

version="ntpd 4.2.2p1@1.1570-o Sat Dec 19 00:56:13 UTC 2009 (1)",

processor="x86_64", system="Linux/2.6.18-238.19.1.el5", leap=00,

stratum=3, precision=-20, rootdelay=131.707, rootdispersion=39.163,

peer=25894, refid=25.201.113.150,

reftime=d5814694.df62076d  Fri, Jul  5 2013 14:20:20.872, poll=10,

clock=d581480a.30d80bc0  Fri, Jul  5 2013 14:26:34.190, state=4,

offset=0.016, frequency=-50.345, jitter=0.296, noise=0.309,

stability=0.001, tai=0


Check the status of it using the below command.

[root@ server1~]# ntpstat

synchronised to NTP server (25.201.113.150) at stratum 3

   time correct to within 39 ms

   polling server every 1024 s

Now it is synced to the ntp server. 




No comments: