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, or if you have already configured NTP clock synchronization, skip this step.
However, if you plan to deploy a distributed OceanBase cluster, ensure that the time on each server in the cluster is synchronized. Otherwise, the cluster does not start, and services may encounter exceptions during operation. The OceanBase cluster only allows a maximum clock deviation of 2 seconds. If the deviation is exceeded, 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 version 4.1.0, OceanBase Database supports dynamic modification of clocks without affecting data accuracy and stable cluster operation.
Prerequisites
You have the root user privileges on all OBServer 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 on an OBServer node.
Note
You can enable the NTP service on an OBServer node 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 whether the configuration is successful.
Run the following command:
ntpstatFor example, the 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:
timedatectlFor example, the 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 output above indicates that NTP service is running.