OceanBase 数据库时钟源排查的相关指南

OceanBase 集群的正常运行依赖稳定的时钟源,同集群内 OBServer 服务器间如果发生较大系统时间偏差(例如异常时钟跃变),可能导致预期外集群级稳定性风险,导致表分区无法选主成功,进而影响数据库访问。本文主要介绍 OceanBase 数据库及相关产品时钟源检查的方法。

适用版本

OceanBase 数据库所有版本

基础设施层检查

由于虚机相比物理机存在时间不稳定风险,可能导致链路中时钟源自守时,整个时钟源链路要求使用物理设备。 时钟源服务架构为:

OBServer → 本地时钟源 → 上级时钟源 → 外部时钟源

其中,外部时钟源选择北斗 + GPS 或北斗 + 原子钟;本地和上级时钟源选择物理机。

时钟源要求满足以下标准:

  • 支持 NTP v1、v2、v3、v4,(RFC1119&1305)、SNTP(RFC2030)、Telnet(RFC854)、TIME(RFC868) 与 DAYTIME(RFC867)
  • 用户容量:NTP 请求量支持 20000 次/秒,可支持数万台客户端
  • 守时精度小于 3 ms/年
  • 日平均准确度优于 1E-12
  • 日漂移率优于 3E-12
  • 秒稳定度优于 1E-11

后接评论区————

OceanBase 一般部署形态的检查方法

本节内容适用于打通 SSH 并安装 PGM 工具的场景。

  1. 各 OBServer 服务器间打通 SSH 连接。
  2. 在任一 OBServer 服务器执行以下命令,其中 
    dest_ip
     为其余各 OBServer 的 IP 地址。
[admin@hostname ~]$ ssh-keygen -t rsa
[admin@hostname ~]$ cat id_dsa.pub >> ~/.ssh/authorized_keys
[admin@hostname ~]$ chmod 644 authorized_keys
[admin@hostname ~]$ scp -r ~/.ssh dest_ip:~/
  1. 在各 OBServer 服务器上安装 PGM 工具。
[root@hostname /]# yum install -y pgm
  1. 通过 admin 用户登录任意一台 OBServer 服务器,在本地创建一个包含所有 OBServer 的 IP 地址的文件 
    oblist
xxx.xxx.xx.xx1
xxx.xxx.xx.xx2
xxx.xxx.xx.xx3
  1. 检查当前的 Chronyc 的同步状态。如果状态为 
    Normal
    ,则表示时钟同步。
[admin@hostname ~]$ sudo pgm -b -f oblist -l root "chronyc -n tracking"|grep -E "SUCCESS|Leap"
[1] 14:52:03 [SUCCESS] xxx.xxx.xx.xx1
Leap status          : Normal
[2] 14:52:03 [SUCCESS] xxx.xxx.xx.xx2
Leap status          : Normal
[3] 14:52:03 [SUCCESS] xxx.xxx.xx.xx3
Leap status          : Normal
  1. 检查 OBServer 服务器当前的 Chronyc Offset。
  2. 多次执行以下命令,如果结果小于 
    100000 us
    ,则表示时钟同步在可接受范围内。
[admin@hostname ~]$ sudo pgm -b -f oblist -l root "chronyc sources -v"|grep -E "SUCCESS|^\^\*"
MS Name/IP address            strarum Poll Reach LastRX Last sample
==================================================================================
^- am35.ntp1.tbsite.net             6  4    377      15 -251us [ -251us]   -/-  128ms
^* ntp2.tbsite.net                  6  4    377      16 -322us [ -340us]   -/-  126ms
  1. 横向检查当前 OBServer 服务器间操作系统的时间对比。
  2. 如果打印出的信息中第三列小于 
    100
    ,且第三列正值减去负值之差小于 
    100
    ,则表示各操作系统间时钟同步。
[admin@hostname ~]$  sudo pgm -f oblist -l root "clockdiff -o `head -1 oblist`" |awk '$3 !=0'
[1] 18:11:31 [SUCCESS] xxx.xxx.xx.xx1 
1624950809 0 1
[2] 18:11:31 [SUCCESS] xxx.xxx.xx.xx2
1624950809 0 0
[3] 18:11:31 [SUCCESS] xxx.xxx.xx.xx3
1624950809 1 2


OceanBase 数据库其他部署形态的检查方法

本节内容适用于对于不具备 SSH 打通与 PGM 工具的场景,可以通过以下方式检查各 OBServer 服务器间的时钟同步状态。

  1. 检查各 OBServer 服务器操作系统间的时间对比。 如果打印出的信息中第三列小于 
    100
    ,且第三列正值减去负值之差小于 
    100
    ,则表示各操作系统间时钟同步。
[admin@hostname ~]$ cat oblist|while read line; do clockdiff -o $line; done
1624950809 0 0
1624950809 0 0
1624950809 0 0
  1. 检查 Chronyc 同步情况。
  2. 如果 
    Leap status
     状态为 
    Normal
    ,则表示时钟同步。
[admin@hostname ~]$  chronyc -n tracking
  1. 检查 OBServer 服务器当前的 Chronyc Offset。
  2. 如果 
    Sample
     列方括号中的值小于 
    100000 us
    ,则表示时钟同步在可接受范围内。
[admin@hostname ~]$ chronyc sources -v
  1. 运行 
    ntpstat
     与 
    ntpq
     检查 NTP 服务器状态。
  2. 如果 
    ntpstat
     结果为 
    synchronised to NTP server
    ,并且 
    ntpq
     命令的结果中 
    offset
     的值小于 
    100ms
    ,则表示 NTP 服务时钟同步。
[root@hostname /]# ntpstat
synchronised to NTP server (xx.xxx.xx.xxx) at stratum 4
   time correct to within 4 ms
   polling server every 32 s
[root@hostname /]# ntpq -p|grep -E "\*|\=|remote"
   remote         refid           st t when poll reach    delay     offset     jitter
==========================================================================
*xxxxxxxxxxx       xxxxx           2 u   16  64  377       1.333     0.046   0.033


可能会有些机器使用

clockdiff
会报错。此时可以换下面命令判断时间同步误差。

[admin@obce02 oceanbase]$ ping -T tsandaddr 172.20.249.52 -c 2
PING 172.20.249.52 (172.20.249.52) 56(124) bytes of data.
64 bytes from 172.20.249.52: icmp_seq=1 ttl=64 time=0.161 ms
TS:   172.20.249.49  24851014 absolute
    172.20.249.52  -1
    172.20.249.52  0
    172.20.249.49  1

64 bytes from 172.20.249.52: icmp_seq=2 ttl=64 time=0.172 ms
TS:   172.20.249.49  24852054 absolute
    172.20.249.52  -1
    172.20.249.52  0
    172.20.249.49  1



1 个赞