如果没能帮你解决问题,请在下方留言
实例:
服务端-192.168.111.143
客户端-192.168.111.170
1. 获取rpm包
解压操作系统的镜像文件,获取rpm包
.CentOS-7.4-x86_64-DVD-1708Packages
2. 安装rpm
3. 设置服务器时间
查看当前时区
如果不是预期的时区,继续执行以下步骤
查看时区完整名称
设置服务器的时区为香港时区
timedatectl set-timezone Asia/Hong_Kong手动配置当前时间
timedatectl set-time "2019-07-17 14:45:10"写入硬件时钟
hwclock --hctosys重启
reboot查看配置结果
date4. 修改/etc/ntp.conf文件
服务端:
rm -rf /etc/ntp.confvi /etc/ntp.conf将以下内容写进文件
#系统时间与BIOS事件的偏差记录 driftfile /var/lib/ntp/drift #允许任何主机进行时间同步 restrict default ignore #确保服务器本身有足够权限 restrict 127.0.0.1 restrict ::1 #授权192.168.0.0网段上的所有机器可以从这台机器上查询和同步时间. restrict 192.168.0.0 mask 255.255.0.0 nomodify notrap server 192.168.111.143 iburst #当外部时间不可用时,使用本地时间. server 127.127.1.0 fudge 127.127.1.0 stratum 10 interface ignore wildcard interface listen 192.168.111.143 interface listen 127.0.0.1 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitor5. 停止ntpd时钟服务
service ntpd stop6. 设置不与网络服务同步
timedatectl set-ntp no7. 开启ntp服务
service ntpd start8. 查看ntp服务状态
service ntpd status9. 设置开机自启动
systemctl enable ntpd客户端:
rm -rf /etc/ntp.confvi /etc/ntp.confdriftfile /var/lib/ntp/drift restrict default nomodify notrap nopeer noquery restrict 127.0.0.1 restrict ::1 server 192.168.111.143 iburst restrict 192.168.111.143 nomodify notrap noquery server 127.127.1.0 fudge 127.127.1.0 stratum 10 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys disable monitor10. 连接NTP服务器同步时间
ntpdate 192.168.111.14311. 开启ntp服务
service ntpd start12. 设置开机自启动
systemctl enable ntpd13. 结果检查
timedatectl14. 查看客户端的时间和时区是否和服务端保持一致,NTP 同步是否开启
watch ntpq -pchkconfig --level 35 ntpd on