flume學習02-flume安裝配置啟動
阿新 • • 發佈:2018-12-31
上一篇部落格簡單介紹了flume的一些基本概念和架構,更詳細的內容可以去官網使用者手冊學習,這篇部落格主要介紹如何安裝配置flume,以及作個簡單示例如何使用
下載flume
- tar -zxvf apache-flume-1.5.2-bin.tar.gz
- cp conf/flume-env.sh.template conf/flume-env.sh
- cp conf/flume-conf.properties.template simple-agent.properties
啟動和停止
- 修改配置檔案simple-agent.properties(這裡需要根據你自己的業務去修改這個檔案,這裡舉個簡單的例子):
# 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'
agent.sources = so1
agent.channels = c1
agent.sinks = s1
# For each one of the sources, the type is defined
agent.sources.so1.type = netcat
agent.sources.so1.bind = localhost
agent.sources.so1.port = 44444
# The channel can be defined as follows.
# agent.sources.seqGenSrc.channels = memoryChannel
# Each sink's type must be defined
agent.sinks.s1.type = logger
#Specify the channel the sink should use
# agent.sinks.loggerSink.channel = memoryChannel
# Each channel's type is defined.
agent.channels.c1.type = memory
agent.channels.c1.capacity = 1000
agent.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
agent.sources.so1.channels = c1
agent.sinks.s1.channel = c1
# Other config values specific to each type of channel(sink or source)
# can be defined as well
# In this case, it specifies the capacity of the memory channel
# agent.channels.memoryChannel.capacity = 100
這就是最簡單的一個配置,收集到的日誌直接在flume的logger中打印出來
啟動
bin/flume-ng agent –conf ./conf/ -f conf/simple-agent.properties -Dflume.root.logger=DEBUG,console -n agent
注意點:
–conf:指定flume-env.sh的目錄
-f:flume定義元件的配置檔案
-n:啟動Agent的名稱,該名稱在元件配置檔案中定義
-Dflume.root.logger:flume自身執行狀態的日誌,根據需要配置停止
直接ctrl+c就好了指令碼啟動暫停
非後臺執行的flume看上去比較怪,所以我們還是寫2個指令碼來實現後臺啟動和停止
start.sh和stop.sh
使用
./start.sh simple-agent.properties agent
引數1:指定啟動的配置檔案
引數2:指定agent的名字./stop.sh 44444
引數1:配置檔案中指定的啟動埠
#!/bin/bash
nohup bin/flume-ng agent --conf ./conf/ -f conf/$1 -Dflume.root.logger=DEBUG,console -n $2 &
#!/bin/bash
kill -9 $(lsof -i:12306 | awk '{print $2}' | tail -n 1)
測試
由於配置中的source是netcat,那麼我們直接telnet
[email protected]:~$ telnet localhost 44444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
dasdasd
OK
我們再看flume console的輸出
2015-02-12 10:39:14,886 (SinkRunner-PollingRunner-DefaultSinkProcessor) [INFO - org.apache.flume.sink.LoggerSink.process(LoggerSink.java:70)] Event: { headers:{} body: 64 61 73 64 61 73 64 0D dasdasd. }
可以看到正常執行了
安裝配置啟動就簡單得介紹到這裡,畢竟我學這個是用來收集日誌的,所以接下去幾篇都會介紹用flume如何去接受log4j的輸出日誌,有可能涉及到日誌的分析處理。