This topic describes how to configure an NTP clock source for multiple machines in a cluster. If you plan to deploy OceanBase Database on a single machine, for personal testing, or if you have already configured NTP clock synchronization, this setting is not required.
If you plan to deploy a distributed OceanBase cluster, you must ensure that the time on all machines within the cluster is synchronized. Otherwise, the cluster cannot be started, and service exceptions may occur during runtime. The allowable clock skew in an OceanBase cluster cannot exceed 2 seconds. When it exceeds 2 seconds, a leaderless state occurs. After restoring clock synchronization, restart the OceanBase cluster to restore normal operation.
Note
This topic provides operational guidance based on the x86 architecture CentOS Linux 7.9 image environment. Other environments may differ slightly; please refer to your actual environment.
OceanBase Database supports dynamic clock modification starting from V4.0.0. Modifications within a 2-second interval do not affect data correctness or the stable operation of the cluster.
If OCP is not deployed on the OceanBase cluster nodes, clock synchronization must also be configured for the OCP nodes and the OceanBase cluster nodes to avoid OCP operational exceptions caused by clock skew during use.
Prerequisites
Before configuring the NTP clock source, ensure you have root user privileges on all machines.
Procedure
Follow these steps to configure NTP clock synchronization.
On each machine, run the following command to install NTP.
[root@test002 ~]# yum install ntp ntpdate -yRun the following command to check the server's NTP connection.
[root@test002 ~]# ntpq -4p remote refid st t when poll reach delay offset jitter ============================================================================== *time6.aliyun.co xxx.xxx.xxx.xxx 2 u 712 1024 377 21.951 4.253 4.208(Optional) Start the NTP server service.
If you already have an NTP server, skip this step. This document uses the target machine
10.10.10.1as the NTP server.Edit the configuration file.
Log in to the NTP server as the root user and run the following command to edit the configuration file:
[root@test001 ~]# vi /etc/ntp.confAdd the following content to the configuration file:
server <your_ntp_server_ip>Save and close the configuration file.
Run the following command to restart the NTP server service:
[root@test001 ~]# service ntpd restartRun the following command to check whether the NTP server service has started successfully:
[root@test001 ~]# ps -ef | grep -i ntpdRun the following command to set the NTP service to start automatically at boot:
[root@test001 ~]# chkconfig ntpd on
Enable the NTP client service.
Notice
After the NTP server service is started, you must wait for 5 minutes before enabling the NTP client service. Otherwise, the system will display the message "no server suitable for synchronization found".
Log in to the OBServer node server as the root user.
Run the following command to stop the NTP service:
[root@test002 ~]# service ntpd stopRun the following command to synchronize time from the NTP server:
[root@test002 ~]# ntpdate 10.10.10.1Edit the configuration file.
Run the following command to open the configuration file:
[root@test002 ~]# vi /etc/ntp.confAdd the following content to the configuration file:
server <your_ntp_server_ip>Run the following command to start the NTP service:
[root@test002 ~]# /etc/init.d/ntpd start
Run the following command to verify that the configuration is successful.
Run the command:
[root@test002 ~]# ntpstatThe following result is returned:
synchronised to NTP server (xxx.xxx.xxx.xxx) at stratum 3 time correct to within 2 ms polling server every 64 sRun the command:
[root@test002 ~]# timedatectlThe following result is returned:
Local time: Thu 2021-04-22 11:02:32 CST Universal time: Thu 2021-04-22 03:02:32 UTC RTC time: Thu 2021-04-22 11:02:32 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yes NTP synchronized: yes RTC in local TZ: yes DST active: n/aIf the preceding command returns the corresponding result, the NTP service is effective.
