网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

greenplum使用gplink连接外部数据源-创新互联

  作为一个基于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 .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)

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页题目:greenplum使用gplink连接外部数据源-创新互联
转载来源:http://bjjierui.cn/article/ejcos.html

其他资讯