一、背景
由于客户数据库迁移,更改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采集数据库,递增数据通过状态文件控制,递增字段值一定要大于现有的值。