flume采集mysql数据库增量数据说明

  • flume依赖包

1、https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.48.tar.gz

2、flume-ng-sql-source-1.5.3.jar

  • flume配置文件
    agent.sources = sqlSource
    agent.sinks = k1
    agent.channels = c1
    
    agent.sources.sqlSource.start_time =17:00:00
    agent.sources.sqlSource.channels = c1
    agent.sources.sqlSource.cycle_time =5*60*1000
    agent.sources.sqlSource.is_select_table =true
    agent.sources.sqlSource.is_up_than_field =true
    agent.sources.sqlSource.identity_field =id
    
    agent.sources.sqlSource.type = org.keedio.flume.source.SQLSource
    agent.sources.sqlSource.hibernate.connection.url = jdbc:mysql://172.16.1.180:3306/zabbix?useSSL=false
    # Hibernate Database connection properties
    agent.sources.sqlSource.hibernate.connection.user = zabbix
    agent.sources.sqlSource.hibernate.connection.password = zabbix
    agent.sources.sqlSource.hibernate.connection.autocommit = true
    agent.sources.sqlSource.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
    agent.sources.sqlSource.hibernate.connection.driver_class = com.mysql.jdbc.Driver
    agent.sources.sqlSource.status.file.path = /opt/
    agent.sources.sqlSource.status.file.name = sqlSource.status
    # Custom query
    agent.sources.sqlSource.custom.query = select * from abc where id > \'$@$\'
    agent.sources.sqlSource.hibernate.connection.provider_class = org.hibernate.connection.C3P0ConnectionProvider
    
    agent.sources.sqlSource.where =
    agent.sources.sqlSource.up_columns = id
    agent.sources.sqlSource.as_columns = id
    agent.sources.sqlSource.column_type=integer
    agent.sources.sqlSource.time_type=date
    agent.sources.sqlSource.time_type_type=timestamp
    agent.sources.sqlSource.start.from = 0
    agent.sources.sqlSource.begin_time =2020-09-01 14:48:56
    agent.sources.sqlSource.end_time =2020-10-02 14:48:56
    agent.sources.sqlSource.max.rows = 500
    agent.sources.sqlSource.run.query.delay=180000
    agent.sources.sqlSource.run.query.delayTimes=180000
    agent.sources.sqlSource.interceptors=i1
    agent.sources.sqlSource.interceptors.i1.type = static
    agent.sources.sqlSource.interceptors.i1.key=key
    agent.sources.sqlSource.interceptors.i1.value={"vendor":"McAfee","product":"防病毒","agent_ip":"192.2.17.35","agent_name":"mcafee","topicName":"flume1", "hostIP":"191.2.8.2"}
    
    agent.channels.c1.type = memory
    agent.channels.c1.capacity = 100000
    agent.channels.c1.transactionCapacity = 10000
    
    agent.sinks.k1.type = thrift
    agent.sinks.k1.channel=c1
    agent.sinks.k1.hostname = 172.16.1.180
    agent.sinks.k1.port = 5330
    agent.sinks.k1.connect.timeout = 0
    agent.sinks.k1.request.timeout = 0

  • 配置文件注意事项
    1. 状态文件和路径不能出现-或者_,否则启动可能报错
    2. 状态文件路径如果不存在,请新建路径,状态文件可以不新建
    3. sql语句请指定自增字段,否则会重复读取全量数据
  • 测试样例
  • 数据库原始数据:
  • 测试效果:

     

    测试结论:

    当前配置,可以实现数据增量获取。

    当数据新增时,重启flume或者等几分钟,可以获取新增数据。

 

  • 0
    点赞
  • 1
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhcha_xr

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值