ntp-time synchronization

1. Role

NTP是用来使用计算机时间同步的一种协议。它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正(LAN上与标准时间差小于1毫秒,WAN上几十毫秒)。
对于服务器群集来说,这是一个很重要的服务,因为群集需要保证每个服务器的时间是保持一致的,这样他们在执行同一个任务时才不会出现有的服务器有滞后的现象,这样群集的状态才是健康的。

2. NTP working mode

C/S模式

3. NTP protocol and port number

UDP协议123号端口

Four. Configuration steps

1. Server side

yum -y install ntp ntpdate
ntpdate ntp,aliyun.com   //先保证自己的时间是正确的

Modify the configuration file

vi /etc/ntp.conf
8 restrict default nomodify
#restrict、default定义默认访问规则, nomodify禁止远程主机修改本地服务器配置。17 restrict 20.0.0.0 mask  255.255.255.0 nomodify notrap
#从20.0.0.1-20.0.0.254的主机都可以使用我们的NTP服务器来同步时间21-24行删除

加两行
fudge 127.127.1.0 stratum 10    //设置本机的时间层级为10级,0级代表时间层级是0级,是向其他服务器提供时间同步源的意思,不要设置为0级
Stratum 0
 //NTP网络从权威时间源获取时间。这些权威的时间源,也称为第0层设备,是高精度的计时设备,被认为是准确的,并且几乎没有延迟或与之相关联。

Stratum 1
第1层设备直接连接到权威时间源。它们充当主要的网络时间标准。

Stratum 2 and Lower
第2层服务器通过网络连接连接到第1层设备。诸如NTP客户端之类的第2层设备通过使用第1层服务器的NTP数据包来同步其时间。它们还可以充当第3层设备的服务器。
较小的层号表示服务器比较大的层号更接近授权时间源。层数越大,权威性越低。最大跃点数为15。
层16(最低层级别)指示设备未同步。可以将同一层级别上的时间服务器配置为与同一层级别上的其他时间服务器作为对等方,以备份或验证时间。
server 172.127.1.0   //指定本机为时间同步源

Start service

systemctl start ntpd

Check service opening

netstat -anpu | grep ntpd

Set up recurring schedule

crontab -e

Verification effect

date 验证下时间(获取本地时间,格式是年月日时分秒)

2. Client

Install synchronization software

yum -y install ntpdate

Set synchronization source

ntpdate 20.0.0.10

Create a task plan

crontab -e
* * * * * /usr/sbin/ntpdate 20.0.0.10

Verification effect

date 验证下时间

Guess you like

Origin blog.csdn.net/weixin_45647891/article/details/111993419