原理图
1.目标端集群将数据请求由gcluster的5258端口发送至dblink的9898端口
2.Dblink将请求由9898端口转发至源端集群的5258端口
3.源端数据库将接收的请求生成执行计划,由gcluster的5258端口下发至各gnode的5050端口
4.源端的5050端口接收到执行计划进行查询,并将返回结果与目标端集群的gnode的5050端口直接通讯。
5.目标端Gnode将查询结果汇总到gcluster层。
需求描述
多vc模式,源数据库B的t1数据库下存在t11两张表,现需要从数据库A建立DBlink访问数据库B的表。数据库A:
10.185.195.10 coor
10.185.195.101 data
10.185.195.102 data
vc:vc1数据库B:
10.185.195.199 coor
10.185.195.200 data
10.185.195.201 data
vc:vc1
---------------------------------安装---------------------------------------
一、源数据库B操作
### 1.1 建立用户设置默认VC
create user source_user identified by 'source_password';
set default_vc for source_user = vc1;### 1.2 授予库的权限
grant all on vc1.t1.* to source_user;
#select不授权会报错"ERROR 1105 (HY000): Table 'information_schema.table_distribution' doesn't exist",后面两个权限貌似可以不用授权
grant select on gbase.* to gbase_user;
#grant all on gctmpdb.* to gbase_user;
#grant all on vc1.gclusterdb.* to gbase_user;二、数据库A操作
### 2.1 建立用户
create user gbase_user identified by 'gbase_password';### 2.2 创建数据库与授权
create database t1_new;
grant all on vc1.t1_new.* to gbase_user;### 2.3 授权[第一个管理节点]
grant select on gbase.* to gbase_user;
grant all on gctmpdb.* to gbase_user;
grant all on vc1.gclusterdb.* to gbase_user;### 2.4 授权[所有数据节点]
gccli -ugbase -p -h 10.185.195.101 -P5050 -e "grant all on gctmpdb.* to gbase_user"
gccli -ugbase -p -h 10.185.195.102 -P5050 -e "grant all on gctmpdb.* to gbase_user"### 2.5 检查DBlink配置
# 所有管理节点的"[gbasedump]"上方加DBlink的ip与端口,我的DBlink准备配置在数据库A的管理节点上。配置完需要重启集群哦!
[gbase@GBASEMA01 config]$ pwd
/opt/10.185.195.10/gcluster/config
[gbase@GBASEMA01 config]$ cat gbase_8a_gcluster.cnf
...
gbase_dblink_gateway_ip = 10.185.195.10
gbase_dblink_gateway_port = 9898
gcluster_dblink_direct_data_exchange = 0
...
[gbasedump]三、数据库A DBlink配置
### 3.1 数据源配置[这里写的是源数据库B的信息]
[gbase@GBASEMA01 dataSource]$ pwd
/opt/GBase8a_MPP_Cluster_Gateway_8.5.1.2_build4.26/conf/dataSource
[gbase@GBASEMA01 dataSource]$ vim gbase_link_t1.properties
[gbase1]
dataSource_IP=10.185.195.199
dataSource_port=5258
dataSource_dbname=t1
dataSource_dbtype=gcluster
dataSource_user=source_user
dataSource_pwd=source_password
dataSource_charset=utf8### 3.2 数据库配置[这里写的是数据库A的信息]
[gbase@GBASEMA01 gcluster]$ pwd
/opt/GBase8a_MPP_Cluster_Gateway_8.5.1.2_build4.26/conf/gcluster
[gbase@GBASEMA01 gcluster]$ cat gbase8a_gcluster.properties
[gc1]
gcluster_IP=10.185.195.10
gcluster_port=5258
gcluster_user=gbase_user
gcluster_pwd=gbase_password
gcluster_encode=utf-8[gn2]
gcluster_IP=10.185.195.101
gcluster_port=5050
gcluster_user=gbase_user
gcluster_pwd=gbase_password
gcluster_encode=utf-8[gn2]
gcluster_IP=10.185.195.102
gcluster_port=5050
gcluster_user=gbase_user
gcluster_pwd=gbase_password
gcluster_encode=utf-8### 3.3 启动DBlink[端口是9898可以检查下]
[gbase@GBASEMA01 GBase8a_MPP_Cluster_Gateway_8.5.1.2_build4.26]$ pwd
/opt/GBase8a_MPP_Cluster_Gateway_8.5.1.2_build4.26
[gbase@GBASEMA01 GBase8a_MPP_Cluster_Gateway_8.5.1.2_build4.26]$ bash gbaseGatewayServer.sh start### 3.4 建立DBlink
gbase> use vc vc1;
gbase> create database link gbase_link_t1 connect to '' identified by '' using 'gbase_link_t1';### 3.5 连接测试
[gbase@GBASEMA01 config]$ gccli -ugbase_user -pgbase_password
use vc vc1;
use t1_new;
select * from t11@gbase_link_t1;
---------------------------------验证---------------------------------------
一、数据库权限验证
### 1.1 源数据库B权限验证
gbase> show grants for source_user;
+-----------------------------------------------------------------------------------------------------------------------------------+
| Grants for source_user@% |
+-----------------------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.*.* TO 'source_user'@'%' IDENTIFIED BY PASSWORD '*A06F45AD457FDD278DBDFB5061E99288102FA8D3' WITH TASK_PRIORITY 2 |
| GRANT ALL PRIVILEGES ON "vc00001"."t1".* TO 'source_user'@'%' |
| GRANT ALL PRIVILEGES ON "vc00001"."t2".* TO 'source_user'@'%' |
| GRANT SELECT ON "gbase".* TO 'source_user'@'%' |
+-----------------------------------------------------------------------------------------------------------------------------------+### 1.2 数据库B权限验证
# 第一个管理节点
gbase> show grants for gbase_user;
+----------------------------------------------------------------------------------------------------------------------------------+
| Grants for gbase_user@% |
+----------------------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.*.* TO 'gbase_user'@'%' IDENTIFIED BY PASSWORD '*88F4CD22002C0CB142518B20244FBCCA8A94493A' WITH TASK_PRIORITY 2 |
| GRANT SELECT ON "gbase".* TO 'gbase_user'@'%' |
| GRANT ALL PRIVILEGES ON "gctmpdb".* TO 'gbase_user'@'%' |
| GRANT ALL PRIVILEGES ON "vc00001"."gclusterdb".* TO 'gbase_user'@'%' |
| GRANT ALL PRIVILEGES ON "vc00001"."t1_new".* TO 'gbase_user'@'%' |
+----------------------------------------------------------------------------------------------------------------------------------+
5 rows in set (Elapsed: 00:00:00.00)# 所有数据节点
[gbase@GBASEMA01 logs]$ gccli -ugbase -p -h 10.185.195.101 -P5050 -e "show grants for gbase_user"
+--------------------------------------------------------------------------------------------------------------------------------+
| Grants for gbase_user@% |
+--------------------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'gbase_user'@'%' IDENTIFIED BY PASSWORD '*88F4CD22002C0CB142518B20244FBCCA8A94493A' WITH TASK_PRIORITY 2 |
| GRANT ALL PRIVILEGES ON "gctmpdb".* TO 'gbase_user'@'%' |
+--------------------------------------------------------------------------------------------------------------------------------+
[gbase@GBASEMA01 logs]$ gccli -ugbase -p -h 10.185.195.102 -P5050 -e "show grants for gbase_user"
+--------------------------------------------------------------------------------------------------------------------------------+
| Grants for gbase_user@% |
+--------------------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'gbase_user'@'%' IDENTIFIED BY PASSWORD '*88F4CD22002C0CB142518B20244FBCCA8A94493A' WITH TASK_PRIORITY 2 |
| GRANT ALL PRIVILEGES ON "gctmpdb".* TO 'gbase_user'@'%' |
+--------------------------------------------------------------------------------------------------------------------------------+二、数据验证
### 2.1 源数据库B
[gbase@GBASEMA01 ~]$ gccli -usource_user -psource_password -e "use t1;select count(*) from t11;"
+----------+
| count(*) |
+----------+
| 2 |
+----------+### 2.2 数据库A
[gbase@GBASEMA01 logs]$ gccli -ugbase_user -pgbase_passwordGBase client 9.5.3.27.20_patch.9fc3fcec. Copyright (c) 2004-2025, GBase. All Rights Reserved.gbase> use vc vc1;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)gbase> use t1_new;
Query OK, 0 rows affected (Elapsed: 00:00:00.00)gbase> select * from t11@gbase_link_t1;
+------+------+
| id | name |
+------+------+
| 1 | mmm |
| 2 | ddd |
+------+------+
2 rows in set (Elapsed: 00:00:00.07)三、数据库A:DBlink验证
gbase> select * from gbase.db_links;
+--------+---------------+-------------+----------+----------+---------------+---------------------+
| owner | db_link | dblink_priv | username | password | host | created |
+--------+---------------+-------------+----------+----------+---------------+---------------------+
| public | gbase_link_t1 | PUBLIC | | NULL | gbase_link_t1 | 2025-01-24 17:08:29 |
+--------+---------------+-------------+----------+----------+---------------+---------------------+
1 row in set (Elapsed: 00:00:00.08)