This is a study note for the hook course

Clock synchronization is a problem

As shown in the figure, three concurrent orders are almost processed at the same time. Due to inconsistent server clocks, the order time of entering the database is very different, resulting in data confusion.

Configure cluster clock synchronization

There are two scenarios

1. All nodes in the distributed cluster can connect to the InternetOperation mode:

Ntpdate -u ntp.api.bz # Synchronize time from a time serverCopy the code

Windows Scheduled task Linux also has scheduled task, crond, you can use Linux scheduled task, run the ntpdate command every 10 minutes

2. A server node in a distributed cluster can access the Internet or all nodes cannot access the Internet

Operation mode:

1) Select A server node (172.17.0.17) in the cluster as the time server (the entire cluster time is synchronized from this server. If this server can access the Internet, you can synchronize the server time with the network time. If this server cannot access the Internet, set A time manually.)

  • First, set the time of A
  • Configure A as the time server (modify the /etc/ntp.conf file)
1If restrictdefaultIgnore, comment it out2Add the following lines restrict172.17. 0. 0 mask 255.255255.. 0Nomodify notrap # enable LAN synchronization172.17. 0. 0Is your LAN network segment server127.1271.. 0 # local clock
 fudge 127.1271.. 0 stratum 10
3Service NTPD restart chkconfig NTPD on service NTPD restart chkconfig NTPD onCopy the code
  • The other nodes in the cluster can then synchronize time from server A
ntpdate 172.17. 017.
Copy the code