用springxd在hadoop中加载数据

disho6za  于 2021-06-03  发布在  Hadoop
关注(0)|答案(2)|浏览(323)

我试图在http源和hdfs接收器之间创建一个流。我的springxd和hdfs安装在不同的机器上**但是我可以启动 hadoop fs ls / 命令成功。
创建和部署流之后,当我使用以下方式发布数据时:

http post --target http://{ipaddressofhdfsmachine:8020} -- data"hello"

它抛出错误:
无法将数据发送到http端点http://{ipaddressofhdfsmachine:8020}
当我使用 localhost with port 9000 它成功地完成了,但是在hdfs中什么也没有显示。
有必要在同一台机器上使用hdfs和spring来创建流吗?

mi7gmzs6

mi7gmzs61#

要知道出了什么问题有点困难,但我会尽量做出有根据的猜测。我不知道您是运行xd singlenode还是分布式模式,是否更改了默认配置以及如何创建流。参考文档可以从spring xd中找到
我在主操作系统(localhost)上运行xd,在虚拟机(node1)上运行hdfs。
因为默认情况下,hdfs namenode地址假定为hdfs://localhost:8020需要更改。用于此用途 servers.yml 文件和更改 fsUri (请注意此yaml文件格式中的空格)。 config/servers.yml :


# Hadoop properties

spring:
  hadoop:
    fsUri: hdfs://node1:8020

我启动xd单节点:

./xd-singlenode

然后运行stream命令,写一些东西并检查写了什么:

xd:>hadoop config fs --namenode hdfs://node1:8020

xd:>hadoop fs ls --recursive true --dir /xd
lsr: `/xd': No such file or directory

xd:>stream create --name test --definition "http|hdfs" --deploy
Created and deployed new stream 'test'

xd:>http post --data "hello" http://localhost:9000
> POST (text/plain;Charset=UTF-8) http://localhost:9000 hello
> 200 OK

xd:>hadoop fs ls --recursive true --dir /xd
drwxr-xr-x   - jvalkealahti supergroup          0 2014-07-14 21:33 /xd/test
-rw-r--r--   3 jvalkealahti supergroup          0 2014-07-14 21:33 /xd/test/test-0.txt.tmp

xd:>stream destroy --name test 
Destroyed stream 'test'

xd:>hadoop fs ls --recursive true --dir /xd
drwxr-xr-x   - jvalkealahti supergroup          0 2014-07-14 21:33 /xd/test
-rw-r--r--   3 jvalkealahti supergroup          6 2014-07-14 21:33 /xd/test/test-0.txt

xd:>hadoop fs cat --path /xd/test/test-0.txt
hello
mnemlml8

mnemlml82#

您必须发布到xd机器,而不是hadoop hdfs机器。
xdhttp接收器将获取post并将其路由到hdfs。
确保你的节点已经为hadoop设置好了,你的shell也已经设置好了。
例如,如果您使用的是2.0:

xd-singlenode --hadoopDistro phd20

xd-shell --hadoopDistro phd20

xd:> had config fs --namenode hdfs://MyPivotalHDServer:8020

查看springxd的github文档,获取最新的springxd,它在不断改进。https://github.com/spring-projects/spring-xd/wiki/sources#http
使用xd shell在服务器中创建流定义

xd:> stream create --name httptest --definition "http | hdfs" --deploy

将一些数据发布到默认端口9000上的http服务器

xd:> http post --target http://localhost:9000 --data "hello world to hadoop from springxd"

这段youtube视频将为您介绍一个示例:http://youtu.be/41sihawjhe0?t=37m6s
您必须发布几次,这取决于您的文件何时足够满,以便滚动到新的块中,或者您需要停止流以检查文件。
首先将内容发送到日志,以便您可以在xd输出日志中看到它。很适合调试。

相关问题