You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Hadoop回收站文件夹配置:如何设置/修改自定义路径?

Customizing Hadoop Trash Directory Path (HDFS or LFS)

Great question! Let's break down how to change Hadoop's default trash directory from the standard /user/<computer-name>/.Trash (on HDFS) to a custom path—either on HDFS or the local filesystem (LFS). Here's everything you need to know:

1. Modify to a Custom HDFS Path

Hadoop manages trash settings via the core-site.xml configuration file. To set a custom HDFS path:

  • Open your cluster's core-site.xml file (typically located in $HADOOP_HOME/etc/hadoop/).
  • Add or update the following configuration properties:
    <property>
      <name>fs.trash.root</name>
      <value>/custom/hadoop/trash/${user.name}</value>
      <description>Custom HDFS path for user-specific trash directories. ${user.name} ensures each user gets their own isolated subfolder.</description>
    </property>
    <!-- Optional: Adjust trash retention time (in minutes) if needed -->
    <property>
      <name>fs.trash.interval</name>
      <value>1440</value> <!-- 24 hours; default is 0 which disables trash -->
    </property>
    
  • Save the file and restart Hadoop's NameNode and DataNode services to apply changes:
    # Stop HDFS services
    $HADOOP_HOME/sbin/stop-dfs.sh
    # Restart HDFS services
    $HADOOP_HOME/sbin/start-dfs.sh
    
  • Critical Permissions Step: Create the parent HDFS directory and set proper permissions so all users can access their trash:
    hdfs dfs -mkdir -p /custom/hadoop/trash
    hdfs dfs -chmod 777 /custom/hadoop/trash
    

2. Modify to a Local Filesystem (LFS) Path

If you want the trash to live on the local filesystem (e.g., for Hadoop running in local mode), specify a local path with the file:// prefix:

  • Edit core-site.xml and update the fs.trash.root property:
    <property>
      <name>fs.trash.root</name>
      <value>file:///opt/hadoop/local-trash/${user.name}</value>
      <description>Local filesystem path for user-specific trash. The triple slash denotes an absolute local path.</description>
    </property>
    
  • Save the file and restart any running Hadoop services (like the local resource manager if using YARN).
  • Local Permissions Check: Create the parent local directory and set permissions for all users:
    sudo mkdir -p /opt/hadoop/local-trash
    sudo chmod 777 /opt/hadoop/local-trash
    

Quick Notes

  • For single-user overrides (not cluster-wide), a user can create a ~/.hadoop/core-site.xml file with the above properties—this will take precedence over the cluster's global config for that user.
  • Verify the change works by deleting a file with hdfs dfs -rm <hdfs-file-path> (for HDFS) or hadoop fs -rm <local-file-path> (for LFS), then checking your custom trash directory to confirm the file was moved there.

内容的提问来源于stack exchange,提问作者Anand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:03:56