在 CentOS 上“测 HDFS 配置”通常分几种情况:配置是否正确、HDFS 是否能启动、基本读写是否正常。下面按最常用、最实用的方式来说明。
HDFS 核心配置文件一般在:
$HADOOP_HOME/etc/hadoop/
重点看这几个文件:
core-site.xmlhdfs-site.xmlhadoop-env.shxmllint --noout $HADOOP_HOME/etc/hadoop/core-site.xml
xmllint --noout $HADOOP_HOME/etc/hadoop/hdfs-site.xml
无输出表示语法 OK。
grep -A2 "fs.defaultFS" $HADOOP_HOME/etc/hadoop/core-site.xml
grep -A2 "dfs.replication" $HADOOP_HOME/etc/hadoop/hdfs-site.xml
hdfs namenode -format
⚠️ 不要重复执行,会清空元数据。
start-dfs.sh
jps
应至少看到:
hdfs dfsadmin -report
hdfs dfs -mkdir /test
hdfs dfs -ls /
echo "hello hdfs" > test.txt
hdfs dfs -put test.txt /test/
hdfs dfs -cat /test/test.txt
hdfs dfs -get /test/test.txt ./out.txt
在浏览器访问:
http://<namenode-ip>:9870
(Hadoop 3.x,老版本是 50070)
可看到:
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
或修改:
vi /etc/selinux/config
SELINUX=disabled
cat /etc/hosts
确保:
192.168.1.10 namenode
192.168.1.11 datanode1
ssh-keygen
ssh-copy-id localhost
✅ 配置文件语法正确
✅ jps 有 NameNode / DataNode
✅ hdfs dfs -ls / 正常
✅ Web 页面可访问
✅ 能 put / get 文件
如果你愿意,可以告诉我:
我可以直接帮你“对症测配置”。