一、HDFS 文件系统操作
1. 查看文件/目录列表
hdfs dfs -ls /path # 查看 HDFS 目录内容
hdfs dfs -ls -R /path # 递归列出目录内容
2. 创建目录
hdfs dfs -mkdir -p /user/hadoop/demo # 创建多级目录
3. 上传/下载文件
hdfs dfs -put local_file /hdfs_path # 上传本地文件到 HDFS
hdfs dfs -get /hdfs_file local_path # 下载 HDFS 文件到本地
4. 删除文件/目录
hdfs dfs -rm /hdfs_file # 删除文件
hdfs dfs -rm -r /hdfs_dir # 递归删除目录
5. 查看文件内容
hdfs dfs -cat /hdfs_file # 查看文件内容
hdfs dfs -tail /hdfs_file # 查看文件末尾内容
二、集群状态与管理
1. 查看集群健康状态
hdfs dfsadmin -report # 显示集群整体状态(节点数、容量、剩余空间等)
2. 节点管理
yarn node -list # 查看集群节点列表
hdfs dfsadmin -refreshNodes # 刷新节点状态(如添加/删除节点后)
3. 资源管理
yarn resourcemanager -status # 查看 ResourceManager 状态
yarn application -list # 查看所有运行中的应用
三、任务与作业监控
1. 查看作业状态
yarn application -status <APP_ID> # 查看指定应用的详细状态
mapred job -list # 查看历史作业列表(需启用 JobHistory Server)
2. 杀死作业
yarn application -kill <APP_ID> # 终止指定应用
四、服务启停命令
1. 启动服务
start-dfs.sh # 启动 HDFS 服务(NameNode、DataNode、SecondaryNameNode)
start-yarn.sh # 启动 YARN 服务(ResourceManager、NodeManager)
2. 停止服务
stop-dfs.sh # 停止 HDFS 服务
stop-yarn.sh # 停止 YARN 服务
五、其他实用命令
权限管理
hdfs dfs -chmod 755 /hdfs_dir # 修改目录权限
hdfs dfs -chown user:group /hdfs_file # 修改文件所有者和组
数据均衡
start-balancer.sh # 启动集群数据均衡工具