知乎专栏 |
过程 2526..1. ntp server
# yum install ntp
port
[root@ntp ~]# netstat -unlnp |grep 123 udp 0 0 192.168.5.5:123 0.0.0.0:* 10810/ntpd udp 0 0 172.16.0.5:123 0.0.0.0:* 10810/ntpd udp 0 0 192.168.3.5:123 0.0.0.0:* 10810/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 10810/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 10810/ntpd udp 0 0 ::1:123 :::* 10810/ntpd udp 0 0 fe80::225:64ff:fe9a:123 :::* 10810/ntpd udp 0 0 :::123 :::* 10810/ntpd [root@ntp ~]# lsof -i :123 COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME ntpd 10810 ntp 16u IPv4 35921 UDP *:ntp ntpd 10810 ntp 17u IPv6 35922 UDP *:ntp ntpd 10810 ntp 18u IPv6 35923 UDP [fe80::225:64ff:fe9a:d7e0]:ntp ntpd 10810 ntp 19u IPv6 35924 UDP localhost6.localdomain6:ntp ntpd 10810 ntp 20u IPv4 35925 UDP localhost.localdomain:ntp ntpd 10810 ntp 21u IPv4 35926 UDP nis.example.com:ntp ntpd 10810 ntp 22u IPv4 35927 UDP 172.16.0.5:ntp ntpd 10810 ntp 23u IPv4 35928 UDP 192.168.5.5:ntp
status
ntpstat
[root@subversion ~]# ntpstat synchronised to local net at stratum 11 time correct to within 11 ms polling server every 1024 s
[root@subversion ~]# ntptrace -n 127.0.0.1 127.0.0.1: stratum 11, offset 0.000000, synch distance 0.010984
[root@subversion ~]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== 122.226.192.4 .INIT. 16 u - 1024 0 0.000 0.000 0.000 218.75.4.130 .INIT. 16 u - 1024 0 0.000 0.000 0.000 www.chinaepg.ne .INIT. 16 u - 1024 0 0.000 0.000 0.000 *LOCAL(0) .LOCL. 10 l 60 64 377 0.000 0.000 0.001
http://www.pool.ntp.org/
vim /etc/ntp.conf server 2.cn.pool.ntp.org server 3.asia.pool.ntp.org server 2.asia.pool.ntp.org
# chkconfig ntpd on # service ntpd start/stop/restart
# yum install ntpdate # systemctl enable ntpdate # systemctl start ntpdate
# ntpdate 172.16.3.51
或使用
# /usr/libexec/ntpdate-wrapper
使用 ntpdate 临时更新时间
[root@dev1 ~]# ntpdate 192.168.3.5 && hwclock -w 9 Aug 12:38:22 ntpdate[2538]: step time server 192.168.3.5 offset 3543.674078 sec
另外一个命令 rdate 同样可以达到ntpdate目的,rdate是系统默认安装。
过程 2526..2. ntp client
# yum install ntp
# chkconfig ntpd on # service ntpd start
vim /etc/ntp.conf #server 0.centos.pool.ntp.org #server 1.centos.pool.ntp.org #server 2.centos.pool.ntp.org server 192.168.3.5
ntpd 启动后,不能再使用ntpdate
# $OpenBSD: ntpd.conf,v 1.7 2004/07/20 17:38:35 henning Exp $ # sample ntpd configuration file, see ntpd.conf(5) # Addresses to listen on (ntpd does not listen by default) listen on * #listen on 127.0.0.1 #listen on ::1 # sync to a single server #server ntp.example.org # use a random selection of 4 public stratum 2 servers # see http://twiki.ntp.org/bin/view/Servers/NTPPoolServers # and http://www.pool.ntp.org/ #server 0.debian.pool.ntp.org #server 1.debian.pool.ntp.org #server 2.debian.pool.ntp.org #server 3.debian.pool.ntp.org server 0.asia.pool.ntp.org server 1.asia.pool.ntp.org server 2.asia.pool.ntp.org server 3.asia.pool.ntp.org
# ntpstat Unable to talk to NTP daemon. Is it running?
[root@netkiller nginx]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== LOCAL(0) .LOCL. 10 l 17d 64 0 0.000 0.000 0.000 #time5.aliyun.co 10.137.38.86 2 u 709 1024 177 48.647 4.163 17.751 +120.25.115.19 10.137.38.86 2 u 1907 1024 376 11.631 -0.173 0.366 -120.25.115.20 10.137.38.86 2 u 324 1024 377 11.701 -0.316 0.299 -time4.aliyun.co 10.137.38.86 2 u 1726 1024 376 12.342 -0.919 0.293 +time6.aliyun.co 10.137.38.86 2 u 629 1024 67 44.500 0.076 10.601 -10.143.33.49 10.137.38.86 2 u 547 1024 377 26.710 -1.764 0.403 -10.143.33.50 10.137.38.86 2 u 654 1024 377 27.091 2.432 0.241 -10.143.33.51 10.137.38.86 2 u 923 1024 377 27.375 1.779 0.337 *10.143.0.44 10.137.38.86 2 u 723 1024 377 28.356 0.080 0.338 +10.143.0.45 10.137.38.86 2 u 479 1024 377 28.081 0.188 0.345 -10.143.0.46 10.137.38.86 2 u 986 1024 377 27.809 -0.777 1.672 100.100.5.1 .INIT. 16 u - 1024 0 0.000 0.000 0.000 100.100.5.2 .INIT. 16 u - 1024 0 0.000 0.000 0.000 100.100.5.3 .INIT. 16 u - 1024 0 0.000 0.000 0.000 100.100.3.1 .INIT. 16 u - 1024 0 0.000 0.000 0.000 100.100.3.2 .INIT. 16 u - 1024 0 0.000 0.000 0.000 100.100.3.3 .INIT. 16 u - 1024 0 0.000 0.000 0.000
-n 禁止DNS解析
[root@iZ621r6pk9aZ nginx]# ntpq -n -p remote refid st t when poll reach delay offset jitter ============================================================================== 127.127.1.0 .LOCL. 10 l 17d 64 0 0.000 0.000 0.000 #182.92.12.11 10.137.38.86 2 u 757 1024 177 48.647 4.163 17.751 +120.25.115.19 10.137.38.86 2 u 1955 1024 376 11.631 -0.173 0.366 -120.25.115.20 10.137.38.86 2 u 372 1024 377 11.701 -0.316 0.299 -120.25.108.11 10.137.38.86 2 u 1774 1024 376 12.342 -0.919 0.293 +115.28.122.198 10.137.38.86 2 u 677 1024 67 44.500 0.076 10.601 -10.143.33.49 10.137.38.86 2 u 595 1024 377 26.710 -1.764 0.403 -10.143.33.50 10.137.38.86 2 u 702 1024 377 27.091 2.432 0.241 -10.143.33.51 10.137.38.86 2 u 971 1024 377 27.375 1.779 0.337 *10.143.0.44 10.137.38.86 2 u 771 1024 377 28.356 0.080 0.338 +10.143.0.45 10.137.38.86 2 u 527 1024 377 28.081 0.188 0.345 -10.143.0.46 10.137.38.86 2 u 1034 1024 377 27.809 -0.777 1.672 100.100.5.1 .INIT. 16 u - 1024 0 0.000 0.000 0.000 100.100.5.2 .INIT. 16 u - 1024 0 0.000 0.000 0.000 100.100.5.3 .INIT. 16 u - 1024 0 0.000 0.000 0.000 100.100.3.1 .INIT. 16 u - 1024 0 0.000 0.000 0.000 100.100.3.2 .INIT. 16 u - 1024 0 0.000 0.000 0.000 100.100.3.3 .INIT. 16 u - 1024 0 0.000 0.000 0.000