centos7 and other operating systems to achieve clock synchronization ntp

A, ntp server set up

1.centos7.6 build ntp server

Pre-installation:

[root@ntpserver ~]# more /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
[root@ntp-server ~]# ps -ef|grep ntp
root      18054  17742  0 15:53 pts/0    00:00:00 grep --color=auto ntp
[root@ntp-server ~]# ll /etc/|grep ntp
[root@ntp-server ~]# ntpdate
-bash: ntpdate: 未找到命令
[root@ntp-server ~]# systemctl status ntpd
Unit ntpd.service could not be found.

ntp server ip is 172.27.9.131, operating system version centos 7.6, no ntp service prior to installation, the / etc directory and no ntp-related documents, nor ntpdate command

Pictures .png

installation:

[root@ntp-server ~]# yum -y install ntp
[root@ntp-server ~]# ps -ef|grep ntp      
root      18225  17742  0 16:00 pts/0    00:00:00 grep --color=auto ntp
[root@ntp-server ~]# ll /etc/|grep ntp    
drwxr-xr-x   3 root root       52 11月  5 15:59 ntp
-rw-r--r--   1 root root     2000 8月   6 21:44 ntp.conf
[root@ntp-server ~]# ntpdate              
 5 Nov 16:01:04 ntpdate[18240]: no servers can be used, exiting
[root@ntp-server ~]# systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

Pictures .png

2.ntp server configuration

New profile ntp-source.conf

[root@ntp-server ~]# cat >/etc/ntp/ntp-source.conf <<EOF
server ntp.ntsc.ac.cn prefer
server ntp1.aliyun.com iburst
server time1.cloud.tencent.com  iburst
server 0.cn.pool.ntp.org iburst
server 1.cn.pool.ntp.org iburst
server 2.cn.pool.ntp.org iburst
> EOF

ntp.ntsc.ac.cn for the National Time Service Center domain (the preferred ntp source), ntp1.aliyun.com Ali cloud ntp server, time1.cloud.tencent.com Tencent cloud ntp server, 0.cn.pool. ntp.org as the official website in China ntp ntp server.

Modify the configuration file ntp.conf

#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
includefile /etc/ntp/ntp-source.conf

Clock source configuration file /etc/ntp/ntp-source.conf call

Start Service

[root@ntp-server ~]# systemctl start ntpd 
[root@ntp-server ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@ntp-server ~]# systemctl is-enabled chronyd.service
enabled
[root@ntp-server ~]# systemctl disable chronyd.service
Removed symlink /etc/systemd/system/multi-user.target.wants/chronyd.service.

Start ntp service and set the boot, if chrony is set to boot is removed, Centos7 chrony to use the default time synchronization, and ntpd chrony conflict may cause ntpd open failed to start

View ntp service

[root@ntpserver ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*114.118.7.161   123.139.33.3     2 u   36   64   77   23.196    6.770   1.028
+120.25.115.20   10.137.53.7      2 u   24   64   77   20.913    6.897   1.506
-139.199.215.251 100.122.36.196   2 u   22   64   77   21.854    8.122   1.458
-119.28.183.184  100.122.36.196   2 u   19   64   77   33.594    4.266   2.011
+ntp6.flashdance 194.58.202.148   2 u   91   64   72  268.044    6.483   1.516
+119.28.206.193  100.122.36.4     2 u   20   64   77   32.332    7.080   1.344
[root@ntpserver ~]# ntpstat 
synchronised to NTP server (114.118.7.161) at stratum 3
   time correct to within 996 ms
   polling server every 64 s

ntpq -p command to view and ntpstat ntp synchronization status, once every 64 seconds synchronization

Detailed ntpq -p

Pictures .png

  • Remote : the name of the NTP server in response to this request.
  • refid : NTP server on an NTP server.
  • ST : level remote remote server. Set to Low level server 1--16, in order to mitigate network congestion and load, it is recommended to avoid direct connection to the server 1 level on principle.
  • T : U: unicast (Unicast), b: broadcast (Broadcast), l: local (local clock)
  • when the current number of seconds since the last successful request:
  • poll : local and remote server synchronization once how much time (in seconds). When the initial run NTP, poll the value will be relatively small, and increase the frequency synchronization server, it is recommended to adjust to the correct time as soon as possible. After the adjustment, poll will gradually increase the value, the frequency of the synchronization will be reduced accordingly.
  • the REACH : octal value, and to test whether the server connection. Each time a successful connection, will increase the value of reach.
  • Delay : synchronization requires round trip time from the NTP server to send the local machine.
  • offset : host through NTP time synchronization with the synchronized time source offset in milliseconds (ms). offset closer to 0, the host and the time of the NTP server closer.
  • the Jitter : used to make the value of statistics. Statistical continuous connection in the distribution of the number of offset in particular. I.e., the absolute value of the jitter value is smaller, the precise time of the host.

remote state logo Detailed

Pictures .png

  • Empty : Indicates that no host for remote communication
  • the X- : no longer in use
  • - : no longer in use
  • # : Good remote node or server but not in use
  • + : Good and priority use of the remote node or server
  • *****: The current primary synchronization objects as a priority remote node or server
  • O : the PPS node (node is active when the priority). The actual system synchronization is derived from the second pulse signal (pulse-per-second, PPS ), PPS may be driven by a clock or by a kernel interface

ntp port View

[root@ntpserver ~]# netstat -nupl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
udp        0      0 172.27.9.131:123        0.0.0.0:*                           17174/ntpd          
udp        0      0 127.0.0.1:123           0.0.0.0:*                           17174/ntpd          
udp        0      0 0.0.0.0:123             0.0.0.0:*                           17174/ntpd          
udp6       0      0 fe80::20c:29ff:fed9:123 :::*                                17174/ntpd          
udp6       0      0 ::1:123                 :::*                                17174/ntpd          
udp6       0      0 :::123                  :::*                                17174/ntpd         

ntp service port 123, UDP protocol

Second, the client synchronization service mode --ntpd

1.centos7.3

Installing and starting with ntp server, configured as follows:

[root@centos7 ~]# view /etc/ntp.conf
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server ntpserver iburst 
[root@centos7 ~]# view /etc/hosts
172.27.9.131    ntpserver
[root@centos7 ~]# systemctl enable ntpd
[root@centos7 ~]# systemctl start ntpd
[root@centos7 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntpserver       114.118.7.161    3 u    1   64    3    0.221   12.641   0.495
[root@centos7 ~]# ntpstat 
synchronised to NTP server (172.27.9.131) at stratum 4
   time correct to within 1049 ms
   polling server every 64 s

2.ubuntu1604

root@ubuntu1604:~# view /etc/hosts
root@ubuntu1604:~# apt install -y ntp
root@ubuntu1604:~# view /etc/ntp.conf 
root@ubuntu1604:~# systemctl enable ntp
ntp.service is not a native service, redirecting to systemd-sysv-install
Executing /lib/systemd/systemd-sysv-install enable ntp
root@ubuntu1604:~# systemctl start ntp
root@ubuntu1604:~# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntpserver       114.118.7.161    3 u   51   64  377    0.254   -4.194   1.090

Pictures .png

3.suse11

Install ntp

Pictures .png

Pictures .png

suse11:~ # view /etc/hosts
172.27.9.131    ntpserver
suse11:~ # view /etc/ntp.conf 
#server 127.127.1.0             # local clock (LCL)
#fudge  127.127.1.0 stratum 10  # LCL is unsynchronized
server ntpserver iburst
suse11:~ # service ntp restart
Shutting down network time protocol daemon (NTPD)                                                                                                                                                                             done
Starting network time protocol daemon (NTPD)                                                                                                                                                                                  done
suse11:~ # ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntpserver       114.118.7.161    3 u    1   64    1    0.223    2.271   0.285
suse11:~ # chkconfig ntp on
suse11:~ # chkconfig --list|grep ntp
ntp                       0:off  1:off  2:off  3:on   4:off  5:on   6:off

The default is synchronized with the local, modified to synchronize with ntpserver.

4.AIX

aix:/ #view /etc/ntp.conf
driftfile /etc/ntp.drift
tracefile /etc/ntp.trace
server ntpserver
aix:/ #view /etc/hosts  
172.27.9.131    ntpserver
aix:/ #stopsrc -s xntpd
0513-044 The /usr/sbin/xntpd Subsystem was requested to stop.
aix:/ #startsrc -s xntpd
0513-059 The xntpd Subsystem has been started. Subsystem PID is 1663192.
aix:/ #ntpq -p
     remote           refid      st t when poll reach   delay   offset    disp
==============================================================================
*ntpserver       114.118.7.161    3 u    1   64   37     1.16    5.744  875.43
aix:/ #l***c -ls xntpd
 Program name:    /usr/sbin/xntpd 
 Version:         3 
 Leap indicator:  00 (No leap second today.) 
 Sys peer:        ntpserver 
 Sys stratum:     4 
 Sys precision:   -17 
 Debug/Tracing:   DISABLED 
 Root distance:   0.051193 
 Root dispersion: 0.176468 
 Reference ID:    172.27.9.131 
 Reference time:  e16e4fd5.e2945000  Thu, Nov  7 2019 16:09:57.885 
 Broadcast delay: 0.003906 (sec) 
 Auth delay:      0.000122 (sec) 
 System flags:    pll monitor filegen  
 System uptime:   436 (sec) 
 Clock stability: 7.000000 (sec) 
 Clock frequency: 0.000000 (sec) 
 Peer: ntpserver 
      flags: (configured)(sys peer) 
      stratum:  3, version: 3 
      our mode: client, his mode: server 
Subsystem         Group            PID          Status 
 xntpd            tcpip            1663192      active

5.redhat6.8

[root@redhat6 ~]# view /etc/hosts
172.27.9.131    ntpserver
[root@redhat6 ~]# view /etc/ntp.conf
server ntpserver iburst
[root@redhat6 ~]# service ntpd restart
Shutting down ntpd:                                        [  OK  ]
Starting ntpd:                                             [  OK  ]
[root@redhat6 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntpserver       114.118.7.161    3 u    1   64    1    0.432    3.366   0.000
[root@redhat6 ~]# ntpstat 
synchronised to NTP server (172.27.9.131) at stratum 4 
   time correct to within 8030 ms
   polling server every 64 s

6.windows 7

Pictures .png

Applicable windows7 and Windows Server 2008, etc.

Third, the client synchronization --ntpdate command mode

[root@centos7 ~]# systemctl stop ntpd
[root@centos7 ~]# ntpdate ntpserver  
 7 Nov 16:33:02 ntpdate[2618]: adjust time server 172.27.9.131 offset -0.002048 sec
[root@centos7 ~]# crontab -l
0 1 * * * /usr/sbin/ntpdate  ntpserver

ntp service and ntpdate command can not be used simultaneously, before using ntpdate, ntp service needs to be stopped. Ntpdate command mode using suitable clock synchronization suse, redhat, AIX, centos, ubuntu other operating systems, the timing task timing synchronization can be made per day.

ntpd ntpdate service mode and command mode can achieve clock synchronization client can choose the best according to production.

Guess you like

Origin blog.51cto.com/3241766/2454816