hadoop重启虚机后hdfs中数据丢失,需要重新格式化问题

本文介绍了Hadoop虚机重启后遇到的数据丢失问题,详细日志显示因存储目录不存在导致FSNamesystem初始化失败。为解决此问题,可以使用`hadoop namenode -format`进行格式化,但更持久的解决方案是修改core-site.xml和hdfs-site.xml配置文件,指定正确的DFS名称和数据目录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1,虚机每次重启后,如果不格式化namenode,就错误,日志如下:

INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Registered FSNamesystemStateMBean and NameNodeMXBean   INFO org.apache.hadoop.hdfs.server.namenode.NameNode: Caching file names occuring more than 10 times  INFO org.apache.hadoop.hdfs.server.common.Storage: Storage directory /tmp/hadoop-sylar/dfs/name does not exist. ERROR org.apache.hadoop.hdfs.server.namenode.FSNamesystem: FSNamesystem initialization failed. org.apache.hadoop.hdfs.server.common.InconsistentFSStateException: Directory /tmp/hadoop-sylar/dfs/name is in an inconsistent state: storage directory does not exist or is not accessible. 

2,解决方法,重新格式化:

~]$bin/hadoop namenode -format

3, 如果想彻底消除错误,并且每次重启机器不格式化,需要修改core-site.xml 和 hdfs-site.xml, 如下:

vm1:~/hadoop/conf$ cat core-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->

<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://192.168.1.105:9000</value>
</property>

<property>  
    <name>hadoop.tmp.dir</name>  
    <value>/home/hadoop/filesystem/tmp</value>  
    <description> temporary directories.</description>  
</property>  

<property>  
    <name>dfs.name.dir</name>  
    <value>/home/hadoop/filesystem/name</value>  
    <description>where on the local filesystem the DFS name node should store the name table</description>  
</property>  

<property>  
    <name>dfs.data.dir</name>  
    <value>/home/hadoop/filesystem/data</value>  
    <description>where on the local filesystem an DFS data node should store its blocks.</description>  
</property>  
   
</configuration>

vm1:~/hadoop/conf$

~/hadoop/conf$ cat hdfs-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->

<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
<name>dfs.permissions</name>
<value>false</value>
</property>
</configuration>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值