当前位置: 首页 > article >正文

6、Flume安装

按照采集通道规划,需在hadoop102,hadoop104两台节点分别部署一个Flume。可参照以下步骤先在hadoop102安装,然后再进行分发。

1. Flume安装部署

1.1 安装地址

(1) Flume官网地址:Welcome to Apache Flume — Apache Flume

(2)文档查看地址:Flume 1.11.0 User Guide — Apache Flume

(3)下载地址:Index of /dist/flume

1.2 安装部署

(1)将apache-flume-1.10.1-bin.tar.gz上传到linux的/opt/software目录下

(2)解压apache-flume-1.10.1-bin.tar.gz到/opt/module/目录下

[shuidi@hadoop102 software]$ tar -zxvf /opt/software/apache-flume-1.10.1-bin.tar.gz -C /opt/module/

 (3)修改apache-flume-1.10.1-bin的名称为flume

[shuidi@hadoop102 module]$ mv /opt/module/apache-flume-1.10.1-bin /opt/module/flume

(4)修改conf目录下的log4j2.xml配置文件,配置日志文件路径

[shuidi@hadoop102 flume]$  vim log4j2.xml



<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

-->
<Configuration status="ERROR">
  <Properties>
    <Property name="LOG_DIR">/opt/module/flume/log</Property>
  </Properties>
  <Appenders>
    <Console name="Console" target="SYSTEM_ERR">
      <PatternLayout pattern="%d (%t) [%p - %l] %m%n" />
    </Console>
    <RollingFile name="LogFile" fileName="${LOG_DIR}/flume.log" filePattern="${LOG_DIR}/archive/flume.log.%d{yyyyMMdd}-%i">
      <PatternLayout pattern="%d{dd MMM yyyy HH:mm:ss,SSS} %-5p [%t] (%C.%M:%L) %equals{%x}{[]}{} - %m%n" />
      <Policies>
        <!-- Roll every night at midnight or when the file reaches 100MB -->
        <SizeBasedTriggeringPolicy size="100 MB"/>
        <CronTriggeringPolicy schedule="0 0 0 * * ?"/>
      </Policies>
      <DefaultRolloverStrategy min="1" max="20">
        <Delete basePath="${LOG_DIR}/archive">
          <!-- Nested conditions: the inner condition is only evaluated on files for which the outer conditions are true. -->
          <IfFileName glob="flume.log.*">
            <!-- Only allow 1 GB of files to accumulate -->
            <IfAccumulatedFileSize exceeds="1 GB"/>
          </IfFileName>
        </Delete>
      </DefaultRolloverStrategy>
    </RollingFile>
  </Appenders>

  <Loggers>
    <Logger name="org.apache.flume.lifecycle" level="info"/>
    <Logger name="org.jboss" level="WARN"/>
    <Logger name="org.apache.avro.ipc.netty.NettyTransceiver" level="WARN"/>
    <Logger name="org.apache.hadoop" level="INFO"/>
<Logger name="org.apache.hadoop.hive" level="ERROR"/>
# 引入控制台输出,方便学习查看日志
    <Root level="INFO">
      <AppenderRef ref="LogFile" />
      <AppenderRef ref="Console" />
    </Root>
  </Loggers>

</Configuration>

1.3 分发Flume

[shuidi@hadoop102 conf]$ xsync /opt/module/flume/

项目经验

(1)堆内存调整

Flume堆内存通常设置为4G或更高,配置方式如下:

修改/opt/module/flume/conf/flume-env.sh文件,配置如下参数(虚拟机环境暂不配置)

export JAVA_OPTS="-Xms4096m -Xmx4096m -Dcom.sun.management.jmxremote"

注:

-Xms表示JVM Heap(堆内存)最小尺寸,初始分配。

-Xmx 表示JVM Heap(堆内存)最大允许的尺寸,按需分配。

2.日志采集Flume

2.1 日志采集Flume配置概述

按照规划,需要采集的用户行为日志文件存放在hadoop102,故需要在该节点配置日志采集Flume。日志采集Flume需要采集日志文件内容,并对日志格式(JSON)进行校验,然后将校验通过的日志发送到Kafka。

此处可选择TaildirSource和KafkaChannel,并配置日志校验拦截器。

选择TailDirSource和KafkaChannel的原因如下:

1)TailDirSource

TailDirSource相比ExecSource、SpoolingDirectorySource的优势。

TailDirSource:断点续传、多目录。Flume1.6以前需要自己自定义Source记录每次读取文件位置,实现断点续传。

ExecSource可以实时搜集数据,但是在Flume不运行或者Shell命令出错的情况下,数据将会丢失。

SpoolingDirectorySource监控目录,支持断点续传。

2)KafkaChannel

采用Kafka Channel,省去了Sink,提高了效率。

日志采集Flume关键配置如下:

2.2 日志采集Flume配置实操

1)创建Flume配置文件

在hadoop102节点的Flume的job目录下创建file_to_kafka.conf。

[shuidi@hadoop102 flume]$ mkdir job
[shuidi@hadoop102 flume]$ vim job/file_to_kafka.conf

2)配置文件内容如下

#定义组件
a1.sources = r1
a1.channels = c1

#配置source
a1.sources.r1.type = TAILDIR
a1.sources.r1.filegroups = f1
a1.sources.r1.filegroups.f1 = /opt/module/applog/log/app.*
a1.sources.r1.positionFile = /opt/module/flume/taildir_position.json

#配置channel
a1.channels.c1.type = org.apache.flume.channel.kafka.KafkaChannel
a1.channels.c1.kafka.bootstrap.servers = hadoop102:9092,hadoop103:9092
a1.channels.c1.kafka.topic = topic_log
a1.channels.c1.parseAsFlumeEvent = false

#组装 
a1.sources.r1.channels = c1

2.3 日志采集Flume测试

1)启动Zookeeper、Kafka集群

2)启动hadoop102的日志采集Flume

[shuidi@hadoop102 flume]$ bin/flume-ng agent -n a1 -c conf/ -f job/file_to_kafka.conf

3)启动一个Kafka的Console-Consumer

[shuidi@hadoop102 kafka]$ bin/kafka-console-consumer.sh --bootstrap-server hadoop102:9092 --topic topic_log

4)生成数据

执行集群日志生成脚本。

[shuidi@hadoop102 ~]$ lg.sh test 100

5)观察Kafka消费者是否能消费到数据

2.4 日志采集Flume启停脚本

1)在hadoop102节点的/home/shuidi/bin目录下创建脚本f1.sh

[shuidi@hadoop102 bin]$ vim f1.sh

在脚本中填写如下内容。

#!/bin/bash

case $1 in
"start"){
    echo " --------启动 hadoop102 采集flume-------"
    ssh hadoop102 "nohup /opt/module/flume/bin/flume-ng agent -n a1 -c /opt/module/flume/conf/ -f /opt/module/flume/job/file_to_kafka.conf >/dev/null 2>&1 &"
};; 
"stop"){
    echo " --------停止 hadoop102 采集flume-------"
    ssh hadoop102 "ps -ef | grep file_to_kafka | grep -v grep |awk  '{print \$2}' | xargs -n1 kill -9 "
};;
esac

2)增加脚本执行权限

[shuidi@hadoop102 bin]$ chmod 777 f1.sh

3)f1启动

[shuidi@hadoop102 bin]$ f1.sh start

4)f1停止

[shuidi@hadoop102 bin]$ f1.sh stop


http://www.kler.cn/news/304211.html

相关文章:

  • 通信工程学习:什么是PC永久连接、SPC软永久连接
  • Open-Sora代码详细解读(2):时空3D VAE
  • 双流join
  • Vmware 傻瓜式安装( Linux 网络操作系统 01)
  • 【python计算机视觉编程——10.OpenCV】
  • python画图|3D surface基础教程
  • GO Server-Sent Events (SSE)
  • Linux 基础命令-系统信息查看
  • 可测试,可维护,可移植:上位机软件分层设计的重要性
  • 【Python机器学习】循环神经网络(RNN)——审察模型内部情况
  • 警惕!尿血背后隐藏的健康危机,你不可不知的五大原因!
  • PHP 线程,进程、并发、并行 的理解
  • 大模型从失败中学习 —— 微调大模型以提升Agent性能
  • 华为云服务器的数据库部署及管理
  • Jwt、Filter、Interceptor
  • Python实现牛顿法 目录
  • JDK命令工具
  • 中学 教资 科目二
  • IOS Siri和快捷指令打开app
  • golang学习笔记14——golang性能问题的处理方法
  • 2-94 基于matlab的最佳维纳滤波器的盲解卷积算法
  • 基于微信小程序的食堂点餐预约管理系统
  • IP纯净度对跨境电商有哪些影响
  • terminator-gnome
  • 在Linux系统中如何创建一个新用户
  • STM32+ESP01连接到机智云
  • 移动应用门户实现的技术方案
  • [数据集][目标检测]岩石种类检测数据集VOC+YOLO格式4766张9类别
  • 【贪心算法】贪心算法
  • Mongodb Error: queryTxt ETIMEOUT xxxx.wwwdz.mongodb.net