本文介绍在不配置只读副本的情况下,如何通过 OBProxy 的 LDC 属性配置 OceanBase 数据库的读写分离集群。
适用版本
OceanBase 数据库所有版本
本文档适用于 2-2-2 及以上配置的集群。
配置读写分离集群
本文中,
xxx.xxx.xx.xx1
、
xxx.xxx.xx.xx2
为
zone1
中的两台 OBServer,
xxx.xxx.xx.xx3
、
xxx.xxx.xx.xx4
为
zone2
中的两台 OBServer,
xxx.xxx.xx.xx5
、
xxx.xxx.xx.xx6
为
zone3
中的两台 OBServer。
本文以在
zone3
的会话层开启弱读,实现基于非 Primary Zone 副本的读写分离实现。
-
首先查看 OceanBase 数据库非 Primary Zone 的 IDC 属性。
-
其中
name
为
idc
的行的
info
列即为各 Zone 的 IDC 属性。
obclient> SELECT svr_ip,zone FROM __all_server ORDER BY zone; ±---------------±------+ | svr_ip | zone | ±---------------±------+ | xxx.xxx.xx.xx1 | zone1 | | xxx.xxx.xx.xx2 | zone1 | | xxx.xxx.xx.xx3 | zone2 | | xxx.xxx.xx.xx4 | zone2 | | xxx.xxx.xx.xx5 | zone3 | | xxx.xxx.xx.xx6 | zone3 | ±---------------±------+ obclient> SELECT * FROM __all_zone WHERE name=‘idc’; ±---------------------------±---------------------------±------±-----±------±-----+ | gmt_create | gmt_modified | zone | name | value | info | ±---------------------------±---------------------------±------±-----±------±-----+ | 2020-09-16 16:36:54.226819 | 2020-09-16 16:56:34.488518 | zone1 | idc | 0 | c3 | | 2020-09-16 16:36:54.228121 | 2020-09-16 16:56:34.599247 | zone2 | idc | 0 | c4 | | 2020-09-16 16:36:54.229390 | 2020-09-16 16:56:34.713054 | zone3 | idc | 0 | c6 | ±---------------------------±---------------------------±------±-----±------±-----+ 3 rows in set (0.012 sec)
-
配置 OBPROXY 的 LDC 设置。需要在每个 OBProxy 的节点配置。
-
配置
xxx.xxx.xx.xx5
与
xxx.xxx.xx.xx6
的 OBProxy,将 IDC 名称设置为
c6
。
obclient -hxxx.xxx.xx.xx5 -P2883 -u@# -p obclient> ALTER PROXYCONFIG SET proxy_idc_name=‘c6’; obclient -hxxx.xxx.xx.xx6 -P2883 -u@# -p obclient> ALTER PROXYCONFIG SET proxy_idc_name=‘c6’;
- 登录 OceanBase 数据库,设置会话变量为弱一致性读。
obclient -hxxx.xxx.xx.xx6 -P2883 -u@# -p obclient> SET @@ob_read_consistency=‘weak’;