-
-
Save robcowie/45748c5c788b6677348b23f8ad2a6a11 to your computer and use it in GitHub Desktop.
Script to check that both NameNodes are alive in HDFS HA configuration and will force failover to the preferred NameNode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# This script will check that both NameNodes are alive in HDFS HA | |
# configuration and will force failover to the preferred NameNode. | |
# | |
# Author: Stas Alekseev <[email protected]> | |
# | |
ACTIVE_NAMENODE=nn1 | |
STANDBY_NAMENODE=nn2 | |
if [ ${USER} != "hdfs" ]; then | |
echo "This script must be run as hdfs user." | |
exit 1 | |
fi | |
# Check that both NameNodes are alive | |
hdfs haadmin -checkHealth ${ACTIVE_NAMENODE} && hdfs haadmin -checkHealth ${STANDBY_NAMENODE} || { | |
printf '%s\n' 'ERROR: one of the namenodes is dead' | |
exit 1 | |
} | |
if [ $(hdfs haadmin -getServiceState ${ACTIVE_NAMENODE}) = "standby" ] | |
then | |
hdfs haadmin -failover ${STANDBY_NAMENODE} ${ACTIVE_NAMENODE} | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment