1. 程式人生 > >3、flume資料匯入到Hdfs中

3、flume資料匯入到Hdfs中



[[email protected] apache-flume-1.5.2-bin]# vim conf/agent2.conf


agent2.sources=source1
agent2.channels=channel1
agent2.sinks=sink1


agent2.sources.source1.type=avro
agent2.sources.source1.bind=0.0.0.0
agent2.sources.source1.port=44444
agent2.sources.source1.channels=channel1


agent2.sources.source1.interceptors = i1 i2
agent2.sources.source1.interceptors.i1.type = org.apache.flume.interceptor.HostInterceptor$Builder
agent2.sources.source1.interceptors.i1.preserveExisting = true
agent2.sources.source1.interceptors.i1.useIP = true
agent2.sources.source1.interceptors.i2.type = org.apache.flume.interceptor.TimestampInterceptor$Builder


agent2.channels.channel1.type=memory
agent2.channels.channel1.capacity=10000
agent2.channels.channel1.transactionCapacity=1000
agent2.channels.channel1.keep-alive=30


agent2.sinks.sink1.type=hdfs
agent2.sinks.sink1.channel=channel1
agent2.sinks.sink1.hdfs.path=hdfs://192.168.1.200:9000/flume/events/%{host}/%y-%m-%d
agent2.sinks.sink1.hdfs.fileType=DataStream
agent2.sinks.sink1.hdfs.writeFormat=Text
agent2.sinks.sink1.hdfs.rollInterval=0
agent2.sinks.sink1.hdfs.rollSize=10000
agent2.sinks.sink1.hdfs.rollCount=0
agent2.sinks.sink1.hdfs.idleTimeout=5


啟動44444埠:
資料匯入到HDFS中這個埠要一直啟動:

[[email protected] apache-flume-1.5.2-bin]# bin/flume-ng agent --conf ./conf/ -Dflume.monitoring.type=http -Dflumetoring.port=34343 -n agent2 -f conf/agent2.conf &


log4j.properties:
#log4j.appender.flume.Port = 41414
log4j.appender.flume.Port = 44444



HDFS上的目錄/flume/events:
[[email protected] hadoop]# hdfs dfs -ls -R /flume
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hbase-0.99.2/lib/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
drwxr-xr-x   - root supergroup          0 2015-06-21 12:50 /flume/events

[[email protected] hadoop]#



執行程式碼:
package flume;

import java.text.SimpleDateFormat;
import org.apache.log4j.Logger;

public class LogProducer {
public static void main(String[] args) {
Logger log=Logger.getLogger(LogProducer.class);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
while (true) {
log.info("日誌格式:"+sdf.format(System.currentTimeMillis()));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}




檢視HDFS裡的資料:


[[email protected] hadoop]# hdfs dfs -ls -R /flume/events
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hbase-0.99.2/lib/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
drwxr-xr-x   - root supergroup          0 2015-06-21 12:55 /flume/events/192.168.1.200
drwxr-xr-x   - root supergroup          0 2015-06-21 12:55 /flume/events/192.168.1.200/15-06-21
-rw-r--r--   1 root supergroup          0 2015-06-21 12:55 /flume/events/192.168.1.200/15-06-21/FlumeData.1434862524993.tmp

[[email protected] hadoop]#



[email protected] hadoop]# hdfs dfs -ls -R /flume/events/192.168.1.200/15-06-21
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hbase-0.99.2/lib/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
-rw-r--r--   1 root supergroup       2940 2015-06-21 12:56 /flume/events/192.168.1.200/15-06-21/FlumeData.1434862524993
[[email protected] hadoop]#


[[email protected] hadoop]# hdfs dfs -ls -R /flume/events
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hbase-0.99.2/lib/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
drwxr-xr-x   - root supergroup          0 2015-06-21 12:55 /flume/events/192.168.1.200
drwxr-xr-x   - root supergroup          0 2015-06-21 12:56 /flume/events/192.168.1.200/15-06-21
-rw-r--r--   1 root supergroup       2940 2015-06-21 12:56 /flume/events/192.168.1.200/15-06-21/FlumeData.1434862524993

[[email protected] hadoop]# hdfs dfs -text /flume/events/192.168.1.200/15-06-21/FlumeData.1434862524993
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hbase-0.99.2/lib/slf4j-log4j12-1.7.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
日誌格式:2015-06-21 12:52:12
日誌格式:2015-06-21 12:52:13
日誌格式:2015-06-21 12:52:14
日誌格式:2015-06-21 12:52:15
日誌格式:2015-06-21 12:52:16
日誌格式:2015-06-21 12:52:17
日誌格式:2015-06-21 12:52:18
日誌格式:2015-06-21 12:52:19






[[email protected] hadoop]#

相關推薦

3flume資料匯入Hdfs

[[email protected] apache-flume-1.5.2-bin]# vim conf/agent2.conf agent2.sources=source1 agent2.channels=channel1 agent2.sinks=sink1

hbase資料匯入hdfs之(使用MapReduce程式設計統計hbase庫的mingxing表男女數量)

資料 zhangfenglun,M,20,13522334455,[email protected],23521472 chenfei,M,20,13684634455,[email protected],84545472 liyuchen,M,20,1352233425

flume將kafkatopic資料匯入hive

一、首先更加資料的表結構在hive中進行表的建立。          create table AREA1(unid string,area_punid string,area_no string,area_name s

使用sqoop將資料hdfs匯入mysql時,卡在INFO mapreduce.Job: map 100% reduce 0%的解決辦法

最近在將hdfs中已經處理好的資料匯入到mysql的時候遇到這麼一個現象,當任務執行到 INFO mapreduce.Job: map 100% reduce 0% mapreduce任務卡在map100% ,任何reduce不繼續執行。 總結了以下解決辦法: 一,如果沒

MapReduce將HDFS文字資料匯入HBase

HBase本身提供了很多種資料匯入的方式,通常有兩種常用方式: 使用HBase提供的TableOutputFormat,原理是通過一個Mapreduce作業將資料匯入HBase 另一種方式就是使用HBase原生Client API 本文就是示範如何通過M

3Flume

.com mage 配置 gen 發送 chan info nbsp 核心 1、概述   Flume:收集、聚集,移動大量日誌數據到指定位置 2、核心組件   基本單位:agent   source:收集   channel:聚集   sink:發送

3基本資料型別&運算

1、整型 整數型別: 無符號與有符號型別: 有符號型別:int、int8、int16、int32、int64 無符號型別:uint、uint8、uint16、uint32、uint64 基於架構的型別:int、uint、uintptr(視其作業系統而定,比如64位作業系統,int則對應i

利用sqoop將hive資料匯入Oracle(踩的坑)

教程很多,這裡只說踩過的坑 1.下載sqoop時,還得下一個bin的包,拿到sqoop-1.4.6.jar 的包,放到hadoop的lib目錄下 2.匯入oracle,執行程式碼時,使用者名稱和表名必須大寫!且資料庫建表時表名必須大寫!  示例程式碼: sqoop expo

mysql匯入資料load data infile用法(將txt檔案資料匯入)

我們常常匯入資料!mysql有一個高效匯入方法,那就是load data infile 下面來看案例說明   基本語法: load data  [low_priority] [local] infile 'file_name txt' [replace | ignor

資料匯入終章:如何將HBase的資料匯入HDFS

我們的最終目標是將資料匯入Hadoop,在之前的章節中,我們介紹瞭如何將傳統關係資料庫的資料匯入Hadoop,本節涉及到了HBase。HBase是一種實時分散式資料儲存系統,通常位於與Hadoop叢集相同的硬體上,或者與Hadoop叢集緊密相連,能夠直接在MapReduce中使用HBase資料,或將

使用sqoop將mysql 資料匯入hdfs時各種報錯

資訊 18/06/29 10:45:08 ERROR sqoop.Sqoop: Got exception running Sqoop: java.lang.RuntimeException: java.lang.RuntimeException: java.sql.SQLExcepti

mysql資料匯入mongodb

# 把mysql資料庫中的資料匯入mongodb中 import pymysql import pymongo # 建立mysql的資料庫連線 con = pymysql.connect(host='localhost', port=3306, user='root', password='12345

從零開始的鐳射通訊(第1章 協議棧)——3提取資料

從零開始的鐳射通訊(第1章 協議棧)——3、提取資料包 github 簡介 函式說明 github https://github.com/HaHaHaHaHaGe/mynetstack 簡介 資料包的提取其實原理並不複雜,就像拼

Sql2012如何將遠端伺服器資料庫及表表結構資料匯入本地資料庫

1、第一步,在本地資料庫中建一個與伺服器同名的資料庫        2、第二步,右鍵源資料庫,任務》匯出資料,彈出匯入匯出提示框,點下一步繼續        3、遠端資料庫操作,確認伺服器名稱(伺服器地址)、身份驗證(輸入使用者名稱、密碼)、選擇需要匯出的源資料庫,點下一步繼續       4、本地目標伺服器

solr 資料匯入過程unable to read:dataimport.properties問題的解決

win7環境下,solr7.5.0版本,Jetty伺服器,SQL server資料庫,已將solr-dataimporthandler-7.5.0.jar、solr-dataimporthandler-extras-7.5.0.jar、sqljdbc42.jar相關驅動放入.

3資料結構】樹形結構之二叉查詢樹

一、樹的介紹 1. 樹的定義     樹是一種資料結構,它是由n(n>=1)個有限節點組成一個具有層次關係的集合。   把它叫做“樹”是因為它看起來像一棵倒掛的樹,也就是說它是根朝上,而葉朝下的。它具有以下的特點:   (1) 每個節點有零個或多個子節點;

oracle通過load data 將資料匯入通過儲存過程進行批量處理

說明:雖然沒圖,但文字表述很清楚,自己做過的專案留著備用(這只是初版,比較繁瑣,但很明確) 準備工作做完之後,後期可直接使用。如後期excel資料有變更,只需改動對應的部分即可,不涉及改動的可直接使用。 實際操作步驟 依照excel資料模版格式準備好建表語句,將中間過渡

3基本資料型別&運算

1、整型 整數型別: 無符號與有符號型別: 有符號型別:int、int8、int16、int32、int64 無符號型別:uint、uint8、uint16、uint32、uint64 基於架構的型別:int、uint、uintptr(視其作業系統而定,比如64

利用sqoop將hive資料匯入Oracle

首先: 如oracle則執行sqoop list-databases --connect jdbc:oracle:thin:@//192.168.27.235:1521/ORCL --username DATACENTER -P 來測試是否能正確連線資料庫  如mysql則執行sq

在hadoop 裡安裝 sqoop 並把mysql資料匯入hdfs

hadoop 2.6.0 sqoop:sqoop-1.4.6.bin__hadoop-2.0.4-alpha.tar.gz 然後把sqoop 解壓。這裡解壓發生的問題是, tar: /home/luis:歸檔中找不到 tar: 由於前次錯誤,將以上次的錯誤狀態退出 ta