寒假生活指导05

今天继续完成实验

4.实验报告

题目:

Spark Streaming 编程初级实践

姓名

 

日期2024.1.13

实验环境:操作系统: Ubuntu16.04 Spark 版本:2.1.0 Flume 版本:1.7.0

实验内容与完成情况:

  1. Flum安装

(1)解压安装包

tar -zxvf apache-flume-1.7.0-bin.tar.gz -C /export/server

cd /export/server

sudo mv ./apache-flume-1.7.0-bin ./flume

sudo chown -R hadoop:hadoop ./flume

⑵配置环境变量

sudo vim ~/.bashrc

export JAVA_HOME=javahome

export FLUME_HOME=/usr/local/flume

export FLUME_CONF_DIR=$FLUME_HOME/conf

export PATH=$PATH:$FLUME_HOME/bin

source ~/.bashrc

#修改 flume-env.sh 配置文件

cd /usr/local/flume/conf

sudo cp ./flume-env.sh.template ./flume-env.sh

sudo vim ./flume-env.sh

#打开 flume-env.sh 文件以后,在文件的最开始位置增加一行内容,用于设置

JAVA_HOME 变量

export JAVA_HOME=javahome

⑶查看 flume 版本信息

cd /usr/local/flume

./bin/flume-ng version #查看 flume 版本信息

 

 

  1. 使用 Avro 数据源测试 Flume

agent 配置文件

1.cd /export/server/flume

2.sudo vim ./conf/avro.conf #在 conf 目录下编辑一个 avro.conf 空文件

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 = 4141

#注意这个端口名,在后面的教程中会用得到

# 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 agent a1

 

/export/server/flume/bin/flume-ng agent -c . -f /export/server/flume/conf/avro.conf -n a1

-Dflume.root.logger=INFO,console #启动日志控制台

⑶创建指定文件

 

先打开另外一个终端,在/usr/local/flume 下写入一个文件 log.00,内容为 hello,world:

/export/server/flume/bin/flume-ng agent -c . -f /export/server/flume/conf/avro.conf -n a1

-Dflume.root.logger=INFO,console #启动日志控制台

#我们再打开另外一个终端

cd /export/server/flume

bin/flume-ng avro-client --conf conf -H localhost -p 4141 -F /export/server/flume/log.00 #4141 是 avro.conf 文件里的端口名

结果展示:

 

 

  1. 使用 netcat 数据源测试 Flume

⑴  创建 agent 配置文件

cd /export/server/flume

sudo vim ./conf/example.conf #在 conf 目录创建 example.conf

#在 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 = 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

⑵  启动 flume agent (即打开日志控制台):

/export/server/flume/bin/flume-ng agent --conf ./conf

--conf-file ./conf/example.conf --name a1

-Dflume.root.logger=INFO,console

再打开一个终端,输入命令:telnet localhost 44444

telnet localhost 44444

这里补充一点,flume 只能传递英文和字符,不可以是中文。

运行结果:

 

 

4.

 

出现的问题:

解决方案(列出遇到的问题和解决办法,列出没有解决的问题):

posted @ 2024-01-13 18:07  一个小虎牙  阅读(3)  评论(0编辑  收藏  举报