阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Flume对Nginx群集日志收集方案

454次阅读
没有评论

共计 7995 个字符,预计需要花费 20 分钟才能阅读完成。

Flume 是一个分布式、可靠、和高可用的海量日志聚合的系统,支持在系统中定制各类数据发送方,用于收集数据;同时,Flume 提供对数据进行简单处理,并写到各种数据接受方(可定制)的能力。

flume 的基本概念
如下图

Flume 对 Nginx 群集日志收集方案

每个 agent 都具有三个元素,source、channel、sink。
source:数据流的源。产生 event。
channel:可以理解成数据流的管道。传递 event
sink :  数据流的终点。消耗 event
注:source 可以上一节点的 sink,sink 可以指定为下一节点的 source。比较常见的场景如下图

Flume 对 Nginx 群集日志收集方案

为以收集日志,并做实时的集中存储,元素相应类型如下
1.source:client 端使用 exec 类型,通过 tail –F 产生 event。server 端使用 avro 类型,用于接收 client 端发出的 event
2.channel:使用 file 类型。(测试期使用了 mem 类似)
3. sink: client 端使用 avro 类型,传递给 server 端。server 端使用 file_roll 类型,指定相应目录储存日志。最终方案会使用 hdfs

Flume 对 Nginx 群集日志收集方案

flume 具体配置如下:
1、将 flume 解压到 /usr/local/flume 下
2、agent 端配置

flume 允许对环境资源使用做设置,需要修改配置,/PREFIX/conf/flume-env.sh  可以通过实际情况进行调整
JAVA_OPTS=”-Xms100m -Xmx200m -Dcom.sun.management.jmxremote”
# 此处 PREFIX 代表 /usr/local/flume

配置(/PREFIX/conf/flume-client.properties)
# Name the components on this agent
a1.sources = r1
a1.channels = c1
a1.sinks = k1

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -n 0 -F /space/nginxlogs/access.web.log
a1.sources.r1.channels = c1

 

# Describe/configure the channels (后面有 memory channel 配置方案)
a1.channels.c1.type = file
a1.channels.c1.keep-alive = 10
a1.channels.c1.write-timeout = 10
a1.channels.c1.checkpointDir = /space/guang_mobileapi_flume/checkpoint
a1.channels.c1.useDualCheckpoints = true
a1.channels.c1.backupCheckpointDir =  /space/guang_mobileapi_flume/backupcheckpoint
a1.channels.c1.dataDirs = /space/guang_mobileapi_flume/data

# Describe/configure the sink
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = 192.168.10.35
a1.sinks.k1.port = 44444
a1.sinks.k1.channel = c1

(# Describe/configure the channels(次方案可以替换前面的 file channel 配置方案)
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

server 配置:

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = avro
a1.sources.r1.channels = c1
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.port = 44444

# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = /logs/web/nginx/%Y%m%d
a1.sinks.k1.hdfs.rollInterval = 3600
a1.sinks.k1.hdfs.fileType = DataStream
a1.sinks.k1.hdfs.rollSize = 0
a1.sinks.k1.hdfs.rollCount = 0
a1.sinks.k1.hdfs.useLocalTimeStamp = true
a1.sinks.k1.hdfs.filePrefix = access.guang.j.cn
a1.sinks.k1.hdfs.inUseSuffix = .tmp
a1.sinks.k1.hdfs.idleTimeout = 300

# Use a channel which buffers events in memory
a1.channels.c1.type = file
a1.channels.c1.write-timeout = 10
a1.channels.c1.keep-alive = 10
a1.channels.c1.checkpointDir = /space/flume/checkpoint
a1.channels.c1.useDualCheckpoints = true
a1.channels.c1.backupCheckpointDir =  /space/flume/backupcheckpoint
a1.channels.c1.dataDirs = /space/flume/data

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

(
# Describe the sink(前面面有 hdfs 方式)
a1.sinks.k1.type = file_roll
a1.sinks.k1.sink.directory = /tmp/test
a1.sinks.k1.sink.rollInterval = 3600

# Use a channel which buffers events in memory(前面有 file channel 配置方案)
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
)

 

以上配置 1 小时自动释放一次。可理解成每小时截断一次。因为 Hadoop 目录使用日志变量,在某文件空闲 5 分钟后自己释放。

启动(client 和 server 端只有配置文件不同)
cd /PREFIX
./flume-ng agent -n a1 -c ../conf -f ../conf/flume-XXXXX.properties    2>/dev/null  &

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

相关阅读

CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm

使用 Nginx 搭建 WEB 服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm

搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm

CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm
 

另附启停脚本

#!/bin/bash

PREFIX=”/usr/local/flume”
AGENT=”a1″
start(){
echo starting
ps aux |grep -v grep|grep $PREFIX -q
if [$? -eq 0];then
echo flume is already running
exit 1
fi
cd $PREFIX
bin/flume-ng agent -n $AGENT -c conf -f conf/flume-XXXXX.properties 2>/dev/null &
}
stop(){
ps aux |grep -v grep|grep $PREFIX -q
if [$? -ne 0];then
echo flume is not running
else
ps aux |grep -v grep|grep $PREFIX|awk ‘{print $2}’|xargs kill -15
sleep 3
ps aux |grep -v grep|grep $PREFIX -q
[$? -eq 0] && ps aux |grep flume|grep -v grep|awk ‘{print $2}’|xargs kill -9
fi
}
status(){
ps aux |grep -v grep|grep $PREFIX -q
if [$? -eq 0];then
echo flume is running
else
echo flume is not running
fi
}

case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 1
start
;;
status)
status
;;
*)
echo “Useage : $0 [start|stop|restat|status]”
;;
esac

如果有不同的 agent 并且 server 是一个 而且收集的日志不同,那么上述配置只需要修改几个地方就 OK 了

1、修改 agent 和 server 的端口
2、server 端配置文件要换一个新的 而且中的 a1 c1 r1 k1 换成其他标示如:a2 c2 r2 k2 以及 a1.sinks.k1.hdfs.path a1.channels.c1.checkpointDir a1.channels.c1.backupCheckpointDir a1.channels.c1.dataDirs 的路径

Flume 是一个分布式、可靠、和高可用的海量日志聚合的系统,支持在系统中定制各类数据发送方,用于收集数据;同时,Flume 提供对数据进行简单处理,并写到各种数据接受方(可定制)的能力。

flume 的基本概念
如下图

Flume 对 Nginx 群集日志收集方案

每个 agent 都具有三个元素,source、channel、sink。
source:数据流的源。产生 event。
channel:可以理解成数据流的管道。传递 event
sink :  数据流的终点。消耗 event
注:source 可以上一节点的 sink,sink 可以指定为下一节点的 source。比较常见的场景如下图

Flume 对 Nginx 群集日志收集方案

为以收集日志,并做实时的集中存储,元素相应类型如下
1.source:client 端使用 exec 类型,通过 tail –F 产生 event。server 端使用 avro 类型,用于接收 client 端发出的 event
2.channel:使用 file 类型。(测试期使用了 mem 类似)
3. sink: client 端使用 avro 类型,传递给 server 端。server 端使用 file_roll 类型,指定相应目录储存日志。最终方案会使用 hdfs

Flume 对 Nginx 群集日志收集方案

flume 具体配置如下:
1、将 flume 解压到 /usr/local/flume 下
2、agent 端配置

flume 允许对环境资源使用做设置,需要修改配置,/PREFIX/conf/flume-env.sh  可以通过实际情况进行调整
JAVA_OPTS=”-Xms100m -Xmx200m -Dcom.sun.management.jmxremote”
# 此处 PREFIX 代表 /usr/local/flume

配置(/PREFIX/conf/flume-client.properties)
# Name the components on this agent
a1.sources = r1
a1.channels = c1
a1.sinks = k1

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -n 0 -F /space/nginxlogs/access.web.log
a1.sources.r1.channels = c1

 

# Describe/configure the channels (后面有 memory channel 配置方案)
a1.channels.c1.type = file
a1.channels.c1.keep-alive = 10
a1.channels.c1.write-timeout = 10
a1.channels.c1.checkpointDir = /space/guang_mobileapi_flume/checkpoint
a1.channels.c1.useDualCheckpoints = true
a1.channels.c1.backupCheckpointDir =  /space/guang_mobileapi_flume/backupcheckpoint
a1.channels.c1.dataDirs = /space/guang_mobileapi_flume/data

# Describe/configure the sink
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = 192.168.10.35
a1.sinks.k1.port = 44444
a1.sinks.k1.channel = c1

(# Describe/configure the channels(次方案可以替换前面的 file channel 配置方案)
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

server 配置:

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = avro
a1.sources.r1.channels = c1
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.port = 44444

# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = /logs/web/nginx/%Y%m%d
a1.sinks.k1.hdfs.rollInterval = 3600
a1.sinks.k1.hdfs.fileType = DataStream
a1.sinks.k1.hdfs.rollSize = 0
a1.sinks.k1.hdfs.rollCount = 0
a1.sinks.k1.hdfs.useLocalTimeStamp = true
a1.sinks.k1.hdfs.filePrefix = access.guang.j.cn
a1.sinks.k1.hdfs.inUseSuffix = .tmp
a1.sinks.k1.hdfs.idleTimeout = 300

# Use a channel which buffers events in memory
a1.channels.c1.type = file
a1.channels.c1.write-timeout = 10
a1.channels.c1.keep-alive = 10
a1.channels.c1.checkpointDir = /space/flume/checkpoint
a1.channels.c1.useDualCheckpoints = true
a1.channels.c1.backupCheckpointDir =  /space/flume/backupcheckpoint
a1.channels.c1.dataDirs = /space/flume/data

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

(
# Describe the sink(前面面有 hdfs 方式)
a1.sinks.k1.type = file_roll
a1.sinks.k1.sink.directory = /tmp/test
a1.sinks.k1.sink.rollInterval = 3600

# Use a channel which buffers events in memory(前面有 file channel 配置方案)
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
)

 

以上配置 1 小时自动释放一次。可理解成每小时截断一次。因为 Hadoop 目录使用日志变量,在某文件空闲 5 分钟后自己释放。

启动(client 和 server 端只有配置文件不同)
cd /PREFIX
./flume-ng agent -n a1 -c ../conf -f ../conf/flume-XXXXX.properties    2>/dev/null  &

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

相关阅读

CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm

使用 Nginx 搭建 WEB 服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm

搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm

CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm
 

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计7995字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中

星哥玩云

星哥玩云
星哥玩云
分享互联网知识
用户数
4
文章数
19351
评论数
4
阅读量
7977905
文章搜索
热门文章
星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛NAS-6:抖音视频同步工具,视频下载自动下载保存

星哥带你玩飞牛 NAS-6:抖音视频同步工具,视频下载自动下载保存 前言 各位玩 NAS 的朋友好,我是星哥!...
星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛NAS-3:安装飞牛NAS后的很有必要的操作

星哥带你玩飞牛 NAS-3:安装飞牛 NAS 后的很有必要的操作 前言 如果你已经有了飞牛 NAS 系统,之前...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见zabbix!轻量级自建服务器监控神器在Linux 的完整部署指南

再见 zabbix!轻量级自建服务器监控神器在 Linux 的完整部署指南 在日常运维中,服务器监控是绕不开的...
飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛NAS中安装Navidrome音乐文件中文标签乱码问题解决、安装FntermX终端

飞牛 NAS 中安装 Navidrome 音乐文件中文标签乱码问题解决、安装 FntermX 终端 问题背景 ...
阿里云CDN
阿里云CDN-提高用户访问的响应速度和成功率
随机文章
星哥带你玩飞牛NAS硬件02:某鱼6张左右就可拿下5盘位的飞牛圣体NAS

星哥带你玩飞牛NAS硬件02:某鱼6张左右就可拿下5盘位的飞牛圣体NAS

星哥带你玩飞牛 NAS 硬件 02:某鱼 6 张左右就可拿下 5 盘位的飞牛圣体 NAS 前言 大家好,我是星...
星哥带你玩飞牛NAS-16:飞牛云NAS换桌面,fndesk图标管理神器上线!

星哥带你玩飞牛NAS-16:飞牛云NAS换桌面,fndesk图标管理神器上线!

  星哥带你玩飞牛 NAS-16:飞牛云 NAS 换桌面,fndesk 图标管理神器上线! 引言 哈...
我把用了20年的360安全卫士卸载了

我把用了20年的360安全卫士卸载了

我把用了 20 年的 360 安全卫士卸载了 是的,正如标题你看到的。 原因 偷摸安装自家的软件 莫名其妙安装...
2025年11月28日-Cloudflare史诗级事故:一次配置失误,引爆全球宕机

2025年11月28日-Cloudflare史诗级事故:一次配置失误,引爆全球宕机

2025 年 11 月 28 日 -Cloudflare 史诗级事故: 一次配置失误,引爆全球宕机 前言 继今...
【开源神器】微信公众号内容单篇、批量下载软件

【开源神器】微信公众号内容单篇、批量下载软件

【开源神器】微信公众号内容单篇、批量下载软件 大家好,我是星哥,很多人都希望能高效地保存微信公众号的文章,用于...

免费图片视频管理工具让灵感库告别混乱

一言一句话
-「
手气不错
Prometheus:监控系统的部署与指标收集

Prometheus:监控系统的部署与指标收集

Prometheus:监控系统的部署与指标收集 在云原生体系中,Prometheus 已成为最主流的监控与报警...
国产开源公众号AI知识库 Agent:突破未认证号限制,一键搞定自动回复,重构运营效率

国产开源公众号AI知识库 Agent:突破未认证号限制,一键搞定自动回复,重构运营效率

国产开源公众号 AI 知识库 Agent:突破未认证号限制,一键搞定自动回复,重构运营效率 大家好,我是星哥,...
星哥带你玩飞牛NAS硬件02:某鱼6张左右就可拿下5盘位的飞牛圣体NAS

星哥带你玩飞牛NAS硬件02:某鱼6张左右就可拿下5盘位的飞牛圣体NAS

星哥带你玩飞牛 NAS 硬件 02:某鱼 6 张左右就可拿下 5 盘位的飞牛圣体 NAS 前言 大家好,我是星...
300元就能买到的”小钢炮”?惠普7L四盘位小主机解析

300元就能买到的”小钢炮”?惠普7L四盘位小主机解析

  300 元就能买到的 ” 小钢炮 ”?惠普 7L 四盘位小主机解析 最近...
240 元左右!五盘位 NAS主机,7 代U硬解4K稳如狗,拓展性碾压同价位

240 元左右!五盘位 NAS主机,7 代U硬解4K稳如狗,拓展性碾压同价位

  240 元左右!五盘位 NAS 主机,7 代 U 硬解 4K 稳如狗,拓展性碾压同价位 在 NA...