standalone ntpd não pisa tempo

0

O programa ntpdate foi preterido anos atrás. Estou tentando fazer a transição do código antigo de ntpdate para o ntpd autônomo. O objetivo é confiar no serviço ntp (executado com -g) para disciplinar o relógio, mas permitir uma sincronização de tempo forçada com script se o relógio estiver significativamente errado (devido, talvez, ao tempo prolongado mas temporário incapacidade do daemon ntp para acessar os servidores de horário) e o daemon não consegue consertá-lo.

service ntp stop
ntpd -gq
service ntp start

No momento, estamos usando ntpdate para essa finalidade, sem problemas. Esperamos que "ntpd -gq" sincronize o tempo, independentemente do tamanho da discrepância de tempo - mas isso não funciona no ub14.04.4 LTS. Ele informa um tempo de 0 segundo e sai sem erro.

A mesma abordagem funciona conforme esperado no ub10.04 LTS.

O us de sntp não é uma opção no escopo de nosso aplicativo. Eu não sei o que fazer, além de voltar para ntpdate .

Um conselho útil será apreciado IMENSAMENTE. Obrigado.

O que se segue é a informação sobre os meus sistemas ub14 e ub10, e os logs do meu pequeno teste, que podem ser resumidos em dois passos simples:

  1. Envie o tempo de volta uma hora ou mais.
  2. Tente corrigir o problema com ntpd -gq .

(Desculpe, se TMI. Melhor do que não o suficiente, certo?)

'#======================'  
'# UB14 VERSION DETAILS'  
'#======================'  
'root@goncharova14:~# lsb_release -d ; uname -a'  
'Description:    Ubuntu 14.04.4 LTS'  
'Linux goncharova14 4.2.0-27-generic #32~14.04.1-Ubuntu SMP Fri Jan 22   15:32:26 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux'

'#--------------------'  
'# NTP QUERY of PEERS'  
'#--------------------'  
'root@goncharova14:~# ntpq -p'  
'    remote           refid      st t when poll reach   delay   offset    jitter'
  '=============================================================================='
' golem.canonical 193.79.237.14    2 u    2   64    7   81.242  3459840   2446479'
'*LOCAL(0)        .LOCL.          13 l    3   64    7    0.000    0.000     0.000'

'grep -v -e ^$ -e ^# /etc/ntp.conf /etc/default/ntp'  
'#---------------------------'  
'# NTP.CONF and NTP DEFAULTS'  
'#---------------------------'  
'/etc/ntp.conf:'  

'server ntp.ubuntu.com prefer'  
'server 127.127.1.0'  
'fudge 127.127.1.0 stratum 13'  
'driftfile /var/lib/ntp/ntp.drift'  
'statistics loopstats peerstats clockstats'  
'filegen loopstats file loopstats type day enable'  
'filegen peerstats file peerstats type day enable'  
'filegen clockstats file clockstats type day enable'  
'restrict -4 default kod notrap nomodify nopeer noquery'  
'restrict -6 default kod notrap nomodify nopeer noquery'  
'restrict 127.0.0.1'  
'restrict ::1'  

'/etc/default/ntp:'  

'NTPD_OPTS='-g''  

'#---------------------------------'  
'# PUSH THE TIME BACK && TEST SYNC'  
'#---------------------------------'  

'root@goncharova14:~# date; date 02272000'  
'Mon Feb 27 20:57:39 EST 2017'  
'Mon Feb 27 20:00:00 EST 2017'  

'root@goncharova14:~# service ntp stop && (ntpd -gq ; echo "Status: $?";   date ; echo '---SYSLOG---' ; tail -n 15 /var/log/syslog; echo '---endLOG---' ; date)'  
' * Stopping NTP server ntpd     [ OK ]'  
'ntpd: time slew +0.000000s'  
'Status: 0'  
'Mon Feb 27 20:08:44 EST 2017'  
'---SYSLOG---'  
'Feb 27 20:07:51 goncharova14 ntpd[574]: peers refreshed'  
'Feb 27 20:07:51 goncharova14 ntpd[574]: Listening on routing socket on fd  #22 for interface updates'  
'Feb 27 20:07:53 goncharova14 ntpd[574]: ntpd: time slew +0.000000 s'  
'Feb 27 20:08:42 goncharova14 ntpd[1566]: ntpd [email protected] Thu Feb 11  18:30:40 UTC 2016 (1)'  
'Feb 27 20:08:42 goncharova14 ntpd[1566]: proto: precision = 0.160 usec'  
'Feb 27 20:08:42 goncharova14 ntpd[1566]: ntp_io: estimated max descriptors:   1024, initial socket boundary: 16'  
'Feb 27 20:08:42 goncharova14 ntpd[1566]: Listen and drop on 0 v4wildcard   0.0.0.0 UDP 123'  
'Feb 27 20:08:42 goncharova14 ntpd[1566]: Listen and drop on 1 v6wildcard ::   UDP 123'  
'Feb 27 20:08:42 goncharova14 ntpd[1566]: Listen normally on 2 lo 127.0.0.1   UDP 123'  
'Feb 27 20:08:42 goncharova14 ntpd[1566]: Listen normally on 3 eth0   10.160.74.140 UDP 123'  
'Feb 27 20:08:42 goncharova14 ntpd[1566]: Listen normally on 4 lo ::1 UDP   123'  
'Feb 27 20:08:42 goncharova14 ntpd[1566]: Listen normally on 5 eth0   fe80::a00:27ff:fecd:8c80 UDP 123'  
'Feb 27 20:08:42 goncharova14 ntpd[1566]: peers refreshed'  
'Feb 27 20:08:42 goncharova14 ntpd[1566]: Listening on routing socket on fd   #22 for interface updates'  
'Feb 27 20:08:44 goncharova14 ntpd[1566]: ntpd: time slew +0.000000 s'  
'---endLOG---'  
'Mon Feb 27 20:08:44 EST 2017'  

  '#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'  
'# THE SAME APPROACH WORKS AS EXPECTED IN UB10. Commands are identical. Conf   files are identical. +'
  '#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'  

'#======================'  
'# UB10 VERSION DETAILS'  
'#======================'  
'root@goncharova10:~# lsb_release -d ; uname -a ; echo'  
'Description:    Ubuntu 10.04 LTS'  
'Linux goncharova10 2.6.32-21-generic #32-Ubuntu SMP Fri Apr 16 08:10:02 UTC   2010 i686 GNU/Linux'

'#--------------------'  
'# NTP QUERY of PEERS'  
'#--------------------'  
'root@goncharova10:~# ntpq -p ; echo'  
'    remote           refid      st t when poll reach   delay   offset    jitter'
  '=============================================================================='
'*chilipepper.can 17.253.34.125    2 u  238  512  377   78.643   -2.038     1.020'
' LOCAL(0)        .LOCL.          13 l   22   64  377    0.000    0.000     0.001'

'#---------------------------'  
'# NTP.CONF and NTP DEFAULTS'  
'#---------------------------'  
'root@goncharova10:~# grep -v -e ^$ -e ^# /etc/ntp.conf /etc/default/ntp'  

'/etc/ntp.conf:'  

'server ntp.ubuntu.com prefer'  
'server 127.127.1.0'  
'fudge 127.127.1.0 stratum 13'  
'driftfile /var/lib/ntp/ntp.drift'  
'statistics loopstats peerstats clockstats'  
'filegen loopstats file loopstats type day enable'  
'filegen peerstats file peerstats type day enable'  
'filegen clockstats file clockstats type day enable'  
'restrict -4 default kod notrap nomodify nopeer noquery'  
'restrict -6 default kod notrap nomodify nopeer noquery'  
'restrict 127.0.0.1'  
'restrict ::1'  

'/etc/default/ntp:'  

'NTPD_OPTS='-g''  

'#---------------------------------'  
'# PUSH THE TIME BACK && TEST SYNC'  
'#---------------------------------'  

'root@goncharova10:~# date; date 02272000'  
'Mon Feb 27 21:10:03 EST 2017'  
'Mon Feb 27 20:00:00 EST 2017'  

'root@goncharova10:~# service ntp stop && (ntpd -gq ; echo "Status: $?";   date ; echo '---SYSLOG---' ; tail -n 15 /var/log/syslog; echo '---endLOG---' ; date)'  
' * Stopping NTP server ntpd [ OK ]'  
'ntpd: time set +4203.430466s'  
'Status: 0'  
'Mon Feb 27 21:10:12 EST 2017'  
'---SYSLOG---'  
'Feb 27 20:00:00 goncharova10 ntpd[25264]: ntpd exiting on signal 15'  
'Feb 27 20:00:00 goncharova10 ntpd[31309]: ntpd [email protected] Sat Dec 20   11:53:03 UTC 2014 (1)'  
'Feb 27 20:00:00 goncharova10 ntpd[31309]: precision = 1.000 usec'  
'Feb 27 20:00:00 goncharova10 ntpd[31309]: ntp_io: estimated max   descriptors: 1024, initial socket boundary: 16'  
'Feb 27 20:00:00 goncharova10 ntpd[31309]: Listening on interface #0   wildcard, 0.0.0.0#123 Disabled'  
'Feb 27 20:00:00 goncharova10 ntpd[31309]: Listening on interface #1   wildcard, ::#123 Disabled'  
'Feb 27 20:00:00 goncharova10 ntpd[31309]: Listening on interface #2 lo,   127.0.0.1#123 Enabled'  
'Feb 27 20:00:00 goncharova10 ntpd[31309]: Listening on interface #3 eth0,   10.160.74.40#123 Enabled'  
'Feb 27 20:00:00 goncharova10 ntpd[31309]: Listening on interface #4 lo,   ::1#123 Enabled'  
'Feb 27 20:00:00 goncharova10 ntpd[31309]: Listening on interface #5 eth0,   fe80::20c:29ff:feeb:5b07#123 Enabled'  
'Feb 27 20:00:00 goncharova10 ntpd[31309]: kernel time sync status 2040'  
'Feb 27 20:00:00 goncharova10 ntpd[31309]: frequency initialized -14.511 PPM   from /var/lib/ntp/ntp.drift'  
'Feb 27 21:10:12 goncharova10 ntpd[31309]: synchronized to 91.189.89.198,   stratum 2'  
'Feb 27 21:10:12 goncharova10 ntpd[31309]: time reset +4203.430466 s'  
'---endLOG---'  
'Mon Feb 27 21:10:12 EST 2017'  
    
por Beatrix Goncharova 28.02.2017 / 03:58

1 resposta

0

Você tem firewalls ou qualquer coisa que bloqueie o tráfego UDP? O ntp requer a porta UDP 123 aberta bidirecionalmente. Faça um tcpdump correspondente na porta UDP 123:

sudo tcpdump -i wlan0 udp port 123

Substitua o wlan0 pela sua interface principal voltada para a Internet.

Em seguida, reinicie o serviço ntp. Você deve ver algo semelhante ao seguinte (os endereços podem variar):

22:34:16.962180 IP 10.10.1.150.ntp > muug.ca.ntp: NTPv4, Client, length 48
22:34:16.999362 IP muug.ca.ntp > 10.10.1.150.ntp: NTPv4, Server, length 48
22:34:17.962186 IP 10.10.1.150.ntp > host.hosttechnet.com.ntp: NTPv4, Client, length 48
22:34:17.988816 IP host.hosttechnet.com.ntp > 10.10.1.150.ntp: NTPv4, Server, length 48
22:34:18.962187 IP 10.10.1.150.ntp > ntp2.torix.ca.ntp: NTPv4, Client, length 48
22:34:18.980295 IP ntp2.torix.ca.ntp > 10.10.1.150.ntp: NTPv4, Server, length 48
22:34:19.962194 IP 10.10.1.150.ntp > time.srv.ualberta.ca.ntp: NTPv4, Client, length 48
22:34:20.019589 IP time.srv.ualberta.ca.ntp > 10.10.1.150.ntp: NTPv4, Server, length 48
22:34:20.962167 IP 10.10.1.150.ntp > golem.canonical.com.ntp: NTPv4, Client, length 48
22:34:21.061641 IP golem.canonical.com.ntp > 10.10.1.150.ntp: NTPv4, Server, length 48
    
por TLin 28.02.2017 / 04:35