Hadoop操作
1、Hadoop控制
启动:
hdfs:
/hadoop/hadoop-2.7.7/sbin/start-dfs.sh
在第一次启动hdfs之前先格式化:
/hadoop/hadoop-2.7.7/bin/hdfs namenode -format
yarn:
/hadoop/hadoop-2.7.7/sbin/start-yarn.sh
resourceManager:
/hadoop/hadoop-2.7.7/sbin/yarn-daemon.sh start resourcemanager
日志服务:
/hadoop/hadoop-2.7.7/sbin/mr-jobhistory-daemon.sh start historyserver
namenode:
/hadoop/hadoop-2.7.7/sbin/hadoop-daemon.sh start namenode
datanode:
/hadoop/hadoop-2.7.7/sbin/hadoop-daemon.sh start datanode
所有进程:
/hadoop/hadoop-2.7.7/sbin/start-all.sh
停止:
hdfs:
/hadoop/hadoop-2.7.7/sbin/stop-dfs.sh
yarn:
/hadoop/hadoop-2.7.7/sbin/stop-yarn.sh
resourceManager:
/hadoop/hadoop-2.7.7/sbin/yarn-daemon.sh stop resourcemanager
日志服务:
/hadoop/hadoop-2.7.7/sbin/mr-jobhistory-daemon.sh stop historyserver
namenode:
/hadoop/hadoop-2.7.7/sbin/hadoop-daemon.sh stop namenode
datanode:
/hadoop/hadoop-2.7.7/sbin/hadoop-daemon.sh stop datanode
所有进程:
/hadoop/hadoop-2.7.7/sbin/stop-all.sh
2、查看、修改、添加目录/文件
(1)查看指定目录下的文件
hadoop dfs –ls [目录]
hadoop dfs -ls /input
(2)查看文件内容
hadoop dfs –cat [文件]
hadoop dfs -cat /input/test.txt
(3)上传本地文件/目录到hadoop
hadoop fs -put [本地文件/目录] [hadoop目录]
hadoop fs -put /root/test.txt /input
(4)将hadoop上文件存储至本地
hadoop fs –get [hadoop目录/文件] [本地目录]
hadoop fs -get /input/test.txt /root
(5)将hadoop中目录下所有文件内容汇总并下载至本地
hadoop fs -getmerge [hadoop目录] [本地目录]
hadoop fs -getmerge /input /root/1.txt
(6)删除已有的文件/目录
hadoop fs –rm [文件/目录地址]
hadoop fs -rm /input/test.txt
(6)创建新的目录
hadoop fs -mkdir [目录地址]
hadoop fs -mkdir /input/aaa
(7)创建新的文件
hadoop fs -touchz [hadoop目录/文件]
hadoop fs -touchz /input/2.txt
(8)移动文件
hadoop fs -mv [hadoop原目录] [hadoop新目录]
hadoop fs -mv /input/test.txt /qaz