flume采集sqlserver测试

本文档记录了一次使用Flume从SQL Server数据库采集数据时遇到的重复数据问题。通过测试和日志分析,发现问题是由于状态文件名包含特殊字符‘_’导致Flume无法正确读取。解决方案是避免在配置文件中使用特殊字符,并确保递增字段值大于现有值以实现增量采集。
摘要由CSDN通过智能技术生成

一、背景

     由于客户数据库迁移,更改flume配置后,数据采集重复,故测试环境进行验证

二、准备

     sqlserver:由于公司没有环境,选择linux服务器安装docker,然后docker sqlserver

三、测试准备

    3.1 sqlserver 

          通过数据库连接工具连接上去,新建数据库,里面插入4条数据

    3.2 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 =false
agent.sources.sqlSource.is_up_than_field =false
agent.sources.sqlSource.identity_field =id
agent.sources.sqlSource.type = com.fusionskye.flume.dbSource.source.DBSource
agent.sources.sqlSource.url = jdbc:sqlserver://119.91.130.53:1435;databaseName=mcafee
agent.sources.sqlSource.driver_class = com.microsoft.sqlserver.jdbc.SQLServerDriver
agent.sources.sqlSource.database = sqlserver
agent.sources.sqlSource.user =SA
agent.sources.sqlSource.password =Aa-111111
agent.sources.sqlSource.table = NewView
agent.sources.sqlSource.columns.to.select = *
agent.sources.sqlSource.where =
agent.sources.sqlSource.up_columns = count
agent.sources.sqlSource.as_columns = count
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-10-01 14:48:56
agent.sources.sqlSource.end_time =2020-11-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.status.file.path = /opt/accur/flume/virus/
agent.sources.sqlSource.status.file.name = virus_count.status
agent.sources.sqlSource.custom.query = 0
agent.sources.sqlSource.batch.size=1000
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":"172.16.1.58","agent_name":"virus","topicName":"flume1", "hostIP":"172.16.1.58"}

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.58
agent.sinks.k1.port = 5330
agent.sinks.k1.connect.timeout = 0
agent.sinks.k1.request.timeout = 0 

四、测试验证

      4.1 进入kafka/bin目录,输入./kafka-console-consumer.sh --bootstrap-server 172.16.1.58:9092 --topic accurLogic |grep McAfee 查看数据结果

      4.2 进入flume/bin目录,输入./flume-ng agent -n agent -c ../conf/ -f ../conf/mcafee.conf -Dflume.root.logger=INFO,console 启动flume,并且可以查看日志

      结果验证(依据如下步骤,逐步验证):

      第一次验证:启动flume:

      4.1获取了完整的数据

       第二次验证:删除状态文件,重启flume:

       4.1 重新获取完整的数据

       第三次验证:状态文件和flume不处理,直接新增数据库数据:

        4.1 五分钟后获取到了新增数据

       第四次验证:状态文件不处理,直接重启flume:

        4.1 获取了完整的数据

        第五次验证:只删除状态文件:

       未产生影响,隔五分钟后,自动重新生成。

五、核查验证结果

       验证结果未达到预期,怀疑哪里有故障未解决。

      在flume启动日志中发现了端倪:

     日志告诉我们,flume启动时无法读取状态文件,这大概也就是为什么重启会重新读取全量数据的原因。

六、结论

        查了大量的文档,无果。突然看到状态文件名virus_count.status,怀疑是“—”导致。

       经过重复步骤四的操作后,确定的确是“_”的问题;所以得出以下结论:

      6.1 flume 配置文件不能识别“_”, 配置时需要避免各类特殊字符;

      6.2 flume采集数据库,递增数据通过状态文件控制,递增字段值一定要大于现有的值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值