flume + kafka 日志采集

版权声明:本文为博主原创文章,如需转载,请注明转载地址: https://blog.csdn.net/liurui_wuhan/article/details/82985265

将系统产生日志信息通过flume采集,推送至kafka进行消费处理

架构图

服务ipport备注
flume collectors10.200.132.1816333flume collectors
flume agent10.200.132.168 flume采集器(目前使用一个agent)
kafka10.200.132.1819092 2181kafka和zookeeper

一台机器部署一个flume agent,如果需要采集多个服务的日志,在配置文件里面可以配置多个collect,

关于flume内部架构的详细介绍,可以参考博客:https://blog.csdn.net/lsjseu/article/details/51670933

关于kafka的安装,前面我已经安装过了,可以参考博客:https://blog.csdn.net/liurui_wuhan/article/details/82984615

本文主要安装flume和如何实现日志采集

一、安装部署

1、下载安装flume

下载地址:http://flume.apache.org/download.html

目前最新是1.8版本 http://www.apache.org/dyn/closer.lua/flume/1.8.0/apache-flume-1.8.0-bin.tar.gz

[root@log-system opt]# tar -zxvf apache-flume-1.8.0-bin.tar.gz

2、10.200.132.181机器上配置

新建 flume-collecters.properties ,用于将收集到flume agent日志 推送到kafka

[root@log-system apache-flume-1.8.0-bin]#  cd conf

[root@log-system conf]# vim flume-collecters.properties 
#flume collecters
agent.sources = s1Flume
agent.channels = c1
agent.sinks =sinkKafka
 
# For each one of the sources, the type is defined
agent.sources.s1Flume.channels = c1
agent.sources.s1Flume.type = avro

#flume ip

agent.sources.s1Flume.bind = 10.200.132.181

# flume 端口
agent.sources.s1Flume.port = 6333
 
# The channel can be defined as follows.
agent.sources.s1Flume.channels = c1
 
# Each sink's type must be defined
agent.sinks.sinkKafka.type = org.apache.flume.sink.kafka.KafkaSink

# kafka消息队列名称
agent.sinks.sinkKafka.topic = topic-pear

# kafka ip:port
agent.sinks.sinkKafka.brokerList = 10.200.132.181:9092 
agent.sinks.sinkKafka.requiredAcks = 1
agent.sinks.sinkKafka.batchSize = 20
agent.sinks.sinkKafka.channel = c1
#Specify the channel the sink should use
#agent.sinks.loggerSink.channel = memoryChannel
# Each channel's type is defined.
agent.channels.c1.type = memory
 
# Other config values specific to each type of channel(sink or source)
# can be defined as well
# In this case, it specifies the capacity of the memory channel
agent.channels.c1.capacity = 100

启动flume

[root@log-system apache-flume-1.8.0-bin]#  bin/flume-ng agent -c conf -f conf/flume-collecters.properties -n agent -Dflume.root.logger=INFO,console,LOGFILE &

查看6333端口是否已启动

3、10.200.132.168上flume配置

[root@cm-elk-02 conf]# vim flume-test-collect.properties
agent.sources = fileSource
agent.channels = memoryChannel
agent.sinks = collecter1
 
agent.sinkgroups = gCollecters
agent.sinkgroups.gCollecters.sinks = collecter1
 
#sink调度模式 load_balance  failover
agent.sinkgroups.gCollecters.processor.type = failover
#负载均衡模式  轮询  random  round_robin
agent.sinkgroups.gCollecters.processor.selector=round_robin
#失效降级
agent.sinkgroups.gCollecters.processor.backoff=true
#降级时间30秒
agent.sinkgroups.gCollecters.processor.maxTimeOut=30000
 
 
agent.sources.fileSource.type = exec
# 监控的日志文件
agent.sources.fileSource.command = tail -F /opt/test/logs/test.log
#agent.sources.fileSource.charset=utf-8
agent.sources.fileSource.channels = memoryChannel
 
agent.sources.fileSource.restartThrottle = 10000
agent.sources.fileSource.restart = true
agent.sources.fileSource.logStdErr = true
 
# Each sink's type must be defined
agent.sinks.collecter1.channel = memoryChannel
agent.sinks.collecter1.type = avro
# flume 服务ip
agent.sinks.collecter1.hostname = 10.200.132.181
# flume 端口
agent.sinks.collecter1.port = 6333
agent.sinks.collecter1.batch-size = 10
# Each channel's type is defined.
agent.channels.memoryChannel.type = memory
 
# Other config values specific to each type of channel(sink or source)
#The max number of events stored in the channel
agent.channels.memoryChannel.capacity = 100
#The max number of events stored in the channel per transaction
agent.channels.memoryChannel.transactionCapacity = 100
#Timeout in seconds for adding or removing an event
agent.channels.memoryChannel.keep-alive=30

 

创建日志目录(如果没有就创建)

[root@cm-elk-02 conf]# mkdir -p /opt/test/logs/

启动服务

[root@cm-elk-02 apache-flume-1.8.0-bin]# bin/flume-ng agent -c conf -f conf/flume-test-collect.properties -n agent -Dflume.root.logger=INFO,console,LOGFILE

 

部署配置基本完成

 

二、验证

登录10.200.132.181服务器,执行kafka消费消息

[root@log-system ~]# /opt/kafka_2.12-2.0.0/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic-pear --from-beginning

登录10.200.132.168服务器,往日志文件写日志

[root@cm-elk-02 logs]# echo "hello world" >>test.log

写入完成之后,大概等几秒钟,就可以看到kafka消费者消费的队列信息了。

 

自己也可以写一个springboot程序产生日志,修改flume agent 监控的日志目录文件,就可以实时的将日志通过flume推送至kafka

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
FlumeKafka和HBase都是大数据领域常用的组件,它们可以很好地协同工作来实现数据的实时采集、传输和存储。下面是它们的集成配置。 1. 安装Flume Flume是Apache基金会下的分布式、可靠、高可用的海量日志采集、聚合和传输系统。它支持多种数据源和数据目的地,可以将多种数据源的数据采集到Hadoop平台中进行处理和分析。 安装Flume的步骤如下: - 下载Flume并解压缩 - 配置Flume环境变量 - 配置Flume代理 2. 安装Kafka Kafka是由Apache软件基金会开发的一个开源流处理平台,它是一种高吞吐量的分布式发布-订阅消息系统,适用于大规模的数据流处理。 安装Kafka的步骤如下: - 下载Kafka并解压缩 - 配置Kafka环境变量 - 配置Kafka服务端 3. 安装HBase HBase是一个分布式、可扩展、高可用的NoSQL数据库,它是Hadoop生态圈中的一员,可以处理大规模的结构化和半结构化数据。 安装HBase的步骤如下: - 下载HBase并解压缩 - 配置HBase环境变量 - 配置HBase服务端 4. 配置Flume采集数据 Flume支持多种数据源和数据目的地,可以根据不同的需求进行配置。在此我们以采集日志为例,配置Flume采集到的日志数据发送到KafkaFlume的配置文件如下: ```properties # Name the components on this agent agent.sources = r1 agent.sinks = k1 agent.channels = c1 # Describe/configure the source agent.sources.r1.type = exec agent.sources.r1.command = tail -F /data/logs/access.log agent.sources.r1.batchSize = 1000 agent.sources.r1.batchDurationMillis = 2000 # Describe the sink agent.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink agent.sinks.k1.brokerList = localhost:9092 agent.sinks.k1.topic = access_log # Use a channel which buffers events in memory agent.channels.c1.type = memory agent.channels.c1.capacity = 10000 agent.channels.c1.transactionCapacity = 1000 # Bind the source and sink to the channel agent.sources.r1.channels = c1 agent.sinks.k1.channel = c1 ``` 5. 配置Kafka接收数据 Kafka支持多个topic,多个partition,可以根据需求进行配置。在此我们以接收Flume发送的数据为例,创建一个名为access_log的topic,并将接收到的数据存储到HBase中。 Kafka的配置文件如下: ```properties # Broker configuration broker.id=0 listeners=PLAINTEXT://localhost:9092 num.network.threads=3 num.io.threads=8 socket.send.buffer.bytes=102400 socket.receive.buffer.bytes=102400 socket.request.max.bytes=104857600 # Topic configuration num.partitions=1 offsets.topic.replication.factor=1 transaction.state.log.replication.factor=1 transaction.state.log.min.isr=1 # Zookeeper configuration zookeeper.connect=localhost:2181 zookeeper.connection.timeout.ms=6000 # HBase configuration hbase.zookeeper.quorum=localhost hbase.zookeeper.property.clientPort=2181 hbase.cluster.distributed=true hbase.rootdir=hdfs://localhost:9000/hbase ``` 6. 配置HBase存储数据 HBase支持多个表,多个列族,可以根据需求进行配置。在此我们以存储access_log为例,创建一个名为access_log的表,并在其中创建一个名为cf的列族。 HBase的配置文件如下: ```xml <configuration> <property> <name>hbase.rootdir</name> <value>hdfs://localhost:9000/hbase</value> </property> <property> <name>hbase.zookeeper.quorum</name> <value>localhost</value> </property> <property> <name>hbase.zookeeper.property.clientPort</name> <value>2181</value> </property> </configuration> ``` 7. 启动服务 按照以下顺序启动服务: - 启动Zookeeper服务 - 启动Kafka服务 - 启动HBase服务 - 启动Flume服务 启动命令如下: ```bash # 启动Zookeeper服务 bin/zookeeper-server-start.sh config/zookeeper.properties # 启动Kafka服务 bin/kafka-server-start.sh config/server.properties # 启动HBase服务 bin/start-hbase.sh # 启动Flume服务 bin/flume-ng agent -n agent -c conf -f conf/flume.conf -Dflume.root.logger=INFO,console ``` 8. 验证数据 启动服务后,Flume将会采集到access.log的数据并发送到Kafka中,Kafka将会接收到数据并将其存储到HBase中。可以通过HBase命令行或Web界面来查看数据是否已经存储。 HBase命令行: ```bash # 进入HBase shell bin/hbase shell # 创建表 create 'access_log', 'cf' # 查看表 list # 插入数据 put 'access_log', 'row1', 'cf:col1', 'value1' # 查看数据 scan 'access_log' ``` HBase Web界面: 在浏览器中输入http://localhost:16010,可以进入HBase Web界面,可以通过该界面来查看表、列族、数据等信息。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值