Updated on 2026-06-27 GMT+08:00

Configuring the HDFS Read-Only Mode

Scenario

You can enable the read-only mode for HDFS directories. After the read-only mode is enabled, the configured directories can only be read but cannot be written. Enabling the read-only mode during HDFS inventory data migration can greatly improve migration efficiency and prevent migration failures caused by write operations.

Notes and Constraints

  • This function applies to MRS 3.6.0 or later only.
  • The read-only mode needs to be enabled again after NameNode is restarted.
  • After using the read-only mode, exit the read-only mode immediately to prevent impact on services.

Prerequisites

  • The HDFS client has been installed..

    For example, the installation directory is /opt/client.

  • A human-machine user has been created and added to user group supergroup.

Procedure

  1. Log in to the node where the client is installed as the client installation user.
  2. Go to the client installation directory.

    cd /opt/client

  3. Configure environment variables.

    source bigdata_env

  4. Authenticate the user if the cluster is in security mode. Skip this step for a cluster in normal mode.

    kinit Component service user

  5. Enable the read-only mode.

    hdfs dfsadmin -readonly enable

    • Table 1 describes the parameters in the read-only mode command.
      Table 1 Parameters in the read-only mode command

      Parameter

      Description

      enable

      Enables the read-only mode.

      disable

      Disables the read-only mode.

      get

      Obtains the read-only mode status.

    • If the read-only mode is enabled for only one NameService, add the -fs parameter before the command. In the federation scenario, the -fs parameter is mandatory. For example:

      hdfs dfsadmin -fs hdfs://hacluster -readonly enable

  6. Log in to Manager, choose Cluster > Services > HDFS, click Configurations, and click All Configurations. On the displayed page, search for and set the following parameters as required.

    Table 2 Parameters related to the read-only mode

    Parameter

    Description

    Default Value

    hdfs.readonly-mode.directory.list

    Directories for which the read-only mode is enabled.

    • The configured directory can only be read and cannot be written.
    • Use commas (,) to separate multiple directories.
    • This parameter value does not support regular expressions.

    -

    hdfs.readonly-mode.white.list.user

    Users who are not restricted by the read-only mode after the read-only mode is enabled.

    • Use commas (,) to separate multiple users.
    • This parameter value does not support regular expressions.

    -

  7. Save the configuration. You do not need to restart the service or instance.