导读 NTP服务器【Network Time Protocol(NTP)】是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒),且可介由加密确认的方式来防止恶毒的协议攻击。
检查是否已经安装ntp
# rpm -qa|grep ntp
ntp-4.2.4p8-2.el6.centos.i686
配置ntp.conf
# vim /etc/ntp.conf

需要修改以下几项:

    restrict:表示设置客户端连接到本NTP服务器的权限

 

    其规则为:restrict ip mask netmask_ip parameter

 

    其中IP 可以是地址位,也可以是default;parameter有以下选项:

 

    ignore:关闭所有的NTP链接服务

 

    nomodify:表示client不能更改server端的参数信息

 

    notrust:该client除非通过认证,否则该客户端的来源将被视为不信任网域

 

    noquery:不提供客户端的时间查询

 

    server:

 

    表示设置本NTP服务器连接到远程NTP服务器的地址

 

    server 127.127.1.0

 

    fudge 127.127.1.0 stratum 10

 

    以上两行表示如果server指定的服务器连接失败,则采用本地的时间来同步时间

 

    配置日志:

 

    statsdir /var/log/ntp/

 

    logfile /var/log/ntp/ntp.log

本文做了简单的配置,内容如下:

driftfile /var/lib/ntp/drift
restrict 127.0.0.1
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap
server 210.72.145.44 prefer
server 133.100.11.8
server 0.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 8
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
statsdir /var/log/ntp/
logfile /var/log/ntp/ntp.log
启动ntp
# mkdir -p /var/log/ntp && touch /var/log/ntp/ntp.log
# chkconfig ntpd on
# service ntpd start
客户端测试

通过linux客户端测试ntp server

# ntpdate 192.168.0.4
5 Aug 15:43:22 ntpdate[30958]: adjust time server 192.168.0.4 offset 0.000576 sec

当出现以上信息表示成功配置ntp server!

注意: 如果ntp刚启动起来,在客户端同步的时候会出现 no server suitable for synchronization found 的错误提示,这是因为ntp server 刚启动起来,还没有和上级ntp取得同步,大概过5分钟左右再在客户端上同步,可得到正确信息。

原文来自:http://www.toutiao.com/a6363600831749390594/

本文地址:https://www.linuxprobe.com/centos-install-ntp.html编辑:冯振华,审核员:逄增宝

本文原创地址:https://www.linuxprobe.com/centos-install-ntp.html编辑:public,审核员:暂无