1、在flume目錄下新建/myconf目錄,並在目錄下新建socket-console.conf 文件!
mkdir myconf
cd myconf
touch socket-console.conf
2、編輯文件vim socket-console.conf,添加以下內容:
# 定義這個agent中各組件的名字
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# 描述和配置source組件:r1
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444
# 描述和配置sink組件:k1
a1.sinks.k1.type = logger
# 描述和配置channel組件,此處使用是內存緩存的方式
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# 描述和配置source channel sink之間的連接關係
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
3、運行命令 bin/flume-ng agent --conf conf/ --name a1 --conf-file myconf/socket-console.conf -Dflume.root.logger==INFO,console
其中-Dflume.root.logger==INFO,console的意思是將日誌打印在控制檯上
4、新建一個終端頁面進入44444端口nc localhost 44444,並輸入測試信息
可以看到在flume服務端上已經打印出了相關的信息!!
PS:flume的啓動命令可以使用以下兩種方式
bin/flume-ng agent --conf conf --conf.file example.conf --name a1 -Dflume.root.logger=INFO,console
bin/flume-ng agent -n $agent_name -c conf -f conf/flume-conf.properties.template