This topic describes how to configure the Network Time Protocol (NTP) clock source for servers in a cluster. If you are planning to deploy OceanBase Database on a single server, or for personal testing purposes, or if you have already configured NTP clock synchronization, skip this step.
However, if you plan to deploy a distributed OceanBase cluster, it is necessary to ensure time synchronization among all servers in the cluster. Otherwise, the cluster will not be able to start, and the services may encounter exceptions during runtime. The allowed clock deviation in the OceanBase cluster should not exceed 2 seconds. If the deviation exceeds 2 seconds, the cluster may become leaderless. To restore it to normal, you will need to restore clock synchronization and restart the OceanBase cluster.
Note
Starting from V4.1.0, OceanBase Database supports dynamic modification of clocks without impacting data accuracy and stable cluster operation.
If the nodes for deploying OCP Express or OCP are different from that for deploying the OceanBase cluster, you need to synchronize the clock source between the OCP Express or OCP nodes and the OceanBase cluster nodes. This prevents operational exceptions in OCP Express or OCP due to clock deviations.
Prerequisites
You have the root user privileges on all nodes.
Procedure
Perform the following steps to configure the NTP clock source.
Run the following command on each server to install NTP:
yum install ntp ntpdate -yRun the following command to check the NTP connection to the server:
[root@centos-01 ~]# 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) Enable the NTP service.
If you already have an NTP server, skip this step. The following example describes how to enable time synchronization by taking the server
10.10.10.1as the NTP server.Edit the configuration file.
Log on to the NTP server as the root user and run the following command to edit the configuration file:
vi /etc/ntp.confAdd the following content to the configuration file:
server <your_ntp_server_ip>Save and close the file.
Run the following command to restart the NTP service:
service ntpd restartRun the following command to check whether the NTP service is enabled:
ps -ef | grep -i ntpdRun the following command to enable the NTP service upon startup.
chkconfig ntpd on
Enable the NTP service.
Note
You can enable the NTP service 5 minutes after the NTP server is started. Otherwise, the system prompts "no server suitable for synchronization found".
Log on to OceanBase Database as the root user.
Run the following command to stop the NTP service:
service ntpd stopRun the following command to synchronize the time with the NTP server:
ntpdate 10.10.10.1Edit the configuration file.
Run the following command to open the configuration file:
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:
/etc/init.d/ntpd start
Verify that the configuration is successful.
Run the following command:
ntpstatThe following output 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 following command:
timedatectlThe following output 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/aThe outputs above indicate that the NTP service takes effect.