单个flume agent实践上线后宕机过程记录

本文详细介绍了一种单节点Flume部署方案,包括Hadoop准备、Flume环境变量配置、Flume日志收集配置等步骤,并给出了logback.xml的具体配置样例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一 单节点flume部署
1 hadoop准备
在hdfs中创建flume目录,并将flume目录的权限分配给flume用户
hdfs dfs -mkdir flume
hdfs dfs -chown -R flume:flume /flume
2 flume-env.sh
进入${FLUME_HOME}/conf

cp flume-env.sh.template flume-env.sh
vi flume-env.sh,设置JAVA的环境变量
export JAVA_HOME=/usr/java/jdk1.7.0_79

3 flume-conf.properties
下方配置中application和dir由应用系统在logback.xml中配置

agent1.sources=source1  
agent1.channels=channel1  
agent1.sinks=sink1  
  
agent1.sources.source1.type=avro  
agent1.sources.source1.bind=0.0.0.0  
agent1.sources.source1.port=44444  
agent1.sources.source1.channels=channel1  
  
agent1.channels.channel1.type=memory  
agent1.channels.channel1.capacity=10000  
agent1.channels.channel1.transactionCapacity=1000  
agent1.channels.channel1.keep-alive=30  
  
agent1.sinks.sink1.type=hdfs  
agent1.sinks.sink1.channel=channel1  
agent1.sinks.sink1.hdfs.path=hdfs://dashuju174:9000/flume/%{application}/%{dir}/%Y%m%d
agent1.sinks.sink1.hdfs.fileType=DataStream  
agent1.sinks.sink1.hdfs.writeFormat=Text  
agent1.sinks.sink1.hdfs.rollInterval=0  
agent1.sinks.sink1.hdfs.rollSize=10240  
agent1.sinks.sink1.hdfs.rollCount=0  
agent1.sinks.sink1.hdfs.idleTimeout=60

4 logback配置
logback.xml中添加下方日志,专门针对TRACE级别的日志。选择TRACE的原因是因为开发人员对INFO\ERROR\DEBUG比较熟悉,对TRACE应用较为生疏,故我这里要求开发人员统一使用TRACE级别的日志。

<appender name="flume" class="com.gilt.logback.flume.FlumeLogstashV1Appender">
  <!-- 此项是连接flume节点的ip和端口 -->
  <flumeAgents> 192.168.5.174:44444  </flumeAgents>
  <flumeProperties>connect-timeout=4000;request-timeout=8000</flumeProperties>
  <batchSize>100</batchSize>
  <reportingWindow>1000</reportingWindow>
  <!-- 此项配置avro头部信息 -->
  <additionalAvroHeaders>myHeader=dengjun</additionalAvroHeaders>
  <!-- 此项配置当前应用   -->
  <application>bds</application>
  <filter class="ch.qos.logback.classic.filter.LevelFilter"><!-- 只打印错误日志 -->
    <level>TRACE</level>
    <onMatch>ACCEPT</onMatch>
    <onMismatch>DENY</onMismatch>
  </filter>
  <layout class="ch.qos.logback.classic.PatternLayout">
    <pattern>%message%n%ex</pattern>
  </layout>
</appender>

5 环境变量
flume依赖zookeeper,故安装flume之前需要安装zookeeper
tar zxvf apache-flume-1.6.0-bin.tar.gz
ln -s apache-flume-1.6.0 flume
设置flume的环境变量
export FLUME_HOME=/home/hadoop/application/flume
export PATH=PATH:PATH:PATH:FLUME_HOME/bin
二 上线运行宕机记录
按照上述配置后,上线第3天,flume宕机了。我这里把解决过程记录下来,毕竟第一次使用flume。
待续。。。

### 启动 Flume Agent 的具体方法 Flume 是一个分布式、可靠和高可用的日志收集系统,其核心组件之一是 **Agent**。以下是关于如何配置和启动 Flume Agent 的详细说明。 #### 配置 Flume Agent Flume Agent 的配置通常存储在一个 `.conf` 文件中,该文件定义了数据流的源(source)、通道(channel)以及接收器(sink)。以下是一个典型的 Flume 配置文件结构: ```properties # 定义 agent 名称及其组件 agent1.sources = source1 agent1.sinks = sink1 agent1.channels = channel1 # 配置 Source agent1.sources.source1.type = exec agent1.sources.source1.command = tail -F /var/log/system.log # 配置 Sink agent1.sinks.sink1.type = hdfs agent1.sinks.sink1.hdfs.path = hdfs://namenode:8020/user/flume/logs/%Y%m%d agent1.sinks.sink1.hdfs.fileType = DataStream # 配置 Channel agent1.channels.channel1.type = memory agent1.channels.channel1.capacity = 1000 agent1.channels.channel1.transactionCapacity = 100 # 将 Source 和 Sink 绑定到 Channel agent1.sources.source1.channels = channel1 agent1.sinks.sink1.channel = channel1 ``` 此配置文件描述了一个简单的日志采集场景:从本地 `/var/log/system.log` 中读取数据并通过 HDFS 存储下来[^2]。 --- #### 启动 Flume Agent 命令 启动 Flume Agent 使用 `flume-ng` 工具完成。以下是具体的命令格式: ```bash flume-ng agent \ -c /path/to/conf/directory \ -f /path/to/flume/configuration/file.conf \ -n agent_name \ -Dflume.root.logger=LOG_LEVEL,console ``` - `-c`: 指定 Flume 的配置目录路径。 - `-f`: 指向 Flume 配置文件的具体位置。 - `-n`: 指定要启动的 Agent 名称。 - `-Dflume.root.logger`: 设置日志级别(如 DEBUG 或 INFO),并将日志输出到控制台。 例如,假设我们有一个名为 `exec_mem_hdfs.conf` 的配置文件,并希望以调试模式运行名为 `agent1` 的 Agent,则可以执行以下命令: ```bash flume-ng agent \ -c /apps/flume/conf \ -f /apps/flume/conf/exec_mem_hdfs.conf \ -n agent1 \ -Dflume.root.logger=DEBUG,console ``` 这会根据指定的配置文件启动 Flume Agent 并将其绑定到名称为 `agent1` 的实例上。 --- #### 动态管理 Flume Configuration via Zookeeper 如果需要动态更新 Flume 配置而无需重启服务,可以通过 Apache Zookeeper 实现集中化管理。以下是基本流程: 1. 创建 Zookeeper 节点用于存储 Flume 配置。 2. 编写脚本或工具将 Flume 配置文件的内容上传至 Zookeeper 节点。 3. 修改 Flume 启动参数以支持从 Zookeeper 加载配置。 ##### 示例代码:Python 写入 Flume 配置到 Zookeeper 以下 Python 脚本展示了如何将 Flume 配置文件内容写入 Zookeeper 节点: ```python from kazoo.client import KazooClient def write_flume_config_to_zookeeper(zk_hosts, zk_path, config_content): zk = KazooClient(hosts=zk_hosts) zk.start() if not zk.exists(zk_path): zk.create(zk_path, makepath=True) zk.set(zk_path, bytes(config_content, 'utf-8')) zk.stop() if __name__ == "__main__": zookeeper_hosts = "localhost:2181" zookeeper_path = "/config/flume/agent1" flume_config = """ agent1.sources = source1 agent1.sinks = sink1 agent1.channels = channel1 # ... (其余配置省略) """ write_flume_config_to_zookeeper(zookeeper_hosts, zookeeper_path, flume_config) ``` 当配置成功写入 Zookeeper 后,Flume 可以通过监听这些节点的变化来实时加载新的配置[^4]。 --- #### 自动化部署与管理 为了简化大规模集群环境下 Flume Agent 的管理和维护,可以借助 Ansible 等自动化运维工具实现批量部署、升级或卸载操作。Ansible Playbook 提供了一种声明式的语法来定义任务序列,从而减少手动干预的可能性[^1]。 --- ### 总结 以上介绍了两种方式来配置和启动 Flume Agent: 1. 手动编写配置文件并通过命令行启动; 2. 利用 Zookeeper 进行动态配置管理并结合自动化工具提升效率。 无论采用哪种方式,都需要确保配置文件无误且网络连通性正常以便于各模块间通信顺畅。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

warrah

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值