环境说明
NTP服务端:Rich63.cn IP:192.168.1.63
NTP客户端:Rich64.cn IP:192.168.1.64
操作系统版本:CentOS Linux release 7.5.1804 (Core)
服务端安装配置NTP
yum install ntp ntpdate -y
修改配置文件,使该NTP服务器在不联网的情况下,使用本服务器的时间作为同步时间
vim /etc/ntp.conf # 编辑配置文件,注释掉以下4行
#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 iburst # 配置文件内添加此行
wq保存退出!
启动ntp服务
systemctl start ntpd
验证状态
systemctl status ntpd
设置开机自启动
systemctl enable ntpd
验证ntp
ntpq -p
配置客户端
安装与服务端一致,只是配置文件修改不一样
#注释掉其他上游时间服务器
#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
#配置上游时间服务器为本地的ntpd Server服务器
server 192.168.1.63
#配置允许上游时间服务器主动修改本机的时间
restrict 192.168.1.63 nomodify notrap noquery
然后初次同步需要手动同步
ntpdate -u 192.168.1.63
然后设置客户端ntp服务开机自启动即可
systemctl enable ntpd