Flum、Yum、Telnet、光盘挂载装yum
附加:
Flum的使用
数据处理流程
数据源-----存储-----计算------结果展示
数据倒入场景:(数据采集webServer---DataServer过程)
- 一次性倒入
- 数据更新频次低(一天、一周)
- 实时性导入(毫秒级别)
关于验证码的使用,有第三方接口
比如用户点击获取验证码、第三方接口同时向运营商以及用户各发一次验证码,用户输入验证码再与运营商的相互对比
Flum可以监听接口,文件,http等
Flum配置文件运行的参数解析:
一般情况下文件结构包括三部分:Source(收集)、Channer(聚合)、Sink(输出)
Source:配置文件的来源比如一个接口、文件路径、HTTP请求
Channer:文件暂存比如内存等
Sink:日志保存的位置比如hdfs,Avro(数据序列化系统)等
Telnet(远程连接)的使用
问题:离线的环境,需要装软件,配置一个yum源进行软件安装
本地yum源的配置:(解决rpm包依赖的问题)
第一步:切换到root用户
如果是系统刚刚安装好,有外网就可以直接使用yum
Yum的配置文件路径:
Cd /etc/yum.repos.d/
第二步:对虚拟机的光驱进行配置
右键虚拟机-----设置---CD(DVD)IDE-------将设备状态已连接打上勾----浏览添加虚拟机镜像的位置选择镜像
Dev下可以识别到光盘设备,U盘也会识别成为光盘
执行:
cd /dev/------切换到dev下
ll cdrom-----查看挂载设备的名称
第三步进行光盘挂载:
新建文件夹
Mkdir /mnt/cdrom
Mount /dev/cdrom /mnt/cdrom/
第四步配置本地的yum源:
Cd /etc/yum.repos.d/
将原来的文件进行备份
mv CentOS-Base.repo CentOS-Base.repo.bak
修改文件
在/etc/yum.repos.d/路径下
vi CentOS-Media.repo
关闭校验:gpgcheck=0 -> 路径配置:baseurl=file:///mnt/cdrom -> 开启:enabled=1
注释掉gpgkey那一行
保存退出
Yum list telnet搜所一下有没有telnet软件
Yum源配置完成
Yum公网软件包网址:
Yum 安装软件:
Yum install {name}-------首先去搜所-----结果列表------确认后进行安装
注意********************************************************
如果安装gcc以及ngnix等源码安装的软件的话需要将配置复位,不然安装不了,所以需要慎重配置
光盘挂载删除掉
备份文件复位CentOS-Base.repo
vi CentOS-Media.repo
[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
file:///media/cdrom/
file:///media/cdrecorder/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
************************************************************************************
安装telnet
Yum install telnet
然后用telnet链接44444端口发送数据
Telnet hh(主机名) 44444(端口号)
Telnet相当于SecureCRT的linux远程连接工具一样
Linux的Tomcat运行程序的监控
Flume
掌握Flume的安装和使用了解实时计算的应用和场景
一、Flume概述
分布式、高可靠、高可用服务,用于高效收集,聚合和移动大量的日志数据
二、Flume核心组件
1. Source(收集)
2. Channel(聚合)
3. Sink(输出)
4. 架构模式
跨过多个代理,或跳数据流,接收器指向源的主机名和端口
常见的日志收集方式,多个生成日志的客户端将数据存储到少数消费者中
可以将日志信息复用到多个目的地
三、Flume安装部署
1. 安装
安装包:apache-flume-1.8.0-bin.tar.gz
解压缩
tar -zvxf apache-flume-1.8.0-bin.tar.gz
环境变量配置(.bash_profile)
vi ~/.bash_profile
export FLUME_HOME=/home/bigdata/apache-flume-1.8.0-bin
PATH=$PATH:$FLUME_HOME/bin
source .bash_profile
2. 配置
配置启动脚本文件
cd $FLUME_HOME/conf
mv flume-env.sh.template flume-env.sh
vi flume-env.sh
export JAVA_HOME=/opt/app/jdk1.8.0_181
a1:agent名称
r1:source名称
c1:channel名称
k1:sink名称
cd $FLUME_HOME/conf
touch example.conf
vi example.conf
# example.conf: A single-node Flume configuration
# 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 = SZ01
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
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
启动命令
flume-ng agent \
--name a1 \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/example.conf \
-Dflume.root.logger=INFO,console
解析:console只有sinks配置成logger的时候才会用到
四、Flume日志收集
1. 从端口直接采集数据
从指定网络端口采集数据输出到控制台
telnet SZ01 44444
hello flume
Event: {
headers:{}
body: 68 65 6C 6C 6F 20 66 6C 75 6D 6E 0D hello flume.
}
2. 采集文件新增的数据
修改source的type属性为:exec
添加source的command属性为:tail -f {fileName}
cd $FLUME_HOME/conf
touch file-memory-logger.conf
vi file-memory-logger.conf
# 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 /home/bigdata/data.log
# Describe the sink
a1.sinks.k1.type = logger
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
启动命令
flume-ng agent \
--name a1 \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/file-memory-logger.conf \
-Dflume.root.logger=INFO,console
追加内容
echo hello flume >> ~/data.log
Event: {
headers:{}
body: 68 65 6C 6C 6F 20 66 6C 75 6D 65 hello flume
}
3. 将采集的日志记录到文件
修改sink的type属性为:hdfs
添加sink的hdfs.path属性为:{hdfsPath}
cd $FLUME_HOME/conf
touch file-memory-hdfsFile.conf
vi file-memory-hdfsFile.conf
# 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 /home/bigdata/data.log
# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://SZ01:8020/flume
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
启动命令
flume-ng agent \
--name a1 \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/file-memory-hdfsFile.conf
4. 将数据收集到另外的服务器
服务器A:source(exec) + channel(memory) + sink(avro)
cd $FLUME_HOME/conf
touch file-memory-avro.conf
vi file-memory-avro.conf
# 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 /home/bigdata/data.log
# Describe the sink
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = SZ01
a1.sinks.k1.port = 44444
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
flume-ng agent \
--name a1 \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/file-memory-avro.conf
服务器B:source(avro) + channel(memory) + sink(logger)
Echo 内容 >> 文件------------向文件追加内容
Flum监听web应用
Linux的Tomcat运行程序的监控
第一步:web创建程序
添加log4j的jar包放在lib文件夹下
Src下添加log4j.properties配置文件
# 全局配置 -> DEBUG(调试) -> INFO(信息) ->ERROR(错误)
|
ServerLet代码
ackage com.org.contrl; //tomcat下的log也会记录相关的信息 |
Jsp代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %> |
项目打包:
File----Project structure-------Artifacts----点击加号-------Web Application Archive--------for javaEE;war exploded----Apply---OK
然后点击build-----build Artifacts
右键压缩包-----show in exporter----复制压缩包到指定的位置
将压缩包上传到tomcat的webapp下面
Tomcat中配置80端口
root用户设置端口转发 - 80->8080 - 添加转发规则
到root用户下
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
(1)Tomcat中设置默认访问的项目(ROOT)
(2)修改项目名称为ROOT(修改原ROOT为别的)以第二种举例
mv ROOT ROOT1
rm -rf javaEE_war
mv javaEE_war.war ROOT.war
./startup.sh
启动网站
Flume文件配置:
cd $FLUME_HOME/conf
|
启动flume监控
flume-ng agent \ --name a1 \ --conf $FLUME_HOME/conf \ --conf-file $FLUME_HOME/conf/example-file.conf \ -Dflume.root.logger=INFO,console
|
查看(已经添加了内容)
data.log
Flum方式采集数据->生成文件存储(HDFS)
cp example-file.conf example-hdfs.conf
Vi example-hdfs.conf
# 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 /home/hadoop/data.log # Describe the sink a1.sinks.k1.type = hdfs a1.sinks.k1.hdfs.path = hdfs://hh:8020/logDir
# Use a channel which buffers events in memory a1.channels.c1.type = memory
# Bind the source and sink to the channel a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1 |
flume-ng agent \
--name a1 \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/example-hdfs.conf
此时hdfs中会出现logDir文件夹
再次运行Tomcat中的项目
可以下载查看文件
Avro的配置
启动两个flume程序
第一个传递日志
复制两份文件
example-avro1.conf
example-avro2.conf
接受日志
flume-ng agent \
--name a1 \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/example-avro1.conf
flume-ng agent \
--name a1 \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/example-avro2.conf
再一次运行web程序查看生成的log文件