4.1 Flume(日志收集系统)

简介

  • 最开始是cloudera实时日志收集系统,现在纳入到Apache旗下
  • 版本:
    flume-og
    flume-ng


Flume工作流程

  • flume由event作为其基本单位
    它是一个字节数组
    由消息头和消息内容组成
  • 在Source端创建,然后发送给channel,最终传递给Sink持久化
  • Source:源数据端,负责产生数据,按照指定的格式进行压缩
        avro
        exec
        spool dir
        netcat
  • channel:数据的缓冲区(类似于生产者消费者模式)
        memory
        file
        jdbc
  • Sink:数据的目的地端,负责持久化数据
        hdfs
        roll file
        hbase
        elastic search
  • Flume就是由这三段组成,一个三段被统称为Agent
    将来我们搭建的时候,我们需要指定 source的channel,Sink的channel
    Flume 运行的核心是 Agent。Flume以agent为最小的独立运行单位。
  • 数据的过滤
    我们可以在source和channel中间添加过滤器
  • 数据传输的安全
    channel中:
            在送到目的地之前,会先缓存数据,待数据真正到达目的地后,删除自己缓存的数据。
    end-to-end
        收到数据agent首先将event写到磁盘上,当数据传送成功后,再删除;如果数据发送失败,可以重新发送。
    Store on failure
        这也是scribe采用的策略,当数据接收方crash时,将数据写到本地,待恢复后,继续发送
    Besteffort
        数据发送到接收方后,不会进行确认


Flume的搭建

准备flume的tar包

在这里插入图片描述

1.解压移动并简单修改

解压tar包
语法:
tar -zxf apache-flume-1.6.0-bin.tar.gz
移动到软件目录
语法:
mv apache-flume-1.6.0-bin /opt/sxt/
进入文件夹
语法:
cd /opt/sxt/
修改目录名称
语法:
mv apache-flume-1.6.0-bin flume-1.6.0

完成示意图:
在这里插入图片描述

2.修改配置文件

进入配置文件目录后修改配置文件名称(conf目录)

语法:
cp flume-env.sh.template flume-env.sh
编辑flume-env.sh配置文件
语法:
vim flume-env.sh

因为flume是基于java的
----修改JAVA_HOME和Jvm Options

这里只修改JAVA_HOME即可 Jvm Options暂时用不到


3.修改环境变量

语法:
vim /etc/profile
source /etc/profile

Flume 使用测试

查看官网用户文档
http://flume.apache.org/releases/content/1.9.0/FlumeUserGuide.html

测试(flume版本)

语法:
flume-ng version

创建存放flume配置目录
在Flume安装目录下创建一个新的文件夹,用来存放接下来的配置

语法:
mkdir -p /opt/sxt/flume-1.6.0/options

Flume测试netcat----logger(本机来源)

netcat

进入自己创建的配置文件目录
cd /opt/sxt/flume-1.6.0/options
创建并编辑配置文件
vim netcat2logger.conf

这里用 来源和输出来命名 为了好区分

配置文件

# example.conf: A single-node Flume configuration
# flume-ng agent -n a1 -f /opt/sxt/flume-1.6.0/options/netcat2logger.conf -Dflume.root.logger=INFO,console

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

# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444

# Describe the sink
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
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

第二行是自己要用的执行代码记下来要用
因为太长所以存到这里了

官网netcat
在这里插入图片描述
配置netcat有3个必选项
类型 ---- type
绑定(数据来源) ---- bind
端口 ---- port

启动flume语法:
flume-ng agent -n a1 -f /opt/sxt/flume-1.6.0/options/netcat2logger.conf -Dflume.root.logger=INFO,console

解析:
flume-ng agent ---- 固定格式
a1 ---- 源路径别名 在配置文件中定的
/…/ ---- 配置文件路径
-Ddlume.root.logger=…,… ---- 输出级别&输出方式

控制台打印的提示 开启 ….
INFO channel.DefaultChannelFactory: Creating instance of channel c1 type memory
INFO source.DefaultSourceFactory: Creating instance of source r1, type netcat
INFO sink.DefaultSinkFactory: Creating instance of sink: k1, type: logger
INFO node.AbstractConfigurationProvider: Channel c1 connected to [r1, k1]


源----r1 管道----c1 sink----k1

使用telnet访问本机的44444端口(用Xshell再启动一个1号机)

语法:
telnet localhost 44444

测试的另一个本机进行输入测试
在这里插入图片描述

本机显示测试数据:
在这里插入图片描述

输出机退出
ctrl+] -->quit
本机退出
ctrl + c

Flume测试exec----logger (nginx来源)

exec

在options目录中创建并编辑配置文件

语法:
vim exec2logger.conf

配置文件

#flume-ng agent -n a1 -f /opt/sxt/flume-1.6.0/options/exec2logger.conf -Dflume.root.logger=INFO,console
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /var/sxt/nginx/log/access.log

# Describe the sink
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
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

配置exec有2个必选项

类型 ---- type
绑定(数据来源) ---- bind

启动flume语法:
flume-ng agent -n a1 -f /opt/sxt/flume-1.6.0/options/exec2logger.conf -Dflume.root.logger=INFO,console
(额外主机)追加 hello 到 一个access.log的文件中(只是测试用的)
语法:
echo 'hello' >> /var/sxt/nginx/log/access.log

本机显示
在这里插入图片描述

接着测试下nginx情况
额外主机启动nginx

语法:
cd /opt/sxt/nginx/sbin
./nginx

eclipse启动BIG_DATA_LOG2 服务
点击测试
在这里插入图片描述
在这里插入图片描述

Flume测试dir ---- logger (nginx来源)

spooldir (监控以文件为单位)

以文件目录中的文件为基本读取单位,只对创建或者拷贝的文件有效
如果你想向文件中添加数据,是读取不到的
上面的netcat和exec是监听数据

在options目录中创建并编辑配置文件

语法:
vim dir2logger.conf

配置文件

#flume-ng agent -n a1 -f /opt/sxt/flume-1.6.0/options/dir2logger.conf -Dflume.root.logger=INFO,console
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /var/sxt/nginx/log

# Describe the sink
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
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

在这里插入图片描述

启动flume语法:
flume-ng agent -n a1 -f /opt/sxt/flume-1.6.0/options/dir2logger.conf -Dflume.root.logger=INFO,console

额外主机查看
在这里插入图片描述


查看 /var/sxt/nginx/log/目录下的access.log文件立即变成了
带有.COMPLETED后缀的文件
代表监控完成


这里删除该文件重新创建结果也是一样
测试只传送数据不会对其造成影响
结论----只监控文件 不监控数据
主机显示
在这里插入图片描述
前面省略了一些代码


Flume测试netcat ---- hdfs

在options目录中创建并编辑配置文件

语法:
vim dir2hdfs.conf

配置文件

#flume-ng agent -n a1 -f /opt/sxt/flume-1.6.0/options/netcat2hdfs.conf -Dflume.root.logger=INFO,console
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444


# Describe the sink
a1.sinks.k1.type=hdfs
hdfs.filePrefix=shsxt
a1.sinks.k1.hdfs.path=hdfs://shsxt/flume/netcat2hdfs/%Y-%m-%d/%H%M

##每隔60s或者文件大小超过10M的时候产生新文件
# hdfs有多少条消息时新建文件,0不基于消息个数
a1.sinks.k1.hdfs.rollCount=0
# hdfs创建多长时间新建文件,0不基于时间
a1.sinks.k1.hdfs.rollInterval=60
# hdfs多大时新建文件,0不基于文件大小
a1.sinks.k1.hdfs.rollSize=10240
# 当目前被打开的临时文件在该参数指定的时间(秒)内,没有任何数据写入,则将该临时文件关闭并重命名成目标文件
a1.sinks.k1.hdfs.idleTimeout=3

# 数据类型和使用本地时间
a1.sinks.k1.hdfs.fileType=DataStream
a1.sinks.k1.hdfs.useLocalTimeStamp=true

## 每五分钟生成一个目录:
# 是否启用时间上的”舍弃”,这里的”舍弃”,类似于”四舍五入”,后面再介绍。如果启用,则会影响除了%t的其他所有时间表达式
a1.sinks.k1.hdfs.round=true
# 时间上进行“舍弃”的值;
a1.sinks.k1.hdfs.roundValue=5
# 时间上进行”舍弃”的单位,包含:second,minute,hour
a1.sinks.k1.hdfs.roundUnit=minute

# Use a channel which buffers events in memory
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
启动flume语法:
flume-ng agent -n a1 -f /opt/sxt/flume-1.6.0/options/netcat2hdfs.conf -Dflume.root.logger=INFO,console

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

因为设置了3秒
快速刷新可以看到以.tmp结尾的文件

其他示例
参考官网配置即可



项目中Flume的配置

目标:日志存放/log/目录下 以yyyyMMdd为子目录 分别存放每天的数据

将Linux本地的日志信息抓取到HDFS

在options目录中创建并编辑配置文件

语法:
vim app.conf

配置文件

#nohup flume-ng agent -n a1 -f /opt/sxt/flume-1.6.0/options/app.conf -Dflume.root.logger=INFO,console >>/root/flume.log 2>&1 &
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /var/sxt/nginx/log/access.log

# Describe the sink
a1.sinks.k1.type=hdfs
a1.sinks.k1.hdfs.path=hdfs://shsxt/flume/app/%Y%m%d/%H%M
a1.sinks.k1.hdfs.filePrefix=shsxt

##每隔60s或者文件大小超过10M的时候产生新文件
# hdfs有多少条消息时新建文件,0不基于消息个数
a1.sinks.k1.hdfs.rollCount=0
# hdfs创建多长时间新建文件,0不基于时间
a1.sinks.k1.hdfs.rollInterval=60
# hdfs多大时新建文件,0不基于文件大小
a1.sinks.k1.hdfs.rollSize=10240
# 当目前被打开的临时文件在该参数指定的时间(秒)内,没有任何数据写入,则将该临时文件关闭并重命名成目标文件
a1.sinks.k1.hdfs.idleTimeout=3

# 数据类型和使用本地时间
a1.sinks.k1.hdfs.fileType=DataStream
a1.sinks.k1.hdfs.useLocalTimeStamp=true

## 每五分钟生成一个目录:
# 是否启用时间上的”舍弃”,这里的”舍弃”,类似于”四舍五入”,后面再介绍。如果启用,则会影响除了%t的其他所有时间表达式
a1.sinks.k1.hdfs.round=true
# 时间上进行“舍弃”的值;
a1.sinks.k1.hdfs.roundValue=10
# 时间上进行”舍弃”的单位,包含:second,minute,hour
a1.sinks.k1.hdfs.roundUnit=minute

# Use a channel which buffers events in memory
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

注意:
此时可能出现一些问题

我们先去/var/sxt/nginx/log/将里面的文件全部删除
重新建一个access.log文件
rm -rf …
cd /var/sxt/nginx/log/
touch access.log
重启nginx
cd /opt/sxt/nginx/sbin/
./nginx -s reload

在这里插入图片描述

flume启动语法:
nohup flume-ng agent -n a1 -f /opt/sxt/flume-1.6.0/options/app.conf -Dflume.root.logger=INFO,console >>/root/flume.log 2>&1 &

这里用了黑洞 所以看不到打印信息

测试结果:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

ETL数据清洗

  • ETL是英文Extract-Transform-Load的缩写,用来描述将数据从来源端经过抽取(extract)、转换(transform)、加载(load)至目的端的过程。

  • 作用

      去除掉脏数据,无效数据

      将数据拆分成能直接处理的格式

数据示例:
192.168.31.1^A1575530576.255^Abd1301^A/shsxt.jpg?en=e_pv&p_url=http%3A%2F%2Flocalhost%3A8080%2FBIG_DATA_LOG2%2Fdemo2.jsp&p_ref=http%3A%2F%2Flocalhost%3A8080%2FBIG_DATA_LOG2%2Fdemo2.jsp&tt=%E6%B5%8B%E8%AF%95%E9%A1%B5%E9%9D%A22&ver=1&pl=website&sdk=js&u_ud=77D8B5C4-51EF-4227-A9F5-7D183B24624C&u_mid=zhangsan&u_sd=6D1E3941-2F2D-4137-AB28-16C4FFA26F5F&c_time=1575530576039&l=zh-CN&b_iev=Mozilla%2F5.0%20(Windows%20NT%206.1%3B%20Win64%3B%20x64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F78.0.3904.108%20Safari%2F537.36&b_rst=1366*768

      我们将数据清洗的结果直接存放到HBase

      HBase可以和MapReduce无缝对接

  • 数据的处理

      普通数据:转换成键值对格式(key=value)
      特殊数据:
            IP:TestIPSeekerExt–>将IP转化成 (国 省 市)
            浏览器信息:UserAgentUtil–》将浏览器信息转成(名字,版本,操作系统,操作系统版本)
      所有数据都会处理好放入到Map中

额外的 项目中的内容
TestMaker 运行
使用项目途中的建表
创建表 hbase shell
create ‘eventlog’,’log’

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
牙科就诊管理系统利用当下成熟完善的SSM框架,使用跨平台的可开发大型商业网站的Java语言,以及最受欢迎的RDBMS应用软件之一的Mysql数据库进行程序开发。实现了用户在线查看数据。管理员管理病例管理、字典管理、公告管理、药单管理、药品管理、药品收藏管理、药品评价管理、药品订单管理、牙医管理、牙医收藏管理、牙医评价管理、牙医挂号管理、用户管理、管理员管理等功能。牙科就诊管理系统的开发根据操作人员需要设计的界面简洁美观,在功能模块布局上跟同类型网站保持一致,程序在实现基本要求功能时,也为数据信息面临的安全问题提供了一些实用的解决方案。可以说该程序在帮助管理者高效率地处理工作事务的同时,也实现了数据信息的整体化,规范化与自动化。 管理员在后台主要管理病例管理、字典管理、公告管理、药单管理、药品管理、药品收藏管理、药品评价管理、药品订单管理、牙医管理、牙医收藏管理、牙医评价管理、牙医挂号管理、用户管理、管理员管理等。 牙医列表页面,此页面提供给管理员的功能有:查看牙医、新增牙医、修改牙医、删除牙医等。公告信息管理页面提供的功能操作有:新增公告,修改公告,删除公告操作。公告类型管理页面显示所有公告类型,在此页面既可以让管理员添加新的公告信息类型,也能对已有的公告类型信息执行编辑更新,失效的公告类型信息也能让管理员快速删除。药品管理页面,此页面提供给管理员的功能有:新增药品,修改药品,删除药品。药品类型管理页面,此页面提供给管理员的功能有:新增药品类型,修改药品类型,删除药品类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值