ntp时间同步
时间同步的作用
- NTP (Network Time Protocol,网络时间协议)是用来使计算机时间同步的一种协议。它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒)。对于服务器群集来说,这个是一个很重要的服务,因为群集需要保证每个服务器的时间是保持一致的,这样它们在执行同一个任务时才不会出现有的服务器有滞后的现象,这样群集的状态才是健康的。
- NTP的工作模式:C/S模式
- NTP的协议及端口号:UDP协议123号端口
ntp时间同步的配置
服务器配置
yum -y install ntpdate
yum -y install ntp
vim /etc/ntp.conf
restrict default nomodify #第8行
restrict 192.168.17.0 mask 255.255.255.0 nomodify notrap #第17行
#server 0.centos.pool.ntp.org iburst #第21到第24行删除,或注释掉
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
fudge 127.127.1.0 stratum 8 #添加内容
server 127.127.1.0 #添加内容
systemctl start ntpd
crontab -e
* * * * * /usr/sbin/ntpdate ntp.aliyun.com
客户端配置
yum -y install ntpdate
ntpdate 192.168.17.10
crontab -e
* * * * * /usr/sbin/ntpdate 192.168.17.10
效果验证