OceanBase products are implicitly correlated to each other in time. Therefore, the physical time on all servers of OceanBase products must be synchronized with a latency of no more than 2s. Therefore, the Network Time Protocol (NTP) service or chrony service must be configured for the clocks of nodes in the cluster and the OceanBase Cloud Platform (OCP) node to ensure a clock offset of no more than 2s for all nodes. This topic describes how to configure an NTP clock source for multiple servers in a cluster.
You do not need to configure an NTP clock source for a standalone OceanBase database.
Prerequisites
You have the root user permissions on all servers.
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 by using 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 6where
restrictspecifies the privileges of time synchronization commands related to the IP address.restrict [IP] mask [netmask_IP] [parameter]Valid values of
parameterareignore,nomodify,noquery,notrap, andnotrust. Here,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
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 xxx.xxx.xxx.xxx 2 u 18 64 377 1.591 0.249 0.054Parameters in the result of the
ntpqcommand are described as follows: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.
The following example is for your 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 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