1.拉取Flume鏡像
2.啟動調試
拉取鏡像:
從hub.docker.com中拉取anchorfree/flume鏡像,docker pull anchorfree/flume:latest
通過docker image ps查看
宿主機創建卷路徑:mkdir /data_volume/flume
通過下面命令創建container:
docker run -p 9090:80 --name flume -it --net host -v /data_volume/flume/:/data anchorfree/flume:latest /bin/bash
命令介紹:
-p 宿主機port:對應容器port
--name 設容器名字為flume
-it 設立偽終端,交互模式運行容器
-v 容器的/data_volume/flume/指向容器的/data路徑(默認無便創建)
anchorfree/flume:latest鏡像
/bin/bash 進入容器終端交互
退出容器終端可以按ctrl+P+Q,掛起容器,但是不會直接停止容器。
重新進入容器可以docker exec -it <container name> /bin/bash進入
其他命令可以參考docker命令
由於該鏡像apt-get指定的代理是ubantu的,所以需要修改,不然無法get到東西
查找sources.list,本文件是可以通過修改apt-get源,但是缺乏vim,所以這里我直接通過在/data_volume/flume下創建文件sources.list
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
把以上寫入sources.list,然后進入容器flume后,在容器根目錄下的/data查看sources.list
並把sources.list 復制到/etc/apt/下,替換原來sources.list
shell輸入apt-get update,即可更新apt-get源,可以使用apt-get
啟動調試
首先安裝telnet,直接apt-get install telnet
把以下寫在/data下的example.conf(自己創建文件flume的conf文件)
# example.conf: 一個單節點的 Flume 實例配置 # 配置Agent a1各個組件的名稱 a1.sources = r1 #Agent a1 的source有一個,叫做r1 a1.sinks = k1 #Agent a1 的sink也有一個,叫做k1 a1.channels = c1 #Agent a1 的channel有一個,叫做c1 # 配置Agent a1的source r1的屬性 a1.sources.r1.type = netcat #使用的是NetCat TCP Source,這個的是別名,Flume內置的一些組件都是有別名的,沒有別名填全限定類名 a1.sources.r1.bind = localhost #NetCat TCP Source監聽的hostname,這個是本機 a1.sources.r1.port = 44444 #監聽的端口 # 配置Agent a1的sink k1的屬性 a1.sinks.k1.type = logger # sink使用的是Logger Sink,這個配的也是別名 # 配置Agent a1的channel c1的屬性,channel是用來緩沖Event數據的 a1.channels.c1.type = memory #channel的類型是內存channel,顧名思義這個channel是使用內存來緩沖數據 a1.channels.c1.capacity = 1000 a1.channels.c1.transactionCapacity = 100 # 把source和sink綁定到channel上 a1.sources.r1.channels = c1 #與source r1綁定的channel有一個,叫做c1 a1.sinks.k1.channel = c1 #與sink k1綁定的channel有一個,叫做c1
然后通過find / -name <filename>找到flume-ng
通過下面命令來啟動flume
/opt/flume/bin/flume-ng agent --conf conf --conf-file example.conf --name a1 -Dflume.root.logger=INFO,console
命令解釋參考文檔https://flume.liyifeng.org/#agent
啟動后呈現如此
另開一個宿主機終端,進入flume容器后,telnet localhost 44444,接着輸入hello
回到前一個終端便發現,如下
測試結束。