前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >databus教程_搭建区观察记录表

databus教程_搭建区观察记录表

作者头像
全栈程序员站长
发布2022-09-28 11:28:45
7180
发布2022-09-28 11:28:45
举报

大家好,又见面了,我是你们的朋友全栈君。

最近公司因需要同步oracle数据到mysql ,调研了Datax 对于大数据量的同步代价有些大。开源的databus 需要对源码做二次开发,才可以使用,前期我们搭建后,用自带的person表做了测试。确认可行后研发更改了源码。

准备工作: 1.配制gradle 和 java 2.ojdbc6-11.2.0.2.0.jar放到如下目录: databus-master/sandbox-repo/com/oracle/ojdbc6/11.2.0.2.0/ 更改defaultEnvironment.gradle文替换链接中https为http. 编译databus : gradle -Dopen_source=true clean | assemble

开始搭建: 一. –更改配置信息:

1. 更改 databus-master/databus2-example/database/person/ 下配制 增加相关建表、视图语句和tableapce名称 每个表包括.tab 和 .view两个文件。 建表时需要在最后一行 txn number 字段. 建视图时候需要 把id 列加上别名 key. 2. databus-master/databus2-example/databus2-example-relay-pkg/conf/sources-person.json 连接oracle时候加上ip 及修改相关同步表的信息。 3. 默认路径在 /root/databus-master

二. –更改client的配置 后续打包后生成build_pkg时使用:

cd databus2-example/databus2-example-client/src/main/sources vim db.properties 更改连接库信息 vim client.properties 更改成Relay的端口 配置同步的表信息

–增加以下文本 以同步两张表为例 databus.client.runtime.relay(1).sources=com.linkedin.events.example.person.PrrangeCourse,com.linkedin.events.example.person.plusManager

三. –更改源码的配制信息

vim databus2-example/databus2-example-client/src/main/java/com/linkedin/databus/client/example/PersonClientMain.java #更改db的配制文件目录 vim databus2-example/databus2-example-client/src/main/java/com/linkedin/databus/client/example/xml/XmlParser.java #更改configure文件目录

四. –更改并创建数据库相关信息

vim db/oracle/bin/createUser.sh 更改system密码及创建用户信息。注意:如果表中已存在表 执行多次时候时候 要注释掉删除用户语句。

vim /root/databus-master/db/oracle/bin/createSchema.sh 创建db的包 过程 触发器 函数等。

五. –编译并生成数据库文件 序列化文件

编译databus : gradle -Dopen_source=true [assemble | clean]

sh db/oracle/bin/createUser.sh user pass instance_name tablespace /datadir #创建用户

cd db/oracle/fwk sh /root/databus-master/db/oracle/bin/createSchema.sh user/pass@orcl /root/databus-master/databus2-example/database/person/

mkdir -p /root/databus-master/myperson-avro/avroOut –保存表的字段描述信息 mkdir -p /root/databus-master/myperson-avro/javaOut –保存源码文件

mkdir -p /root/databus-master/myperson-avro/avroOut –保存表的字段描述信息 mkdir -p /root/databus-master/myperson-avro/javaOut –保存源码文件

sh dbus2-avro-schema-gen.sh -namespace com.linkedin.events.example.person -recordName TplusManager -viewName “sy$t_plus_manager” -avroOutDir /root/databus-master/myperson-avro/avroOut -avroOutVersion 1 -javaOutDir /root/databus-master/myperson-avro/javaOut -userName user -password password -database jdbc:oracle:thin:@10.6.6.1:1521:ORCL #生成序列化文件 注意 配制同步多个表 需要执行多次

六.–更改序列化和生成的源码文件

代码语言:javascript
复制
表中第一行  "meta" : "dbFieldName=sy$t_plus_manager;pk=KEY;",  用pk=KEY替换最后一个段
java文件也是  public static final org.apache.avro.Schema SCHEMA$最后一行同样

#将源码和序列化文件cp到指定目录 cd databus2-example/databus2-example-person/src/main/java/com/linkedin/events/example/person cp /root/databus-master/myperson-avro/javaOut/com/linkedin/events/example/person/* ./

cd databus2-example/databus2-example-relay-pkg/schemas_registry/ cp /root/databus-master/myperson-avro/avroOut/* ./

#将cp过来的avsc文件添加到index文件中 vim index.schemas_registry

cd databus2-example/schemas_registry/ cp /root/databus-master/myperson-avro/avroOut/* ./

#编译databus : gradle -Dopen_source=true clean | assemble

七.创建client和relay目录 解包可运行代码

确保client下包括 client.properties configure.xml db.properties 或是确认这几个文件保存在java文件所指的目录 mkdir client relay cd client tar xvzf build/databus2-example-client-pkg/distributions/databus2-example-client-pkg-2.0.0.tar.gz ./

cd …/relay tar xvzf build/databus2-example-relay-pkg/distributions/databus2-example-relay-pkg-2.0.0.tar.gz ./

八 – 运行relay 和 client

#person 是指conf/sources-person.json 文件 sh relay/bin/start-example-relay.sh person sh client/bin/start-example-client.sh person

九.– 最后遇到的问题

问题:

  1. 更新数据时候 新插入一条记录: client 配置文件中没有指定key id 后加上 alias=“KEY” 参考如下脚本

2.Cannot bind to URL rmi://localhost:1099 ServiceUnavailableException错误 在databus-core/databus-core-container/src/main/java/com/linkedin/databus2/core/container/netty/ServerContainer文件的initializeContainerJmx方法倒第二行加 LocateRegistry.createRegistry(_containerStaticConfig.getJmx().getRmiRegistryPort());

在此文件头引入相关包 import java.rmi.registry.LocateRegistry;

–生成client的表的配置文件脚本如下: [root@test2 tedu]# cat genconfig.py

代码语言:javascript
复制
import sys
HEADTXT="\n <field name="
TAILTXT="/>"
TAB_HEAD =" <source name=\"com.linkedin.events.example.person\" id=\"{}\" table={} db=\"mysql\" logEnable=\"true\"> \n <fields>"
TAB_TAIL = "\n </fields> \n </source>"
##read file content 
""" ### file format ### create table *** ( \"col1\" type, \"col2\" type, ) gnerate two files named table_name.sql and table_name.xml """
def read_file(filename,outputfile,id=101):
xml = open(outputfile+".xml",'a')
sql = open(outputfile+".sql",'a')
strxml = ""
strsql = ""
idflag = False
with open(filename,'r') as f:
for line in  f.readlines():
#print(line)
if " TABLE " in line:  #create table 
strxml = TAB_HEAD.format(id,line[line.find('"'):])
strsql = line.replace('"','')
elif " PRIMARY KEY " in line: #last line of create table
strxml = TAB_TAIL
strsql = ')'
id = id+1
elif "(" in line[0:9]:             #"(" in createtable 
idflag=True
continue
else:                         #process line 
strxml = HEADTXT+(line[:line.rfind('"')+1].strip())
if 'ID' in line and idflag: #primarykey field must add ...
strxml+= " alias=\"KEY\" primaryKey=\"true\" "
idflag=False
if ' DATE' in line:
strxml += ' type="java.util.Date"'
strsql = line.replace(" DATE"," datetime")
strsql = strsql.replace('"','')
elif ' NUMBER' in line:
strxml += ' type="double"'
strsql = line.replace(" NUMBER"," bigint")
strsql = strsql.replace('"','')
else:
strsql = line.replace(" VARCHAR2"," varchar")
strsql = strsql.replace('"','')
strxml +=TAILTXT
xml.write(strxml)    
sql.write(strsql)
xml.close()
sql.close()
if __name__ == '__main__':
read_file(sys.argv[1],sys.argv[1]) 
#for x in sys.argv:
# print(x) 

参考链接:

https://github.com/linkedin/databus

https://blog.csdn.net/jyf19/article/details/104555803/

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/183829.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022年8月31日 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 开始搭建: 一. –更改配置信息:
  • 二. –更改client的配置 后续打包后生成build_pkg时使用:
  • 三. –更改源码的配制信息
  • 四. –更改并创建数据库相关信息
  • 五. –编译并生成数据库文件 序列化文件
  • 六.–更改序列化和生成的源码文件
  • 七.创建client和relay目录 解包可运行代码
  • 八 – 运行relay 和 client
  • 九.– 最后遇到的问题
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档