一、安装NTP
yum -y install ntp
二、设置开机启动
chkconfig ntpd on
三、配置内网NTP Server
1、修改ntp.conf
vi /etc/ntp.conf
第一种配置:允许任何IP的客户机都可以进行时间同步 将
restrict default kod nomodify notrap nopeer noquery
这行修改成:
restrict default nomodify
第二种配置:只允许192.168.11.*网段的客户机进行时间同步 在restrict default nomodify notrap noquery(表示默认拒绝所有IP的时间同步)之后增加一行:
restrict 192.168.11.0 mask 255.255.255.0 nomodify
2、同步时间设置
2.1 通过网络时间同步
保持默认即可
2.2 使用本地时间
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
配置文件完成,保存退出,启动服务,执行如下命令
service ntpd start
检查是否成功
ntpstat
出现以下结果即表示配置成功
synchronised to NTP server (85.199.214.100) at stratum 2
time correct to within 174 ms
polling server every 128 s
如果出现异常请等待几分钟,一般等待5-10分钟才能同步。
四、配置客户端
在另外需要同步的机器上先安装ntp并设置为开机启动
vi /etc/ntp.conf
将原来的server配置全部注释
添加两行
#允许hnode1修改本机时间
restrict 192.168.11.70 nomodify notrap noquery
#配置之前的ntp server为时间节点
server 192.168.11.70
配置文件完成,保存退出
启动服务
service ntpd start
查询上级服务时间
ntpq -p
如果如下:
执行命令,查看同步状态
ntpstat
如果出现下图所示,一般情况下原因都是本地的NTPD服务器还没有正常启动起来,一般需要几分钟时间后才能开始同步。等几分钟后再执行命令查看。
出现这个结果表示同步成功