1. ntp和ntpdate区别
- NTP
全名 network time protocol,可以为其他主机提供时间校对服务。安装包名是ntp,守护进程为ntpd,配置文件是/etc/ntp.conf
.
- NTPDATE
用于客户端的时间矫正,非NTP服务器可以不启动NTP。安装包是ntpdate
。在生产环境中一般不建议使用ntpdate,推荐使用ntp进行时间同步。
2. NTP服务器的安装与配置
- 安装
yum install ntp
- 创建配置文件
编辑/etc/
目录下的ntp.conf
的配置文件,在其中配置上有ntp服务器。如下为常见的配置:
# 时间差异文件
driftfile /var/lib/ntp/ntp.drift
# 分析统计信息
#statsdir /var/log/ntpstats/
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
# 不允许来自公网上ipv4和ipv6客户端的访问
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited
# 让NTP Server和其自身保持同步,如果在/etc/ntp.conf中定义的se