# For more information about this file, see the man pages # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift # 防止时间偏差大于1000s ntp不工作 tinker panic 0 # Permit time synchronization with our time source, but do not # permit the source to query or modify the service on this system. restrict default nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could # be tightened as well, but to do so would effect some of # the administrative functions. restrict 127.0.0.1 restrict ::1
# Hosts on local network are less restricted. #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project. # Please consider joining the pool (http://www.pool.ntp.org/join.html). #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 ntp.aliyun.com server 127.127.1.0
# Key file containing the keys and key identifiers used when operating # with symmetric key cryptography. keys /etc/ntp/keys
# Specify the key identifiers which are trusted. #trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility. #requestkey 8
# Specify the key identifier to use with the ntpq utility. #controlkey 8
# Enable writing of statistics records. #statistics clockstats cryptostats loopstats peerstats
# Disable the monitoring facility to prevent amplification attacks using ntpdc # monlist command when default restrict does not include the noquery flag. See # CVE-2013-5211 for more details. # Note: Monitoring will not be disabled with the limited restriction flag. disable monitor
1 2 3 4 5
启用ntp systemctl start ntpd
开机自启动 systemctl enable ntpd
一些常见问题
开机无法自启动
调整chronyd,防止冲突导致ntpd无法开机自启
1
systemctl disable chronyd
主机时间偏差大于1000s无法启动
1 2 3 4 5 6 7
systemctl status ntpd
Apr 28 11:50:08 jianghuihui02 ntpd[6145]: 0.0.0.0 c617 07 panic_stop -2510 s; set clock manually within 1000 s. Apr 28 11:50:08 jianghuihui02 systemd[1]: ntpd.service: main process exited, code=exited, status=255/n/a Apr 28 11:50:08 jianghuihui02 systemd[1]: Unit ntpd.service entered failed state. Apr 28 11:50:08 jianghuihui02 systemd[1]: ntpd.service failed. 客户端的时间与服务端的时间超过1000s,那么ntp进程就会退出并在系统日志文件中记录。
解决方法: 在配置文件 / etc/ntp.conf 中增加一行:
1 2
tinker panic 0 使ntp在时间差较大时依然工作
查看ntp状态
ntpq -p
1 2 3 4 5
[root@master192 ~]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== LOCAL(0) .LOCL. 5 l 123m 64 0 0.000 0.000 0.000 *203.107.6.88 10.137.38.86 2 u 171 256 377 25.486 -0.175 0.451