Linux集群之间配置NTP时间同步ntp

NTP时间同步

注意事项

要注意的是,ntpd 有一个自我保护设置: 如果本机与上源时间相差太大, ntpd 不运行. 所以新设置的时间服务器一定要先 ntpdate 从上源取得时间初值, 然后启动 ntpd服务。ntpd服务 运行后, 先是每64秒与上源服务器同步一次, 根据每次同步时测得的误差值经复杂计算逐步调整自己的时间, 随着误差减小, 逐步增加同步的间隔.每次跳动, 都会重复这个调整的过程.

NTP服务运行原理

NTP(Network Time Protocol,网络时间协议)是用来使计算机时间同步化的一种协议。它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒),且可介由加密确认的方式来防止恶毒的协议攻击。

环境说明

  • 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

猜你喜欢

转载自www.cnblogs.com/fusheng11711/p/12071780.html