标签:完成后 instance wrap 物理 oracle官网 connect 复制表 驱动 下载
本文分别介绍GuassDB跨集群访问远端oracle以及远端MPPDB数据库。因环境有限,这里不列举对接HDFS以及对接Spark功能。Gaussdb要求的unixODBC版本必须为2.3.6。操作系统自带的版本不能正常使用,需要从官方网站单独下载并编译安装。
[root@hd06 ~]# tar -xzf unixODBC-2.3.6.tar.gz
[root@hd06 ~]# cd unixODBC-2.3.6
[root@hd06 unixODBC-2.3.6]# ./configure
[root@hd06 unixODBC-2.3.6]# make
[root@hd06 unixODBC-2.3.6]# make install
安装完成后,需要指定库文件的环境变量,否则使用过程中会报错。
[root@hd06 ~]# vi /etc/profile
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib
[root@hd06 ~]# isql --version
unixODBC 2.3.6
[root@hd06 ~]# su - omm
Last login: Tue Oct 29 16:35:31 CST 2019
[omm@hd06 ~]$ isql --version
unixODBC 2.3.6
保存完成后,必须使环境变量生效。
从oracle官方网站下载如下三个压缩包,然后压缩为package.zip文件。
[root@hd06 tmp]# zip package.zip instantclient-*.zip
adding: instantclient-basic-linux.x64-12.2.0.1.0.zip (stored 0%)
adding: instantclient-odbc-linux.x64-12.2.0.1.0-2.zip (stored 0%)
adding: instantclient-sqlplus-linux.x64-12.2.0.1.0.zip (stored 0%)
登录FusionInsight Manager>选择“集群 > 待操作的集群名称 > 服务 > MPPDB > 对接 > 对接Oracle”,单击“创建”,填写配置组名称,单击“确定”。如下图所示:
参数说明见下表:
输入相关配置参数并上传驱动文件“package.zip”,单击“上传并部署”,等待部署完成。部署完成后,单击“保存”。等待保存配置成功,单击“完成”。然后在集群“概览”页面,选择“更多 > 重启”,执行相应操作重启服务。
注:在服务重启的过程中,系统会把odbc驱动分发到各个节点以完成部署。ODBC的部署目录为:/opt/huawei/Bigdata/mppdb/core/utilslib/fc_conf。
从主机上切换到omm用户,并连接到mppdb数据库,执行下面的语句创建:
[root@hd06 ~]# su - omm
Last login: Tue Oct 29 16:43:45 CST 2019
[omm@hd06 ~]$ gsql -d postgres -p 25308
gsql ((GaussDB Kernel V300R002C00 build 8a9c1eb6) compiled at 2019-08-01 18:47:38 commit 6093 last mr 10175 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
postgres=#CREATE DATA SOURCE ds_oracle TYPE ‘ORACLE‘ OPTIONS (DSN ‘oracle_DSN‘, USERNAME ‘spwuser‘, PASSWORD ‘redhat‘, ENCODING ‘UTF8‘);
CREATE DATA SOURCE
使用下面的语句验证是否可以连接到远端oracle数据库:
postgres=# SELECT * FROM exec_on_extension(‘ds_oracle‘, ‘select * from web_customer;‘) AS (c1 int,c2 text,c3 text,c4 text);
如下图所示:
注:使用“exec_on_extension”之前需要创建Data Source对象。
以下举例将远端的查询结果导入本地表:
[omm@hd06 ~]$ gsql -d postgres -p 25308
gsql ((GaussDB Kernel V300R002C00 build 8a9c1eb6) compiled at 2019-08-01 18:47:38 commit 6093 last mr 10175 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
postgres=#\c rhnschema
rhnschema=# CREATE TABLE dd AS SELECT * FROM exec_on_extension(‘ds_oracle‘, ‘select * from rhnpackagefile;‘) AS (package_id numeric,capability_id numeric,device numeric,
inode numeric,file_mode numeric,username character varying(32),groupname character varying(32),rdev numeric,file_size numeric,mtime timestamp with time zone,
checksum_id numeric,linkto character varying(256),flags numeric,verifyflags numeric,lang character varying(32),created timestamp with time zone,modified timestamp with time zone);
NOTICE: The ‘DISTRIBUTE BY‘ clause is not specified. Using ‘package_id‘ as the distribution column by default.
HINT: Please use ‘DISTRIBUTE BY‘ clause to specify suitable data distribution column.
INSERT 0 6304854
rhnschema=# select count(*) from dd;
count
---------
6304854
(1 row)
GaussDB 200支持两种方式访问远端MPPDB数据库集群,包括通过FusionInsight Manager配置方式和创建Foreign Table的方式。
[omm@hd03 ~]$ gs_guc check -Z coordinator -I all -c "listen_addresses"
expected guc information: hd02: listen_addresses=NULL: [/srv/BigData/mppdb/data1/coordinator/postgresql.conf]
gs_guc check: hd02: listen_addresses=‘localhost,192.168.110.24‘: [/srv/BigData/mppdb/data1/coordinator/postgresql.conf]
Total GUC values: 1. Failed GUC values: 0.
The value of parameter listen_addresses is same on all instances.
listen_addresses=‘localhost,192.168.110.24‘
如果没有监听业务IP,可以使用下面的方法将其加入监听里:
[omm@hd03 ~]$ gs_guc set -I all -Z coordinator -c "listen_addresses=‘localhost,192.168.110.24‘"
expected instance path: [/srv/BigData/mppdb/data1/coordinator/postgresql.conf]
gs_guc set: listen_addresses=‘*‘: [/srv/BigData/mppdb/data1/coordinator/postgresql.conf]
Total instances: 1. Failed instances: 0.
Success to perform gs_guc!
以上只在集群的一个节点有效,其他节点也需要单独操作。另外多个IP之间,用逗号隔开。
在远端集群CN设置认证方式
默认情况下,系统只允许集群各个节点之间互相通信。如果其他网段需要访问就必须设置认证方式,这个在任意一个节点执行即可。
[omm@hd01 ~]$ gs_guc reload -Z coordinator -N all -I all -h "host all all 192.168.120.0/24 sha256"
Begin to perform gs_guc for all coordinators.
Total instances: 3. Failed instances: 0.
Success to perform gs_guc!
设置完成后,重启集群:
[omm@hd01 ~]$ gs_om -t stop && gs_om -t start
[omm@hd06 ~]$ gsql -d postgres -p 25308
gsql ((GaussDB Kernel V300R002C00 build 8a9c1eb6) compiled at 2019-08-01 18:47:38 commit 6093 last mr 10175 )
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
postgres=# CREATE DATA SOURCE ds_mppdb type ‘MPPDB‘ OPTIONS (DSN ‘mppdb_DSN‘, USERNAME ‘spwuser‘, PASSWORD ‘abcABC12‘, ENCODING ‘UTF8‘);
CREATE DATA SOURCE
postgres=# SELECT * FROM exec_on_extension(‘ds_oracle‘, ‘select * from web_customer;‘) AS (c1 int,c2 text,c3 text,c4 text);
c1 | c2 | c3 | c4
----+------+-----------------------------+-----------------------------
1 | xzxj | 2019-4-11 8:42:35.094133000 | 2019-4-11 8:42:35.094168000
(1 row)
注意事项:
postgres=# CREATE SERVER Gauss1 FOREIGN DATA WRAPPER GC_FDW OPTIONS
(address ‘192.168.110.22:25308,192.168.110.23:25308,192.168.110.24:25308‘ ,
dbname ‘rhnschema‘, username ‘spwuser‘, password ‘abcABC12‘);
创建外表并查看
postgres=# CREATE FOREIGN TABLE f_web_customer
(
ID NUMERIC,
NAME character varying(128),
CREATED timestamp with time zone,
MODIFIED timestamp with time zone
)
SERVER Gauss1 OPTIONS
(
schema_name ‘public‘,
table_name ‘web_customer‘,
encoding ‘UTF-8‘
);
postgres=# \d f_web_customer;
使用外表进行导入数据
postgres=# CREATE TABLE local_web_customer
(
ID NUMERIC,
NAME character varying(128),
CREATED timestamp with time zone,
MODIFIED timestamp with time zone
);
postgres=# INSERT INTO local_web_customer SELECT * FROM f_web_customer;
INSERT 0 1
postgres=# select *from local_web_customer;
标签:完成后 instance wrap 物理 oracle官网 connect 复制表 驱动 下载
原文地址:https://blog.51cto.com/candon123/2446396