Hadoop2.7實戰v1.0之Flume1.6.0搭建(Http Source-->Memory Chanel --> Hdfs Sink)

hackeruncle發表於2016-05-22

Hadoop2.7實戰v1.0之Flume1.6.0搭建(Http Source-->Memory Chanel --> Hdfs Sink)

1.檢視系統是否已經配置jdk1.7.0

點選(此處)摺疊或開啟

  1. [root@xxx-01 jdk1.7.0_25]# bin/java -version
  2. java version "1.7.0_25"
  3. Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
  4. Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
  5. [root@xxx-01 jdk1.7.0_25]# pwd
  6. /usr/java/jdk1.7.0_25
  7. [root@xxx-01 jdk1.7.0_25]


##假如沒有配置jdk1.7以上的版本,請參考 http://blog.itpub.net/30089851/viewspace-1994585/ 的 "安裝JDK"

2.下載和解壓flume1.6.0

點選(此處)摺疊或開啟

  1. [root@xxx-01 local]# wget http://ftp.cuhk.edu.hk/pub/packages/apache.org/flume/1.6.0/apache-flume-1.6.0-bin.tar.gz
  2. [root@xxx-01 local]# tar zxvf apache-flume-1.6.0-bin.tar.gz
  3. [root@xxx-01 local]# cd apache-flume-1.6.0-bin
  4. [root@xxx-01 apache-flume-1.6.0-bin]# ll
  5. total 140
  6. drwxr-xr-x 2 template games 4096 May 21 17:32 bin
  7. -rw-r--r-- 1 template games 69856 May 9 2015 CHANGELOG
  8. drwxr-xr-x 2 template games 4096 May 21 17:32 conf
  9. -rw-r--r-- 1 template games 6172 May 9 2015 DEVNOTES
  10. drwxr-xr-x 10 template games 4096 May 12 2015 docs
  11. drwxr-xr-x 2 root root 4096 May 21 17:32 lib
  12. -rw-r--r-- 1 template games 25903 May 9 2015 LICENSE
  13. -rw-r--r-- 1 template games 249 May 9 2015 NOTICE
  14. -rw-r--r-- 1 template games 1779 May 9 2015 README
  15. -rw-r--r-- 1 template games 1585 May 9 2015 RELEASE-NOTES
  16. drwxr-xr-x 2 root root 4096 May 21 17:32 tools
  17. [root@xxx-01 apache-flume-1.6.0-bin]#
  18. [root@xxx-01 apache-flume-1.6.0-bin]# cd conf
  19. [root@xxx-01 conf]# ls -l
  20. total 16
  21. -rw-r--r-- 1 template games 1661 May 9 2015 flume-conf.properties.template
  22. -rw-r--r-- 1 template games 1110 May 9 2015 flume-env.ps1.template
  23. -rw-r--r-- 1 template games 1214 May 9 2015 flume-env.sh.template
  24. -rw-r--r-- 1 template games 3107 May 9 2015 log4j.properties
  25. [root@xxx-01 conf]#
  26. [root@xxx-01 conf]# cp flume-env.sh.template flume-env.sh
  27. [root@xxx-01 conf]# cp flume-conf.properties.template flume-conf.properties
  28. [root@xxx-01 conf]#

 3.配置flume-env.sh 和環境變數

點選(此處)摺疊或開啟

  1. [root@xxx-01 conf]# vi flume-env.sh
  2. export JAVA_HOME=/usr/java/jdk1.7.0_25
  3. export HADOOP_HOME=/opt/cloudera/parcels/CDH/lib/hadoop
  4. [root@xxx-01 ~]# vi /etc/profile
  5. export JAVA_HOME="/usr/java/jdk1.7.0_25"
  6. export FLUME_HOME=/usr/local/apache-flume-1.6.0-bin
  7. export FLUME_CONF_DIR=$FLUME_HOME/conf

  8. export PATH=$FLUME_HOME/bin:$JAVA_HOME/bin:$PATH

  9. [root@xxx-01 ~]# source /etc/profile
  10. [root@xxx-01 ~]# echo $FLUME_HOME
  11. /usr/local/apache-flume-1.6.0-bin

4.配置flume-conf.properties

點選(此處)摺疊或開啟

  1. [root@xxx-01 conf]# vi flume-conf.properties
  2. # Name the components on this agent
  3. a1.sources = r1
  4. a1.sinks = k1
  5. a1.channels = c1

  6. # Describe/configure the source
    ###預設http handle的格式是json
  7. a1.sources.r1.type = http
  8. a1.sources.r1.bind = 本機ip
  9. a1.sources.r1.port = 5140

  10. a1.sources.r1.fileHeader = false
  11. #a1.sources.r1.deserializer.outputCharset=UTF-8

  12. a1.sources.r1.interceptors =i1
  13. a1.sources.r1.interceptors.i1.type = timestamp

  14. # Describe the sink
  15. a1.sinks.k1.type = hdfs
  16. a1.sinks.k1.channel = c1
  17. # 可以指定hdfs ha的fs.defaultFS配置資訊,而不是指定其中一臺master的,關鍵是當前flume機器要有hadoop環境(因為要載入hadoop jar包)
  18. #和在flume機器上這三個hadoop-env.sh hdfs-site.xml core-site.xml檔案要與 日誌儲存的hdfs配置一致.
  19. a1.sinks.k1.hdfs.path = hdfs://nameservice1/testwjp/%Y-%m-%d/%H
  20. #a1.sinks.k1.hdfs.path = hdfs://xxx-01:8022/testwjp/%Y-%m-%d/%H
  21. a1.sinks.k1.hdfs.filePrefix = logs
  22. a1.sinks.k1.hdfs.inUsePrefix = .

  23. a1.sinks.k1.hdfs.rollInterval = 0
  24. ### roll 16 m = 16777216 bytes
  25. a1.sinks.k1.hdfs.rollSize = 16777216
  26. a1.sinks.k1.hdfs.rollCount = 0
  27. a1.sinks.k1.hdfs.batchSize = 1000
  28. a1.sinks.k1.hdfs.writeFormat = text

  29. ###A. plain text format 普通文字格式
  30. a1.sinks.k1.hdfs.fileType = DataStream

  31. ###B. compressed plain text to zip format 壓縮格式
  32. #a1.sinks.k1.hdfs.fileType = CompressedStream
  33. #a1.sinks.k1.hdfs.codeC = bzip2

  34. # Use a channel which buffers events in memory
  35. a1.channels.c1.type = memory
  36. a1.channels.c1.keep-alive = 30
  37. a1.channels.c1.capacity = 100000
  38. a1.channels.c1.transactionCapacity = 1000
  39. # Bind the source and sink to the channel
  40. a1.sources.r1.channels = c1
  41. a1.sinks.k1.channel = c1

5.啟動agent
[root@xxx-01 apache-flume-1.6.0-bin]#bin/flume-ng agent -c conf -f conf/http-memory-hdfs.properties -n a1 -Dflume.root.logger=INFO,console


###後臺啟動
nohup bin/flume-ng agent -c conf -f conf/http-memory-hdfs.properties -n a1 -Dflume.root.logger=INFO,console &


6.測試端A
[root@xxx-01 bin]# curl -X POST -d'[{"headers":{"h1":"v1","h2":"v2"},"body":"hello body"}]'  http://10.168.11.13:5140


7.測試端B Fox瀏覽器+HttpRequester工具

URL:http://本機ip:5140
Type:POST
Content Type: application/json
Content:

點選(此處)摺疊或開啟

  1. [{
  2.    "headers" : {
  3.        "timestamp" : "1",
  4.        "host" : "random_host1.example.com"
  5.        },
  6.    "body" : "random_body1"
  7.    },
  8.    {
  9.    "headers" : {
  10.         "timestamp" : "2",
  11.        "host" : "random_host2.example.com"
  12.        },
  13.    "body" : "random_body2"
  14.   }]

 ###單擊"Submit"按鈕,返回狀態 200,標識內容post成功.
 Hadoop2.7實戰v1.0之Flume1.6.0搭建(Http Source-->Memory Chanel --> Hdfs Sink)
 
 
8.驗證資料是否sink到hdfs上
命令列:hadoop fs -ls hdfs://nameservice1/testwjp/
Web:

官方文件:

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30089851/viewspace-2105014/,如需轉載,請註明出處,否則將追究法律責任。

相關文章