A single NameNode is a point of failure for an HDFS namespace. High availability with the Quorum Journal Manager (QJM) pairs an active NameNode with a standby that can take over using the same edit history.
The active NameNode commits edits to a majority of JournalNodes, while the standby follows those edits. Three JournalNodes on separate hosts tolerate one host failure. The standby also creates checkpoints, so an HA namespace does not use a Secondary NameNode.
Manual failover changes the active NameNode through hdfs haadmin; automatic failover additionally needs ZooKeeper and a ZKFC on each NameNode. A new, empty cluster needs matching Hadoop installations, working host resolution, and storage directories owned by its HDFS service account before its namespace is formatted. Existing namespaces need a migration plan that preserves their metadata.
Steps to configure HDFS high availability with QJM:
- Back up the active Hadoop configuration directory on each host.
$ cp -a "$HADOOP_CONF_DIR" "$HADOOP_CONF_DIR.before-ha"
For a tarball installation, $HADOOP_CONF_DIR commonly points to /opt/hadoop/etc/hadoop. Configuration edits and deployment use the installation administrator's account; daemon and HDFS commands use the dedicated hdfs account. The host names below must resolve from every cluster host and client.
Role Host names Local storage NameNodes nn1.example.net, nn2.example.net /data/hadoop/hdfs/name JournalNodes jn1.example.net, jn2.example.net, jn3.example.net /data/hadoop/hdfs/journal DataNodes Prepared worker hosts Configured DataNode storage directories - Set fs.defaultFS to the logical nameservice inside the existing configuration element in $HADOOP_CONF_DIR/core-site.xml using your text editor.
<property> <name>fs.defaultFS</name> <value>hdfs://cluster1</value> </property>
A property that already exists is replaced rather than duplicated. Other cluster and security settings remain in place.
- Add the nameservice identifiers and both NameNode addresses inside the configuration element in $HADOOP_CONF_DIR/hdfs-site.xml.
<property> <name>dfs.nameservices</name> <value>cluster1</value> </property> <property> <name>dfs.ha.namenodes.cluster1</name> <value>nn1,nn2</value> </property> <property> <name>dfs.namenode.rpc-address.cluster1.nn1</name> <value>nn1.example.net:8020</value> </property> <property> <name>dfs.namenode.rpc-address.cluster1.nn2</name> <value>nn2.example.net:8020</value> </property> <property> <name>dfs.namenode.http-address.cluster1.nn1</name> <value>nn1.example.net:9870</value> </property> <property> <name>dfs.namenode.http-address.cluster1.nn2</name> <value>nn2.example.net:9870</value> </property>
The HTTP addresses are also used to copy the namespace image when bootstrapping the standby. HTTPS deployments use the corresponding https-address properties and their existing HTTP security policy.
- Add the QJM storage paths and client failover provider to the same configuration element in hdfs-site.xml.
<property> <name>dfs.namenode.shared.edits.dir</name> <value>qjournal://jn1.example.net:8485;jn2.example.net:8485;jn3.example.net:8485/cluster1</value> </property> <property> <name>dfs.journalnode.edits.dir</name> <value>/data/hadoop/hdfs/journal</value> </property> <property> <name>dfs.namenode.name.dir</name> <value>file:///data/hadoop/hdfs/name</value> </property> <property> <name>dfs.client.failover.proxy.provider.cluster1</name> <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value> </property>
The JournalNode directory is local to each JournalNode host. The logical URI lets clients find whichever NameNode is active without changing their destination after failover.
- Add the fencing method to hdfs-site.xml.
<property> <name>dfs.ha.fencing.methods</name> <value>shell(nc -z -w 5 "$target_host" "$target_port",ssh -o BatchMode=yes -o ConnectTimeout=5 -i /home/hdfs/.ssh/id_ecdsa hdfs@"$source_host" "fuser -k -n tcp $source_port || ! nc -z -w 5 $source_host $source_port")</value> </property>
Fencing can kill a NameNode process. In Hadoop 3.5.0, the shell method accepts two comma-separated commands. The first checks the future active NameNode; the second stops the former active NameNode or confirms that its RPC port is already closed. The built-in sshfence method can kill both peers during manual forced fencing, so it is unsuitable for that path in this release.
This method requires nc on the administration host and both NameNodes, fuser on both NameNodes, and passwordless SSH as hdfs from every host that runs failover to both NameNodes. The key at /home/hdfs/.ssh/id_ecdsa must be a passphrase-free ECDSA key in PEM format, readable only by its owner, with both server host keys already trusted. The service account can stop its own processes without root privileges. A failed readiness check or SSH command prevents promotion; an unreachable host needs an independently verified fencing method before recovery can proceed.
- Distribute the saved configuration files to the active configuration directory on every NameNode, JournalNode, DataNode, and HDFS client.
The RPC and HTTP listeners must remain on trusted cluster networks. QJM provides metadata availability; it does not add authentication or encryption. Existing Kerberos and transport-security settings remain necessary for protected deployments.
- Start the JournalNode daemon as hdfs on each of the three JournalNode hosts.
$ hdfs --daemon start journalnode
- Format only the first NameNode of the new namespace on nn1.example.net.
Formatting an existing NameNode replaces namespace metadata and can make existing HDFS data inaccessible. Both NameNode storage directories and the journal must belong to this new cluster. Existing-cluster conversion uses metadata backups and -initializeSharedEdits instead of this fresh-format path.
$ hdfs namenode -format -clusterId hadoop-ha01
The fresh format initializes the shared journal as well as the first NameNode's local metadata. The .before-ha copies restore configuration only; they cannot restore formatted namespace metadata.
- Start the first NameNode on nn1.example.net.
$ hdfs --daemon start namenode
- Bootstrap the empty standby storage on nn2.example.net from the running first NameNode.
$ hdfs namenode -bootstrapStandby -nonInteractive
The command copies the namespace image and checks the shared edit history. It must finish successfully before the second NameNode starts.
- Start the standby NameNode on nn2.example.net.
$ hdfs --daemon start namenode
- Start the DataNode daemon on each prepared worker host.
$ hdfs --daemon start datanode
The worker's dfs.datanode.data.dir and replication policy retain their existing values. Both NameNodes receive its block reports.
- Activate nn1 for the first startup of this new namespace.
$ hdfs haadmin -transitionToActive nn1
Both newly started NameNodes begin in standby. Direct activation is only for this initial state with no existing active. Later changes use -failover, which first demotes or fences the old active.
- Check that nn1 is active and nn2 is standby.
$ hdfs haadmin -getAllServiceState nn1.example.net:8020 active nn2.example.net:8020 standby
- Upload a small file through the logical nameservice.
$ printf 'QJM failover works\n' | hdfs dfs -put - /ha-before.txt
The HDFS service account can write this root-level test file. The destination must not already exist. A SafeModeException means the NameNode is still waiting for sufficient block reports; writes remain blocked until safe mode clears.
- Fail over from nn1 to nn2.
$ hdfs haadmin -failover nn1 nn2 Failover from nn1 to nn2 successful
A responsive active NameNode is demoted to standby without killing it. If failover is refused, the reported cause needs resolution before another attempt; –forceactive is not a substitute for a healthy standby or working fencing.
- Confirm that the NameNodes have exchanged active and standby roles.
$ hdfs haadmin -getAllServiceState nn1.example.net:8020 standby nn2.example.net:8020 active
- Read the uploaded file through the same logical nameservice.
$ hdfs dfs -cat /ha-before.txt QJM failover works
The read returns the file uploaded before failover. It still uses hdfs://cluster1 from core-site.xml.