配置一个ntp客户端一个ntp服务器
安装ntp:yum –y install ntp
配置ntp配置文件
vim /etc/ntp.conf
在# the administrative functions.这句话下添加
restrict 192.168.10.134 nomodify notrap nopeer noquery
在#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap下面
restrict 192.168.10.2 mask 255.255.255.0 nomodify notrap
将0-3注释掉并添加
#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 127.127.1.0
Fudge 127.127.1.0 stratum 10
这是配置的主节点
子节点:vim /etc/ntp.conf
restrict 192.168.10.133 nomodify notrap nopeer noquery:ip是子节点的ip
restrict 192.168.10.2 mask 255.255.255.0 nomodify notrap:ip是网关
restrict 192.168.10.134 nomodify notrap noquery :ip是主节点ip
server 192.168.10.134
Fudge 192.168.10.134 stratum 10 :ip是主节点的ip
配置完成之后
使用/bin/systemctl start ntpd.service启动服务
使用ntpstat查看ntp服务器有无和上层ntp连通
若出现unsynchronised time server re-starting polling server every 8 s
需要等待5-10分钟即可
出现synchronised to local net at stratum 6
time correct to within 199 ms
polling server every 64 s
说明主节点正常运行
出现synchronised to NTP server (192.168.10.134) at stratum 7
time correct to within 888 ms
polling server every 64 s
说明子节点正常运行
设置开机自启
chkconfig ntpd on
注意:ntp服务默认端口是123,防火墙需要开放123端口