Last active
October 15, 2017 20:22
-
-
Save salekseev/3c9d1c344f7bf25f94a4 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 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 <me@salekseev.com> | |
# | |
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