centos 7 搭建ntp 服务器

第一步 安装ntp

yum install ntp

第二步,查找最近的时间同步服务器

http://www.pool.ntp.org/zone/asia

第三部编辑 /etc/ntp.conf

server  127.127.1.0  iburst   # local clock 当外部时间服务器不可用的时候,使用本机时间作为时间服务的标准
fudge 127.127.1.0 stratum 10 #这个值不能太高0-15,太高会报错

第四步

添加允许访问的ip 段

restrict 192.168.1.0 netmask 255.255.255.0 nomodify notrap

第五步 配置防火墙

firewall-cmd --add-service=ntp --permanent
firewall-cmd --reload

第六步 启动ntp 服务

systemctl enable ntpd  开机启动

systemctl start ntpd

sytemctl status ntpd

第七步 验证服务

ntpq -p



date -R

第八步

同步远程时间服务

ntpdate -q  0.ro.pool.ntp.org  1.ro.pool.ntp.org

第九步 在客户端机器同步时间

ntpdate -d -b 192.168.85.20

可能遇到的问题

1 centos stratum 0, precision 0, leap 00, trust 000 no server suitable for synchronization found

这个问题是由于防火墙挡住了ntp 端口,使用上买你的firewall-cmd 命令解决

2 stratum  too high 的问题

在/etc/ntp.conf 中 修改 stratum 的值

NTP开机无法启动的解决方法

这个问题往往是由于npt 服务的123 端口被其他服务占用引起,这个占用服务一般是chronyd

禁用这个服务即可

systemctl disable chronyd

原文地址:https://www.cnblogs.com/yudar/p/4276883.html