Hadoop启动报Connection refused错误,需重复格式化NameNode求助
I’ve run into this exact frustrating issue before—having to reformat the NameNode every time you start Hadoop gets old fast. Let’s break down the most common causes and step-by-step fixes:
1. Check Configuration Files For Persistent Storage Paths
The #1 reason this happens is that your NameNode is configured to store metadata in a temporary directory (like /tmp) which gets wiped when your system reboots. Here’s how to fix it:
- Open your
hdfs-site.xmlfile (usually in$HADOOP_HOME/etc/hadoop). - Look for the
dfs.namenode.name.dirproperty. If it points to a/tmppath, replace it with a persistent directory, e.g.:<property> <name>dfs.namenode.name.dir</name> <value>/opt/hadoop/data/namenode</value> </property> - Verify
core-site.xmlhas the correct NameNode address set:<property> <name>fs.defaultFS</name> <value>hdfs://localhost:9000</value> </property>
2. Create The Persistent Directory & Set Permissions
Once you’ve updated the config, create the directory and ensure Hadoop has access to it:
# Create the directory (match the path from hdfs-site.xml) mkdir -p /opt/hadoop/data/namenode # Change ownership to your Hadoop user (replace "hadoop" with your actual username) sudo chown -R hadoop:hadoop /opt/hadoop/data # Set proper read/write permissions chmod -R 755 /opt/hadoop/data
3. Format The NameNode One Final Time
After updating configs and setting up the directory, format the NameNode once—you shouldn’t need to do this again unless you intentionally reset HDFS:
hadoop namenode -format
4. Verify Services Start Correctly
Start Hadoop properly and check if all required daemons are running:
# Start HDFS and YARN services start-dfs.sh start-yarn.sh # List running Hadoop processes jps
You should see NameNode, DataNode, SecondaryNameNode, ResourceManager, and NodeManager listed. If any are missing, check their log files in $HADOOP_HOME/logs for specific errors.
5. Troubleshoot With Logs If Issues Persist
If you still get connection errors, dive into the NameNode log (e.g., hadoop-*-namenode-<your-hostname>.log in the logs folder). Search for keywords like Connection refused or Failed to load metadata—this will pinpoint exactly what’s going wrong.
内容的提问来源于stack exchange,提问作者Amol

