ubuntu下安装
http://www.powerxing.com/install-hadoop/
hadoop命令
和linux基本命令很像
cd到hadoop安装目录
对dfs的操作
执行 NameNode 的格式化
./bin/hdfs namenode -format
启动hadoop
./sbin/start-dfs.sh
在HDFS中创建用户目录
./bin/hdfs dfs -mkdir -p /user/hadoop
在HDFS中创建目录
./bin/hdfs dfs -mkdir /user/hadoop/input
从linux上传文件到hdfs
./bin/hdfs dfs -put ./etc/hadoop/*.xml /user/hadoop/input
查看HDFS文件列表
./bin/hdfs dfs -ls /user/hadoop/input
查看HDFS文件的命令
./bin/hdfs dfs -cat output/*
将 HDFS 上的 output 文件夹拷贝到本机
./bin/hdfs dfs -get /user/hadoop/output ./output
在HDFS上将文件从源路径复制到目标路径
./bin/hdfs dfs -cp /user/hadoop/input/22.txt /user/hadoop/input/11.txt
文件连接getmerge
使用方法:hadoop fs -getmerge <src> <localdst> [addnl]
接受一个源目录和一个目标文件作为输入,并且将源目录中所有的文件连接成本地目标文件。addnl是可选的,用于指定在每个文件结尾添加一个换行符。
假设在你的hdfs集群上有一个/user/hadoop/output目录
里面有作业执行的结果(多个文件组成)part-000000,part-000001,part-000002
然后你想把所有的文件合拢来一起看 可以使用命令:
./bin/hdfs dfs -getmerge /user/hadoop/output/ ~/re.txt
在hdfs指定目录下新建一个空文件
./bin/hdfs dfs -touchz /user/hadoop/input/11.txt
将HDFS上某个文件重命名
./bin/hdfs dfs -mv /user/hadoop/input/11.txt /user/hadoop/input/22.txt
删除HDFS下output 文件夹
./bin/hdfs dfs -rm -r /user/hadoop/output
关闭 Hadoop
./sbin/stop-dfs.sh
常见错误
错误:java.lang.IllegalArgumentException: Wrong FS: hdfs:/, expected: file:///
解决方法:
把hadoop集群上的core-site.xml和hdfs-site.xml放到工程的src目录下
或者
conf.addResource(newPath("/home/hadoop/conf/core-site.xml"));
错误:Input path does not exist
修改代码:
FileInputFormat.addInputPath(job,new Path("hdfs://localhost:9000/anders/passwd"));
FileOutputFormat.setOutputPath(job, new Path("hdfs://localhost:9000/anders/out1"));
这样才能正确,这个路径是根据core-site.xml里面的fs.default.name
http://www.cnblogs.com/wuyudong/category/592600.html
http://blog.csdn.net/GarfieldEr007/article/category/2472155