OceanBase products have implicit relationships in time. Therefore, the physical time on all servers of the OceanBase products must be synchronous with an offset of less than 100 ms or even smaller. Therefore, the clocks of multiple nodes in a cluster and OCP nodes must be configured with the clock synchronization service (NTP or Chrony) to ensure that the clock offset of all nodes is within 100 ms. This topic describes how to configure the clock source under the Network Time Protocol (NTP) for multiple servers in a cluster. Skip this topic if you install OceanBase Database on a single server.
Note
The clocks of servers in the OceanBase cluster must be synchronized. Otherwise, the OceanBase cluster may not start or will encounter operational exceptions. A physical server is synchronous with the clock source server when the clock offset between them is 50 ms or lower. The tolerable clock offset of an OceanBase cluster cannot exceed 100 ms. When the clock offset exceeds 100 ms, the cluster may become leaderless. You can synchronize the clock and restart the OceanBase cluster to restore it to normal. If you have already configured the NTP clock source, no need to do it again.
Prerequisites
You have the root user privileges on all OBServers.
Procedure
Perform the following steps to configure the NTP clock source.
Note
Generally, the built-in NTP service of Linux can be used for time synchronization. If the current environment has a stable and reliable NTP server, this NTP server is used as the NTP source of all servers. If no such NTP server is available, a fixed server is selected as the NTP source.
Install the NTP source on each server through the YUM package manager.
[root@xxx /]# yum install ntp ntpdate -yConfigure the
ntp.conffile.[root@xxx /]# vi /etc/ntp.conf restrict default ignore restrict 127.0.0.1 restrict 192.168.0.0 mask 255.255.0.0 driftfile /var/lib/ntp/drift pidfile /var/run/ntpd.pid #logfile /var/log/ntp.log # local clock server 127.127.1.0 fudge 127.127.1.0 stratum 10 server 192.168.XX.XX iburst minpoll 4 maxpoll 6Parameters:
restrictspecifies the privileges of time synchronization commands related to the IP address.restrict [IP] mask [netmask_IP] [parameter]Valid values of
parameter:ignore,nomodify,noquery,notrap, andnotrust.ignorespecifies to reject all types of NTP synchronization by default.serverspecifies the upper-level NTP source server.server [IP or hostname] [prefer]if no upper-level NTP source server is available, the
serverparameter can be set to127.127.1.0, which means that the local server is used as the NTP source server.
Restart the NTP synchronization service.
[root@xxx /]# systemctl restart ntpd [root@xxx /]# systemctl status ntpdCheck the NTP synchronization status.
Note
If the NTP service has just been started, you need to wait for a moment before running the
ntpstatcommand.[root@xxx /]# ntpstat [root@xxx /]# ntpq remote refid st t when poll reach delay offset jitter ======================================================================== LOCAL(0) .LOCL. 10 l 589 64 0 0.000 0.000 0.000 *192.168.XX.XX 10.10.10.1 2 u 18 64 377 1.591 0.249 0.054Parameters in the result of the
ntpqcommand:remote: indicates the NTP server used.*indicates the current NTP server.LOCALindicates that the local server is used as the NTP server.xindicates that the NTP server is no longer used.-indicates that the NTP server is no longer used.+indicates that the NTP server is in good conditions and preferred.#indicates that the NTP server is in good conditions but not used.refid: indicates the higher-level NTP server used by the remote NTP server.INITindicates that the higher-level NTP server is being obtained.st: indicates the stratum of the remote NTP server.when: indicates the period from the last synchronization to the current time, in seconds by default.hindicates hour anddindicates day.poll: indicates the synchronization frequency, in seconds.delay: indicates the roundabout time from the local server to the remote NTP server, in milliseconds.offset: indicates the time offset between the local server and the remote NTP server, in milliseconds.jitter: indicates the average deviation in the time offset between the local server and the remote NTP server, in milliseconds.
Conduct final check.
Use the following sample code for reference to conduct final synchronization latency check:
[root@xxx /]# clockdiff 192.168.XX.XX .................................................. host=192.168.XX.XX rtt=1(0)ms/1ms delta=0ms/0ms Sat Apr 18 14:41:40 2020(Optional) Perform manual synchronization.
If the time deviation is always great, you can use the
ntpdatecommand to manually correct the time. This conflicts with the automatic synchronization service. Therefore, before you manually correct the time, you need to stop the NTP service first.[root@xxx /]# systemctl stop ntpd [root@xxx /]# ntpdate -u 192.168.XX.XX 18 Apr 14:54:20 ntpdate[108001]: adjust time server 192.168.XX.XX offset -0.000180 secIf this method is effective, you can configure it in
crontabof the system.[root@xxx /]# crontab -e * * * * * /sbin/ntpdate -u 192.168.XX.XX 2>&1 1>>/tmp/ntpupdate.log(Optional) Configure the firewall rule.
In a standard environment, the firewall needs to be disabled. If the firewall must be enabled in a server environment, comply with the following rule:
[root@xxx /]# iptables --A INPUT --p udp --i eth0 --s 192.168.1.0/16 --dport 123 --j ACCEPT [root@xxx /]# systemctl restart ntpd