greenplum使用gplink连接外部数据源

发布时间:2020-10-15 00:06:10 作者:知者不言
来源:网络 阅读:3503

    作为一个基于postgresql开发的数据仓库,随着近几年大数据概念的兴起也备受关注。

    由于GP是近近几年才开源的数据库,网上资料很少,不像mysql这样烂大街,基本上遇到的问题网上都可以搜到。而GP遇到问题只能靠自己判断了,很多时候只能看官方文档,而文档全为英文,对于英文很烂的本人表示真的很无力。。。

gplink的原理:

    greenplum 支持gpfdist协议外部表,gpfdist协议支持自定义transform。

    gplink 使用jdbc连接外部数据源,定义transform,将jdbc数据源的数据转换为text格式导入GP或HAWQ。

    官方提供的有greenplum、sqlserver、hive、oracle数据库的模版,现在需要连接的是mysql数据库,有点麻烦,踩了几个坑,在文章最后面会提到。

所需软件下载地址

gplink下载地址

https://github.com/pivotalguru/gplink

mysql JDBC下载地址

https://dev.mysql.com/downloads/connector/j/

这是官方文档的安装步骤

1.  Download latest version from PivotalGuru.com                                  

2.  Unzip <version>.zip

3.  source gplink_path.sh and add this to your .bashrc file                      

4.  Edit gplink.properties with correct Greenplum or Hawq connection information  

5.  Download 3rd party JDBC drivers and place it in $GPLINK_HOME/jar  

6.  Define source configurations in $GPLINK_HOME/connections/  

7.  Define external table names and columns in $GPLINK_HOME/tables/  

8.  Define SQL statements to execute in the source in $GPLINK_HOME/sql/  

9.  Create the External Table with gpltable

个人翻译的中文(翻译得不好见谅)

1、从pivotalguru.com下载最新版本

2、解压压缩包

3、source gplink_path.sh并添加到 .bashrc文件

4、在gplink.properties中编辑Greenplum或Hawq的连接信息

5、下载第三方JDBC驱动程序并将其放入$GPLINK_HOME/jar

6、在$GPLINK_HOME/connections/修改源数据库配置信息

7、在$GPLINK_HOME/tables/定义外部表名和列

8、在$GPLINK_HOME/sql/定义要在源数据库执行的sql语句

9、用gpltable创建外部表

下面开始安装


    安装之前要先在mysql端(172.16.104.71:3306)给GP开放访问权限,要关闭iptables,或iptables开放mysql端口。

    这里为了方便测试mysql给了最大权限,在实际环境中不能这么做

[root@s121 ~]# mysql -uroot -p123
mysql> grant all on *.* to "root"@"%" identified by '123';
mysql> flush privileges;

1、从pivotalguru.com下载最新版本

[root@mdw ~]# su - gpadmin
[gpadmin@mdw ~]$wget https://codeload.github.com/pivotalguru/gplink/zip/master

2、解压压缩包

[gpadmin@mdw ~]$unzip master

3、source gplink_path.sh并添加到 .bashrc文件

[gpadmin@mdw ~]$source gplink-master/gplink_path.sh
[gpadmin@mdw ~]$vi .bashrc 
source /home/gpadmin/gplink-master/gplink_path.sh

4、在gplink.properties中编辑Greenplum或Hawq的连接信息

[gpadmin@mdw ~]$ vi $GPLINK_HOME/gplink.properties 
connectionUrl=jdbc:postgresql://mdw:5432/gpdb     #gpdb为gp的数据库
classForName=org.postgresql.Driver
readCommitted=true
userName=gpadmin                                  #gp用户名
password=123456                                   #密码,注意后面不能有空格
gplinkHome=/usr/local/gplink
gplinkLog=//usr/local/gplink/log/gplink
gplinkYml=/usr/local/gplink/yml/gplink.yml
gplinkPortLower=24000
gplinkPortUpper=25000

5、下载第三方JDBC驱动程序并将其放入$GPLINK_HOME/jar

[gpadmin@mdw ~]$ wget https://dev.mysql.com/downloads/file/?id=470332
[gpadmin@mdw ~]$ tar xvf mysql-connector-java-5.1.42.tar.gz 
[gpadmin@mdw ~]$ cp mysql-connector-java-5.1.42/mysql-connector-java-5.1.42-bin.jar gplink-master/jar/

 6、在$GPLINK_HOME/connections/修改配置

[gpadmin@mdw ~]$ cp $GPLINK_HOME/connections/oracle.properties $GPLINK_HOME/connections/mysql.properties
[gpadmin@mdw ~]$ vi $GPLINK_HOME/connections/mysql.properties 
connectionUrl=jdbc:mysql://172.16.104.71:3306/test       #test为mysql的数据库
classForName=com.mysql.jdbc.Driver
readCommitted=true
userName=root                                            #mysql用户名
password=123                                             #mysql密码
extraProps=defaultRowPrefetch=2000                       #每次读取的数据量

7、在$GPLINK_HOME/tables/定义外部表名和列

[gpadmin@mdw ~]$ cp $GPLINK_HOME/tables/public.oracle_example.sql $GPLINK_HOME/tables/public.mysql.sql 
[gpadmin@mdw ~]$ vi $GPLINK_HOME/tables/public.mysql.sql 
tableName=public.mysql
columns=first_name text, last_name text

8、在$GPLINK_HOME/sql/定义要在源数据库执行的sql语句

[gpadmin@mdw ~]$ cp $GPLINK_HOME/sql/oracle_example.sql $GPLINK_HOME/sql/mysql_example.sql

 9、用gpltable创建外部表

[gpadmin@mdw ~]$gpltable -s $GPLINK_HOME/connections/mysql.properties -t $GPLINK_HOME/gplink.properties -f $GPLINK_HOME/sql/mysql_example.sql -a $GPLINK_HOME/tables/public.mysql.sql

此时登录GP数据库,发现多了一个mysql表

[gpadmin@mdw ~]$ psql -d gpdatabase
psql (8.2.15)
Type "help" for help.

gpdatabase=# \dx
                 List of relations
 Schema |     Name     | Type  |  Owner  | Storage  
--------+--------------+-------+---------+----------
 public | mysql        | table | gpadmin | external
(1 rows)

测试

[gpadmin@mdw ~]$ gplstart -t $GPLINK_HOME/gplink.properties 
Started all ports needed.
[gpadmin@mdw ~]$ gpldata -s $GPLINK_HOME/connections/mysql.properties -f $GPLINK_HOME/sql/mysql_example.sql
jon|roberts
JON|ROBERTS

OK,该状态说明连接成功。

至于怎么从mysql把数据导入greenplum,本人还未研究,自己慢慢摸索吧。

删除表命令

[gpadmin@mdw ~]$ gpldrop -t $GPLINK_HOME/connections/gplink.properties -n public.mysql

安装过程中踩到的几个坑

1、mysql.properties 中的ClassForName不对,因为没有mysql的模版,是拷贝oracle的模版来用

[gpadmin@mdw ~]$ gpldata -s $GPLINK_HOME/connections/mysql.properties -f $GPLINK_HOME/sql/mysql_example.sql
Exception in thread "main" java.sql.SQLException: mysql.jdbc.driver.MysqlDriver
	at ExternalData.main(ExternalData.java:25)

2、jdbc版本不对,下载了最新版,用不了

[gpadmin@mdw ~]$ gpldata -s $GPLINK_HOME/connections/mysql.properties -f $GPLINK_HOME/sql/mysql_example.sql
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/mysql/jdbc/Driver : Unsupported major.minor version 52.0

3、连接失败,mysql主机的防火墙没关或没开放mysql端口

[gpadmin@mdw ~]$ gpldata -s $GPLINK_HOME/connections/mysql.properties -f $GPLINK_HOME/sql/mysql_example.sql
Exception in thread "main" java.sql.SQLException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any 
	at ExternalData.main(ExternalData.java:25)

4、密码错误,原因是mysql.properties文件中的密码后面有空格

[gpadmin@mdw ~]$ gpldata -s $GPLINK_HOME/connections/mysql.properties -f $GPLINK_HOME/sql/mysql_example.sql
Exception in thread "main" java.sql.SQLException: Access denied for user 'root'@'172.16.104.21' (using password: YES)
	at ExternalData.main(ExternalData.java:25)


推荐阅读:
  1. Hbase连接外部ZK
  2. redis 无法从外部连接

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

greenplum gr

上一篇:AAC ADTS流解析总结

下一篇:web前端入门到实战:Css背景定位

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》