1. 程式人生 > >linux單節點配置flume1.8

linux單節點配置flume1.8

使用版本:hadoop2.7.3  jdk:1.7  flume:1.5

前提:hadoop已經啟動起來。jdk已經安裝好,並且配置了環境變數,此flume輪詢的資料夾是/itcast/logs資料夾,要提前建立。

下載flume1.5到你的系統中,解壓到你指定的目錄下。接著

1,進入到apache-flume-1.5.0-bin/conf。將flume-env.sh.template改成flume-env.sh。vim flume-env.sh。加入

JAVA_HOME=你的jdk目錄,比如/itcast/jdk1.7.0_80

2,弄個conf檔案,比如下面這個(a4.conf),

#定義agent名, source、channel、sink的名稱
a4.sources = r1
a4.channels = c1
a4.sinks = k1

#具體定義source
a4.sources.r1.type = spooldir
a4.sources.r1.spoolDir = /itcast/logs

#具體定義channel
a4.channels.c1.type = memory
a4.channels.c1.capacity = 10000
a4.channels.c1.transactionCapacity = 100

#定義攔截器,為訊息新增時間戳
a4.sources.r1.interceptors = i1
a4.sources.r1.interceptors.i1.type = org.apache.flume.interceptor.TimestampInterceptor$Builder


#具體定義sink
a4.sinks.k1.type = hdfs
a4.sinks.k1.hdfs.path = hdfs://ns1/flume/%Y%m%d

a4.sinks.k1.hdfs.filePrefix = events-
a4.sinks.k1.hdfs.fileType = DataStream
#不按照條數生成檔案
a4.sinks.k1.hdfs.rollCount = 0
#HDFS上的檔案達到128M時生成一個檔案
a4.sinks.k1.hdfs.rollSize = 134217728
#HDFS上的檔案達到60秒生成一個檔案
a4.sinks.k1.hdfs.rollInterval = 60

#組裝source、channel、sink
a4.sources.r1.channels = c1
a4.sinks.k1.channel = c1

其實還有別的方式,這只是其中一種。然後把這個檔案拷貝到apache-flume-1.5.0-bin/conf下。

然後將hadoop中的core-site.xml和hdfs-site.xml拷貝到apache-flume-1.5.0-bin/conf下。

3、hadoop-2.7.3/share/hadoop/common這個檔案下的hadoop-common-2.7.3.jar拷貝到/apache-flume-1.5.0-bin/lib下
     hadoop-2.7.3/share/hadoop/common/lib下的commons-configuration-1.6.jar拷貝到apache-flume-1.5.0-bin/lib下
     hadoop-2.7.3/share/hadoop/common/lib下的hadoop-auth-2.7.3.jar拷貝到/apache-flume-1.5.0-bin/lib下

     hadoop-2.7.3/share/hadoop/hdfs/hadoop-hdfs-2.7.3.jar拷貝到apache-flume-1.5.0-bin/lib下

如果沒拷貝這三個包,對應的錯誤如下:

然後就可以啟動flume了。命令如下

bin/flume-ng agent -n a4 -c conf -f conf/a4.conf -Dflume.root.logger=INFO,console

說明:這是在flume的根目錄下啟動的,如果在bin目錄下啟動,應該是

./flume-ng agent -n a4 -c ../conf -f ../conf/a4.conf -Dflume.root.logger=INFO,console

對比下就知道那裡需要路徑了。其中

flume-ng:啟動flume
agent:啟動agent
-n a4:-n:agent名稱 名稱是a4
-c conf:-c:conf,讀配置資訊,在conf下面
-f conf/a4.conf:-f:決定source等啥型別 在conf/a4.conf中
-Dflume:-D:指定執行時引數

如果有錯誤如下:

這是版本升級導致的,在apache-flume-1.5.0-bin/conf/core-site.xml中加入:

        <property>
                <name>fs.hdfs.impl</name>
                <value>org.apache.hadoop.hdfs.DistributeFileSystem</value>
                <description>
                        The FileSystem for hdfs:uris.
                </description>
        </property>

備註:如果你們已經啟動起來了,在/itcast/logs/資料夾下放入檔案,就會上傳到hdfs上。