美文网首页
阿里云Linux CentOS安装Flume简易例子

阿里云Linux CentOS安装Flume简易例子

作者: 赤色要塞满了 | 来源:发表于2019-12-05 11:32 被阅读0次

安装Java

有的可能已经装了。详细可参考之前写的这篇阿里云Linux CentOS安装Hadoop详细踩坑,里面有安装Java。或者就直接:

yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel

然后找下Java的位置,把环境变量配一下:

vim ~/.bashrc

添加如下:

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64
export PATH=$PATH:$JAVA_HOME/bin

注意,可能大家的Java所在目录不一样,一定自己找清楚。我是在/etc/alternatives里找到的。

image.png
然后生效下,可以source ~/.bashrc,或者直接退出再登录进来,也能生效。我一般用ctrl+d退出。

下载安装Flume

官网点击下载,把链接copy出来。

image.png
下载、解压。
cd /usr/local
wget http://45.252.224.78/files/411900000E0D329D/mirror.bit.edu.cn/apache/flume/1.9.0/apache-flume-1.9.0-bin.tar.gz
tar -zxvf apache-flume-1.9.0-bin.tar.gz
rm -f apache-flume-1.9.0-bin.tar.gz

继续跟Java一样配置环境变量,再生效下,不赘述。

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64
export FLUME_HOME=/usr/local/apache-flume-1.9.0-bin

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

然后配置Flume:

cd $FLUME_HOME/conf
cp flume-env.sh.template flume-env.sh
vim flume-env.sh

把Java的地址配置好。


image.png

配置运行

继续配置:

cp flume-conf.properties.template flume-conf.properties
vim flume-conf.properties

先试试监控端口的,修改内容如下:

# in this case called 'a1'

a1.sources = r1
a1.channels = c1
a1.sinks = k1

# For each one of the sources, the type is defined
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444

# The channel can be defined as follows.
a1.sources.r1.channels = c1

# Each sink's type must be defined
a1.sinks.k1.type = logger

#Specify the channel the sink should use
a1.sinks.k1.channel = c1

# Each channel's type is defined.
a1.channels.c1.type = memory

# 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
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

好了,可以运行下:

flume-ng agent --conf conf --conf-file conf/flume-conf.properties --name a1 -Dflume.root.logger=INFO,console

一段日志飘过,再开一个终端窗口发送消息hello flume,没有的可以先yum install telnet安装下:

[root@master ~]# telnet localhost 44444
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
hello flume
OK

回去之前的窗口,采集到了!

image.png
除了监控端口,也可以监控文件夹,修改下flume-conf.properties,其它地方不变,只修改这段:
# For each one of the sources, the type is defined
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /root/flumemonitor #记住这里是spoolDir,目录名称自己定义

继续运行,一段日志,最后停在这里:


image.png

那就成功了,再开个终端,去监控的目录写文件:

cd /root/flumemonitor
vim test.log

随便写几句,保存退出,发现这个文件变了。


image.png

其实是被Flume采集了,回到Flume运行的窗口,可以看到刚才编辑的内容:


image.png

Ok,先这么用吧。

相关文章

网友评论

      本文标题:阿里云Linux CentOS安装Flume简易例子

      本文链接:https://www.haomeiwen.com/subject/yakdgctx.html