2-2-1 Distributed cluster clock synchronization problems and solutions

1. Cluster clock synchronization problem

1.1 Problems caused by unsynchronized clocks

The clock here refers to the server time. If the clocks of each server in the cluster are inconsistent, it will inevitably lead to a series of problems. Imagine that "a cluster is a team operation of each server, and the work of each family is not at one point, so it is not a mess. !"

For example, in the e-commerce website business, if an order is added, then a record will be added to the order table. There should be a field such as "order time" in this record. Often we Will get the current system time in the program and insert it into the database or get the time directly from the database server. Then our order sub-system is a cluster deployment, or our database is also a cluster deployment of sub-databases and sub-tables, but their system clock is inconsistent. If the time of a server is yesterday, then this time The order time became yesterday, then our data will be confused! as follows

Insert picture description here

1.2 Solution

1.2.1 Scenario 1: Each server node in a distributed cluster can be connected to the Internet

Insert picture description here
Operation method:

#使⽤ ntpdate ⽹络时间同步命令
ntpdate -u ntp.api.bz #从⼀个时间服务器同步时间

Windows has scheduled tasks,
Linux also has scheduled tasks, crond, you can use Linux's scheduled tasks to execute the ntpdate command every 10 minutes

1.2.2 A certain server node in a distributed cluster can access the Internet or all nodes cannot access the Internet

Insert picture description here

Operation Modes:
1) Select the cluster server nodes ⼀ A (172.17.0.17) as a time server (the entire cluster services from this time
synchronization, if this server to access the Internet ⽹ allows this server and web sites Keep the network time in sync. If you
can’t, manually set a time)
First set the time
of A, configure A as a time server (modify the /etc/ntp.conf file)


1、如果有 restrict default ignore,注释掉它
2、添加如下⼏⾏内容
 restrict 172.17.0.0 mask 255.255.255.0 nomodify notrap # 放开局
域⽹同步功能,172.17.0.0是你的局域⽹⽹段
 server 127.127.1.0 # local clock
 fudge 127.127.1.0 stratum 10
3、重启⽣效并配置ntpd服务开机⾃启动
 service ntpd restart
 chkconfig ntpd on

Other nodes in the cluster can synchronize time from server A


ntpdate 172.17.0.17

Guess you like

Origin blog.csdn.net/qq_42082278/article/details/112602056