[root@www ~]# yum install ntp
[root@www ~]# systemctl enable/restart ntpd
[root@www ~]# firewall-cmd –permanent –add-port=123/upd
[root@www ~]# firewall-cmd –reload
[root@www ~]# vim /etc/selinux/config
SELINUX=disabled
[root@www ~]# vim /etc/ntp.conf
# 1. 先处理权限方面的问题,包括放行上层服务器以及开放区网用户来源:
restrict default kod nomodify notrap nopeer noquery #拒绝 IPv4 的用户
restrict -6 default kod nomodify notrap nopeer noquery #拒绝 IPv6 的用户
restrict 203.107.6.88 #放行 ntp.aliyun.com 进入本 NTP 服务器
restrict 127.0.0.1 #底下两个是默认值,放行本机来源
restrict -6 ::1
restrict 192.168.1.0 mask 255.255.255.0 nomodify #放行区网来源
# 2. 设定主机来源,请先将原本的 [0|1|2].centos.pool.ntp.org 的设定批注掉:
server 192.168.1.254 prefer <==以这部主机为最优先
server 59.124.196.83
server 59.124.196.84
# 3.预设时间差异分析档案与暂不用到的 keys 等,不需要更动它:
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys
[root@www ~]# netstat -tlunp | grep ntp
Proto Recv-Q Send-Q Local Address Foreign Address PID/Program name
udp 0 0 192.168.100.254:123 0.0.0.0:* 3492/ntpd
udp 0 0 192.168.1.100:123 0.0.0.0:* 3492/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 3492/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 3492/ntpd
udp 0 0 ::1:123 :::* 3492/ntpd
udp 0 0 :::123 :::* 3492/ntpd
# 主要是 UDP 封包,且在 port 123 这个埠口的啦!
[root@www ~]# ntpstat
synchronised to NTP server (220.130.158.71) at stratum 3
time correct to within 538 ms
polling server every 128 s
[root@www ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
===================================================================
server01.hua .STEP. 16 u – 1024 0 0.000 0.000 0.000
*sv1.ggsrv.de 205.46.178.169 2 u 720 256 314 213.871 33.779 59.189
remote:亦即是 NTP 主机的 IP 或主机名啰~注意最左边的符号
o 如果有『 * 』代表目前正在作用当中的上层 NTP
o 如果是『 + 』代表也有连上线,而且可作为下一个提供时间更新的候选者。
refid:参考的上一层 NTP 主机的地址
st:就是 stratum 阶层啰!
when:几秒钟前曾经做过时间同步化更新的动作;
poll:下一次更新在几秒钟之后;
reach:已经向上层 NTP 服务器要求更新的次数
delay:网络传输过程当中延迟的时间,单位为 10^(-6) 秒
offset:时间补偿的结果,单位与 10^(-3) 秒
jitter:Linux 系统时间与 BIOS 硬件时间的差异时间, 单位为 10^(-6) 秒。