flume的安裝配置

1. 下載解壓

$ sudo tar -zxvf apache-flume-1.8.0-bin.tar.gz -C /usr/local/
$ sudo mv apache-flume-1.8.0-bin flume

 

2. 添加環境變量

$ sudo vim ~/.bashrc
export FLUME_HOME=/usr/local/flume
export FLUME_CONF_DIR=$FLUME_HOME/conf
export PATH=$PATH:$FLUME_HOME/bin
$ source ~/.bashrc

 

3. 修改配置文件

cd /usr/local/flume/conf
cp flume-env.sh.template flume-env.sh
sudo vim flume-env.sh

添加Java的環境變量java

export JAVA_HOME=/usr/local/java-8-openjdk-amd64

 

4. flume版本

./flume/bin/flume-ng version

錯誤: 找不到或沒法加載主類 org.apache.flume.tools.GetJavaPropertyapache

若是系統裏安裝了hbase,會出現錯誤: 找不到或沒法加載主類 org.apache.flume.tools.GetJavaProperty。若是沒有安裝hbase,這一步能夠略過。vim

  1. #一、將hbase的hbase.env.sh的這一行配置註釋掉,即在export前加一個#
  2. #export HBASE_CLASSPATH=/home/hadoop/hbase/conf
  3. #二、或者將HBASE_CLASSPATH改成JAVA_CLASSPATH,配置以下
  4. export JAVA_CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

 

5. 測試flume

(1)Avro

        1. 建立agent配置文件bash

sudo vim ./flume/conf/avro.conf
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = avro
a1.sources.r1.channels = c1
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.port = 4141

#注意這個端口名,在後面的教程中會用獲得

# Describe the sink
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

  2. 啓動flume agent a1   啓動日誌窗口oop

/usr/local/flume/bin/flume-ng agent -c . -f /usr/local/flume/conf/avro.conf -n a1 -Dflume.root.logger=INFO,console

  3. 建立指定文件測試

cd /usr/local/flume/conf/
sudo sh -c 'echo "hello world" > /usr/local/flume/log.00'

  4. 打開另外一個窗口打印日誌this

./flume/bin/flume-ng avro-client --conf conf -H localhost -p 4141 -F /usr/local/flume/log.00

查看日誌窗口spa

(2)telnet

  1. 建立agent配置文件日誌

sudo vim ./flume/conf/example.conf
# Name the components on this agent  
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source  
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444
#同上,記住該端口名

# Describe the sink  
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory  
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel  
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

  2. 啓動agent日誌窗口code

/usr/local/flume/bin/flume-ng agent -c . -f /usr/local/flume/conf/example.conf -n a1 -Dflume.root.logger=INFO,console

 3. 打開另外一個窗口

telnet  localhost 44444

輸入一些字符(不能輸入中文)

  4. 日誌窗口顯示

相關文章
相關標籤/搜索