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
OceanBase Database V4.1 allows for a time deviation limit of up to 2 seconds. Moreover, this version supports dynamic clock modification with no effect on the accuracy of data or stability of a cluster.
Prerequisites
You have the root user privileges on all OBServer nodes.
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 server parameter can be set to
127.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 ntpstat command.
[root@xxx /]# ntpstat
[root@xxx /]# ntpq -p
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 xxx.xxx.xxx.xxx 2 u 18 64 377 1.591 0.249 0.054
Parameters in the result of the ntpq command:
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 condition and is preferred.#indicates that the NTP server is in good condition but is 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 the 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 you notice a significant time deviation, you can manually correct it by using the
ntpdatecommand. However, this method conflicts with automatic synchronization services and requires stopping 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 crontab of 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