在 CentOS 上测试 HDFS 配置通常分为几个层面:配置文件检查、服务启动、基本命令测试、Web 界面验证、日志排查。下面给你一套常用且实用的测试流程。
HDFS 核心配置文件一般在:
/etc/hadoop/
# 或
$HADOOP_HOME/etc/hadoop/
重点检查:
core-site.xmlhdfs-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>
⚠️ 只在首次部署执行
hdfs namenode -format
成功标志:
Storage directory ... has been successfully formatted
start-dfs.sh
或单独启动:
hadoop-daemon.sh start namenode
hadoop-daemon.sh start datanode
检查进程:
jps
应看到:
hdfs dfs -ls /
hdfs dfs -mkdir /test
echo "hello hdfs" > test.txt
hdfs dfs -put test.txt /test/
hdfs dfs -cat /test/test.txt
hdfs dfs -get /test/test.txt ./test2.txt
在浏览器访问(CentOS 服务器 IP):
http://<ip>:9870
(Hadoop 3.x) 或
http://<ip>:50070
(Hadoop 2.x)
可看到:
hdfs dfs -ls /
报错:Connection refused
检查:
netstat -tunlp | grep 9000
或
firewall-cmd --list-all
关闭防火墙测试:
systemctl stop firewalld
hdfs dfs -mkdir /test
报错:Permission denied
解决:
hdfs dfs -chmod -R 777 /
或修改 hdfs-site.xml:
<property>
<name>dfs.permissions.enabled</name>
<value>false</value>
</property>
telnet localhost 9000
或
curl http://localhost:9870
如果你愿意,可以告诉我:
我可以帮你精准定位配置问题。