Flume搭建

举报
菜鸟级攻城狮 发表于 2021/01/26 11:49:22 2021/01/26
【摘要】 Flume搭建

Flume搭建

注意:前期步骤,最小化安装,配置yum,安装bash-completion,安装vim,安装net-tools,关闭防火墙,关闭SELINUXhosts表,免密登录。

1.安装java

2.上传并解压flume

[root@win1 soft]# tar -zxvf apache-flume-1.9.0-bin.tar.gz

3.配置flume环境。默认没有flume-env.sh,需要复制

[root@win1 conf]# cd /hadoop/soft/apache-flume-1.9.0-bin/conf/ 进入conf目录

[root@win1 conf]# scp -p flume-env.sh.template  flume-env.sh 复制一份flume-env.sh

4编辑flume-env.sh文件(只编辑export JAVA_HOME段落)。

# 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.

 

# If this file is placed at FLUME_CONF_DIR/flume-env.sh, it will be sourced

# during Flume startup.

# Enviroment variables can be set here.

export JAVA_HOME=/hadoop/soft/jdk1.8.0_161

后面省略...

5、编辑环境变量

[root@win1 conf]# vim /root/.bashrc

JAVA_HOME=/hadoop/soft/jdk1.8.0_161

FLUME_HOME=/hadoop/soft/apache-flume-1.9.0-bin

PATH=$JAVA_HOME/bin:$PATH:$FLUME_HOME/bin

CLASS_PATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar

6.加载环境变量

[root@win1 ~]# source /root/.bashrc

7.确定环境配置是否成功

[root@win1 ~]# flume-ng version

Flume 1.9.0

Source code repository: https://git-wip-us.apache.org/repos/asf/flume.git

Revision: d4fcab4f501d41597bc616921329a4339f73585e

Compiled by fszabo on Mon Dec 17 20:45:25 CET 2018

From source with checksum 35db629a3bda49d23e9b3690c80737f9

 8.配置flumekafka连接

[root@win1 ~]# cd /hadoop/soft/apache-flume-1.9.0-bin/conf/

[root@win1 conf]# cp flume-conf.properties.template  kafka.properties 

默认没有kafka.properties需复制一份kafka.properties

[root@win1 conf]# vi kafka.properties 进入kafka.properties

 

# 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.

# The configuration file needs to define the sources,

# the channels and the sinks.

# Sources, channels and sinks are defined per agent,

# in this case called 'agent' 把原文件该行之后内容删除后,输入以下内容

#配置flume agentsourcechannelsink

a1.sources = r1

a1.channels = c1

a1.sinks = k1

#配置source

a1.sources.r1.type = exec

a1.sources.r1.command = tail -F /tmp/logs/kafka.log

 

#配置channel

a1.channels.c1.type = memory

a1.channels.c1.capacity = 1000

a1.channels.c1.transactionCapacity = 100

 

#配置sink

a1.sinks.k1.channel = c1

a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink

 

#配置KafkaTopic

a1.sinks.k1.kafka.topic = mytest

#配置kafkabroker地址和端口号

a1.sinks.k1.kafka.bootstrap.servers = win1:9092,win2:9092,win3:9092

#配置批量提交的数量

a1.sinks.k1.kafka.flumeBatchSize = 20

a1.sinks.k1.kafka.producer.acks = 1

a1.sinks.k1.kafka.producer.linger.ms = 1

a1.sinks.k1.kafka.producer.compression.type = snappy

#绑定sourcesinkchannel

a1.sources.r1.channels = c1

a1.sinks.k1.channel = c1

9.创建logs目录

[root@win1 ~]# mkdir -p /tmp/logs 创建logs目录

[root@win1 ~]# touch /tmp/logs/kafka.log 创建kafka.log

10.创建脚本

[root@win1 ~]# cd /root

[root@win1 ~]# vim kafkaoutput.sh 创建并编辑kafkaoutput.sh

#!/bin/bash

for((i=0;i<=1000;i++))

do

echo "kafka_test-"+$i >> /tmp/logs/kafka.log

done

11.脚本赋权

[root@win1 ~]# chmod 777 kafkaoutput.sh

12.kafka节点创建topic

[root@win1 ~]# kafka-topics.sh --create --zookeeper win1:2181 --replication-factor 3 --partitions 1 --topic mytest

13.打开console 第一台win1

[root@win1 ~]# kafka-console-consumer.sh --bootstrap-server win1:9092,win2:9092,win3:9092 --from-beginning --topic mytest

注意:/hadoop/soft/apache-flume-1.9.0-bin/conf/kafka.properties里指定的话题必须和打开控制台的话题一致

#配置KafkaTopic

a1.sinks.k1.kafka.topic = mytest

14.启动flume-Dflume.root.logger=INFO,console   -D后面的为参数,这里使用打印到控制台的方式,并动态修改log4j的为info级别第二台win1

[root@win1 ~]# flume-ng agent --conf /hadoop/soft/apache-flume-1.9.0-bin/conf/ --conf-file /hadoop/soft/apache-flume-1.9.0-bin/conf/kafka.properties -name a1 -Dflume.root.logger=INFO,console

运行之后会出现如下信息反馈并卡在那里,在另一个窗口启动步骤15的执行脚本 ↓

15.执行脚本 第三台win1

[root@win1 ~]# sh kafkaoutput.sh

16.到第一台win1查看kafka

kafka_test-+992

kafka_test-+993

kafka_test-+994

kafka_test-+995

kafka_test-+996

kafka_test-+997

kafka_test-+998

kafka_test-+999

kafka_test-+1000

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。