温馨提示×

centos怎样测试hdfs配置

小樊
43
2026-09-21 16:21:58
栏目: 智能运维

在 CentOS 上测试 HDFS 配置通常分为几个层面:配置文件检查、服务启动、基本命令测试、Web 界面验证、日志排查。下面给你一套常用且实用的测试流程。


一、确认 HDFS 配置文件

HDFS 核心配置文件一般在:

/etc/hadoop/
# 或
$HADOOP_HOME/etc/hadoop/

重点检查:

  • core-site.xml
  • hdfs-site.xml

示例(core-site.xml):

<property>
  <name>fs.defaultFS</name>
  <value>hdfs://localhost:9000</value>
</property>

示例(hdfs-site.xml):

<property>
  <name>dfs.replication</name>
  <value>1</value>
</property>

二、格式化 NameNode(首次)

⚠️ 只在首次部署执行

hdfs namenode -format

成功标志:

Storage directory ... has been successfully formatted

三、启动 HDFS 服务

start-dfs.sh

或单独启动:

hadoop-daemon.sh start namenode
hadoop-daemon.sh start datanode

检查进程:

jps

应看到:

  • NameNode
  • DataNode
  • SecondaryNameNode(非必需)

四、基础 HDFS 命令测试

1️⃣ 查看 HDFS 根目录

hdfs dfs -ls /

2️⃣ 创建目录

hdfs dfs -mkdir /test

3️⃣ 上传文件

echo "hello hdfs" > test.txt
hdfs dfs -put test.txt /test/

4️⃣ 查看文件

hdfs dfs -cat /test/test.txt

5️⃣ 下载文件

hdfs dfs -get /test/test.txt ./test2.txt

五、Web 界面测试(推荐)

在浏览器访问(CentOS 服务器 IP):

http://<ip>:9870

(Hadoop 3.x) 或

http://<ip>:50070

(Hadoop 2.x)

可看到:

  • Live Nodes
  • 文件系统浏览

六、常见测试问题排查

1️⃣ 连接失败

hdfs dfs -ls /

报错:Connection refused

检查:

netstat -tunlp | grep 9000

或

firewall-cmd --list-all

关闭防火墙测试:

systemctl stop firewalld

2️⃣ 权限问题

hdfs dfs -mkdir /test

报错:Permission denied

解决:

hdfs dfs -chmod -R 777 /

或修改 hdfs-site.xml:

<property>
  <name>dfs.permissions.enabled</name>
  <value>false</value>
</property>

七、简单连通性测试(不用 HDFS 命令)

telnet localhost 9000

或

curl http://localhost:9870

如果你愿意,可以告诉我:

  • CentOS 版本
  • Hadoop 版本
  • 单机 / 集群
  • 具体报错信息

我可以帮你精准定位配置问题。

0 踩