Apache Flume 安装文档、日志收集
简介:
文档 https://flume.apache.org/FlumeUserGuide.html
hadoop 生态系统中,flume 的职责是收集数据,一般用作收集各种日志数据。
Source -> Channel -> Sink 这是一个基本的工作流程。
Source 定义了数据从哪里来,Channel 是一个数据暂存的位置 ( disk / mem ),Sink 定义将数据流向哪里!
一、flume 安装
shell > yum -y install jdk1..0_111 # java 环境必不可少 shell > java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) -Bit Server VM (build 25.111-b14, mixed mode) shell > cd /usr/local/src
shell > wget http://www.apache.org/dyn/closer.lua/flume/1.7.0/apache-flume-1.7.0-bin.tar.gz shell > tar zxf apache-flume-1.7.-bin.tar.gz -C /usr/local
二、httpd ( 模拟一个日志源 )
shell > yum -y install httpd shell > /etc/init.d/httpd start
三、flume 基本配置
1、修改 flume 环境变量配置文件
shell > cd /usr/local/apache-flume-1.7.-bin
shell > cp conf/flume-env.sh.template conf/flume-env.sh shell > vim conf/flume-env.sh
# 定义 JAVA_HOME
export JAVA_HOME=/usr/java/default
2、修改 flume 配置文件
shell > vim conf/flume-conf.properties
# 定义 sources、channels、sinks
flumeAgent.sources = r_log
flumeAgent.channels = c_memory
flumeAgent.sinks = s_logger # Source
flumeAgent.sources.r_log.type = exec
flumeAgent.sources.r_log.channels = c_memory
flumeAgent.sources.r_log.command = tail -F /var/log/httpd/access_log # Channel
flumeAgent.channels.c_memory.type = memory
flumeAgent.channels.c_memory.capacity =
flumeAgent.channels.c_memory.transactionCapacity = # Sink
flumeAgent.sinks.s_logger.type = logger
flumeAgent.sinks.s_logger.channel = c_memory # 这是一个测试的配置文件,flume 监听 access_log 并输出到 logger # flumeAgent.channels.c_memory.capacity Channel 存储事件的最大数
# flumeAgent.channels.c_memory.transactionCapacity 从 Source 到 Sink 每传输事物中的最大事件数
四、flume 启动
shell > sh bin/flume-ng agent -c conf -f conf/flume-conf.properties -n flumeAgent -Dflume.root.logger=INFO,console # 启动一个 agent,-c 指定配置文件目录,-f 指定配置文件,-n 指定 agent 名称,-D 指定日志级别、输出位置
# 当 access_log 有新记录时,就会有事件输出到终端
五、flume 收集日志写入 hdfs
shell > cd /usr/local/apache-flume-1.7.-bin shell > vim conf/flume-conf.properties
# 定义 sources、channels、sinks
flumeAgent.sources = r_log
flumeAgent.channels = c_file
flumeAgent.sinks = s_hdfs # Source
flumeAgent.sources.r_log.type = taildir
flumeAgent.sources.r_log.channels = c_file
flumeAgent.sources.r_log.filegroups = f1
flumeAgent.sources.r_log.filegroups.f1 = /var/log/httpd/access_log
flumeAgent.sources.r_log.positionFile = /data/flume/taildir_position_log.json
flumeAgent.sources.r_log.skipToEnd = true # Channel
flumeAgent.channels.c_file.type = file
flumeAgent.channels.c_file.checkpointDir = /data/flume/check
flumeAgent.channels.c_file.useDualCheckpoints = true
flumeAgent.channels.c_file.backupCheckpointDir = /data/flume/backup
flumeAgent.channels.c_file.dataDirs = /data/flume/data
flumeAgent.channels.c_file.keep-alive =
flumeAgent.channels.c_file.write-timeout = # Sink
flumeAgent.sinks.s_hdfs.type = hdfs
flumeAgent.sinks.s_hdfs.channel = c_file
flumeAgent.sinks.s_hdfs.hdfs.path = hdfs://master.hadoop/webroot/logs
flumeAgent.sinks.s_hdfs.hdfs.filePrefix = api
flumeAgent.sinks.s_hdfs.hdfs.rollInterval =
flumeAgent.sinks.s_hdfs.hdfs.rollSize =
flumeAgent.sinks.s_hdfs.hdfs.rollCount =
flumeAgent.sinks.s_hdfs.hdfs.batchSize =
flumeAgent.sinks.s_hdfs.hdfs.fileType = DataStream
flumeAgent.sinks.s_hdfs.hdfs.writeFormat = Text
flumeAgent.sinks.s_hdfs.hdfs.threadsPoolSize =
flumeAgent.sinks.s_hdfs.hdfs.round = true
flumeAgent.sinks.s_hdfs.hdfs.roundValue =
flumeAgent.sinks.s_hfds.hdfs.roundUnit = hour
flumeAgent.sinks.s_hdfs.hdfs.useLocalTimeStamp = true
# 注意:上述配置文件中涉及到的所有目录都会自动生成,不需要手动创建 ( 当然也可以手动创建 )
shell > sh bin/flume-ng agent -c conf -f conf/flume-conf.properties -n flumeAgent -Dflume.root.logger=INFO,console
# 启动 Agent
shell > tree /data/flume
/data/flume
├── backup
│ ├── backupComplete
│ ├── checkpoint
│ ├── checkpoint.meta
│ ├── inflightputs
│ └── inflighttakes
├── check
│ ├── checkpoint
│ ├── checkpoint.meta
│ ├── inflightputs
│ ├── inflighttakes
│ └── queueset
├── data
│ ├── log-
│ ├── log-.meta
│ ├── log-
│ └── log-.meta
└── taildir_position_log.json
# 这便是配置中的所需目录及文件
shell > su - hadoop hadoop shell > hdfs dfs -ls /webroot/logs
-rw-r--r-- root supergroup -- : /webroot/logs/api..tmp hadoop shell > hdfs dfs -tail -f /webroot/logs/api..tmp
192.168.1.246 - - [/Apr/::: +] "GET /icons/apache_pb.gif HTTP/1.1" - "http://192.168.1.25/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0"
192.168.1.246 - - [/Apr/::: +] "GET /icons/poweredby.png HTTP/1.1" - "http://192.168.1.25/" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0"
# 可以看到数据正被写入 hdfs ( 注意:是从日志文件头部读取 )
报错管理:
1、hdfs 权限拒绝
-- ::, (SinkRunner-PollingRunner-DefaultSinkProcessor) [WARN - org.apache.flume.sink.hdfs.HDFSEventSink.process(HDFSEventSink.java:)] HDFS IO error
org.apache.hadoop.security.AccessControlException: Permission denied: user=root, access=WRITE, inode="/webroot/logs":hadoop:supergroup:drwxr-xr-x
at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.check(FSPermissionChecker.java:)
at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:)
at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:)
at org.apache.hadoop.hdfs.server.namenode.FSDirectory.checkPermission(FSDirectory.java:)
at org.apache.hadoop.hdfs.server.namenode.FSDirectory.checkPermission(FSDirectory.java:)
at org.apache.hadoop.hdfs.server.namenode.FSDirectory.checkAncestorAccess(FSDirectory.java:)
at org.apache.hadoop.hdfs.server.namenode.FSDirWriteFileOp.resolvePathForStartFile(FSDirWriteFileOp.java:)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.startFileInt(FSNamesystem.java:)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.startFile(FSNamesystem.java:)
at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.create(NameNodeRpcServer.java:)
at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.create(ClientNamenodeProtocolServerSideTranslatorPB.java:)
解决方法:
shell > su - hadoop
hadoop shell > vim /usr/local/hadoop-2.8./etc/hadoop/hdfs-site.xml
<property>
<name>dfs.permissions.enabled</name>
<value>false</value>
</property>
# 暂时关闭了权限验证,还没找到更好的方法 ( 开放 hdfs / 权限,跟关闭权限验证没啥区别 )
Apache Flume 安装文档、日志收集的更多相关文章
- Apache Hive 安装文档
简介: Apache hive 是基于 Hadoop 的一个开源的数据仓库工具,可以将结构化的数据文件映射为一张数据库表, 并提供简单的sql查询功能,将 SQL 语句转换为 MapReduce 任务 ...
- Apache Hadoop 集群安装文档
简介: Apache Hadoop 集群安装文档 软件:jdk-8u111-linux-x64.rpm.hadoop-2.8.0.tar.gz http://www.apache.org/dyn/cl ...
- ELK Stack 5.2.2 安装文档
简介: ELK Stack 安装文档,这次都使用最新版本(5.2.2).RPM 包的方式搭建 ELK Stack. 下载地址: https://artifacts.elastic.co/downloa ...
- airflow2.0.2分布式安装文档
需要安装的组件 组件 功能 Airflow Webserver 查询元数据以监控和执行DAGs的web界面. Airflow Scheduler 它检查元数据数据库中的DAG和任务的状态,在必要时创建 ...
- _00024 尼娜抹微笑伊拉克_云计算ClouderaManager以及CHD5.1.0群集部署安装文档V1.0
笔者博文:妳那伊抹微笑 itdog8 地址链接 : http://www.itdog8.com(个人链接) 博客地址:http://blog.csdn.net/u012185296 博文标题:_000 ...
- HAProxy安装文档
HAProxy安装文档 [toc][TOC] 一.环境说明 系统环境:CentOS Linux release 7.2.1511 (Core) 系统内核:3.10.0-327.el7.x86_64 软 ...
- Oracle 12c RAC 静默安装文档
参考文档: https://docs.oracle.com/en/database/oracle/oracle-database/12.2/cwlin/index.html https://docs. ...
- Oracle 12c RAC 安装文档
参考文档: https://docs.oracle.com/en/database/oracle/oracle-database/12.2/cwlin/index.html https://docs. ...
- Azkaban使用安装文档
Azkaban使用安装文档 Azkaban简介 Azkaban的是什么 Azkaban是由Linkedin公司推出的一个批量工作流任务调度器,用于在一个工作流内以一个特定的顺序运行一组工作和流程.Az ...
随机推荐
- 菜鸟帮你跳过openstack配置过程中的坑[文末新添加福利]
一:前言 对于一个以前做java全栈工程师而言,而且没学过Linux,很少用虚拟机(还是在大学的时候简单的用过),去配置openstack我想我入的坑肯定比有基础的一定要多,躺在每个坑中徘徊思索的时间 ...
- [转载]从B 树、B+ 树、B* 树谈到R 树
从B 树.B+ 树.B* 树谈到R 树 作者:July.weedge.Frankie.编程艺术室出品. 说明:本文从B树开始谈起,然后论述B+树.B*树,最后谈到R 树.其中B树.B+树及B*树部分由 ...
- 常用flash参数设置
<object type="application/x-shockwave-flash" data="vcastr3.swf" width="6 ...
- 第12课:HTML+CSS的基础用法
1. html之head部分的常用标签的使用 <!--指定html是标准的html还是其它的html--> <!DOCTYPE html> <html lang=&quo ...
- sqlite常用语法详细介绍
1.SQL语句的预编译:将语句转为数据流,执行语句前检查语句的语法,但不能知道语句是否能查出结果.此方法有返回值 预编译成功则返回SQLITE_OK----0否则返回SQLITE_ERROR---- ...
- 前端 —— SVG
0. 简介 SVG:可缩放矢量图形: SVG 是代码,通过浏览器的解析而渲染成一种图形: 可缩放矢量图形是基于可扩展标记语言(XML),以描述二维矢量图形的一种图形格式,由万维网联盟( World W ...
- BZOJ2121: 字符串游戏(DP)(字符串删单词,求最多可以删去多少)
2121: 字符串游戏 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 672 Solved: 376[Submit][Status][Discuss ...
- 在css中使用hover来控制其他元素的样式,该两个元素必须是父子元素
.col-3:hover .check-box { display: block; } 在css中使用hover来控制其他元素的样式,该两个元素必须是父子元素!!!!
- Python程序,辅助微信跳一跳游戏介绍
一.思路介绍 1. 通过Python自动手机截屏,并保存到电脑 2. 通过PhotoShop测量要跳的距离 3. 通过Excel计算按压时间 4. 通过CMD命令控制手机按压时间 二.实现方法详解 1 ...
- ZeroClipboard.js兼容各种浏览器复制到剪切板上
http://www.cnblogs.com/huijieoo/articles/5569990.html <script type="text/javascript" sr ...