Java 使用SpringXD在Hadoop中加载数据
我试图在HTTP源和HDFS接收器之间创建一个流。我的springXD和HDFS安装在不同的机器上**,但我能够成功地启动Java 使用SpringXD在Hadoop中加载数据,java,spring,hadoop,hdfs,spring-xd,Java,Spring,Hadoop,Hdfs,Spring Xd,我试图在HTTP源和HDFS接收器之间创建一个流。我的springXD和HDFS安装在不同的机器上**,但我能够成功地启动hadoop fs ls/命令 创建和部署流后,当我使用以下方式发布数据时: http post --target http://{ipaddressofhdfsmachine:8020} -- data"hello" 它抛出了一个错误: 无法将数据发送到http端点http://{IPAddressOfHfDfsMachine:8020} 当我使用带有端口9000的loc
hadoop fs ls/
命令
创建和部署流后,当我使用以下方式发布数据时:
http post --target http://{ipaddressofhdfsmachine:8020} -- data"hello"
它抛出了一个错误:
无法将数据发送到http端点http://{IPAddressOfHfDfsMachine:8020}
当我使用带有端口9000的localhost时,它成功地完成了,但在hdfs中没有显示任何内容
有必要在同一台机器上使用hdfs和spring来创建流吗?要知道出了什么问题有点困难,但我会尝试做出有根据的猜测。我不知道您是运行XD singlenode还是分布式模式,您是否更改了默认配置以及如何创建流。参考文件可从以下位置找到:
我是我的设置,我在我的主操作系统(本地主机)上运行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
您必须发布到XD机器,而不是Hadoop HDFS机器
XDHTTP接收器将获取POST并为您将其路由到HDFS
确保为Hadoop设置了节点,并且shell也已设置
例如,如果您使用的是Pivotal PHD 2.0:
xd-singlenode --hadoopDistro phd20
xd-shell --hadoopDistro phd20
xd:> had config fs --namenode hdfs://MyPivotalHDServer:8020
查看SpringXD的Github文档,获取最新的SpringXD,它正在不断改进
使用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视频将引导您了解一个示例:
您必须发布几次,这取决于您的文件何时足够满,可以滚动到新的块中,或者您需要停止流以检查文件
首先将内容发送到日志,以便可以在XD输出日志中看到它。很适合调试。感谢Janne的回答。我照你的建议做了,但得到了同样的结果。我使用http post成功地发布了数据,但当我使用hadoop fs-ls recursive true--dir/xd时,它给出了:lsr:DEPRECATED:请改用“ls-R”。.lsr:“/xd”没有这样的文件或目录。然后我非常确定xd singlenode的日志应该显示一些错误。如果您使用singlenode运行它,那么XD admin/container将在同一jvm中执行,因此您会看到admin/container的日志记录是同一个shell。Yaml格式对于正确缩进和使用空格(而不是制表符)非常敏感。不管怎样,如果您在那里出错或出现其他错误,日志应该显示hdfs接收器是否无法写入hdfs。我看到的另一个问题是,在默认情况下,hdfs接收器尝试写入/xd/。如果sink没有创建此目录的权限,则可以使用--directory config选项对其进行更改。嘿,Janne,我检查了日志并遇到错误消息DeliveryException,表示Dispatcher没有订阅服务器。关于这方面的任何建议。我正在尝试修复它。请确保您创建了主/xd目录,并为其授予适当的测试权限(通常为777),以确保一切正常,并从常规HDFS和xd命令到HDFS进行测试。