1、场景描述

有时候为了简单,尝尝在连接dolphinscheduler的时候,我们会使用单NameNode来进行资源中心地址的配置。当然dolphinscheduler是支持HA的

2、比如说保证NN2 Active

ensure_nn2_active.sh

#!/bin/bash

# Namenode identifiers
NN1="nn1"
NN2="nn2"

# Function to get the service state of a given namenode
get_service_state() {
    local nn=$1
    hdfs haadmin -getServiceState $nn
}

# Get the state of nn1 and nn2
NN1_STATE=$(get_service_state $NN1)
NN2_STATE=$(get_service_state $NN2)

echo "State of $NN1: $NN1_STATE"
echo "State of $NN2: $NN2_STATE"

# Ensure nn2 is active
if [ "$NN2_STATE" != "active" ]; then
    echo "$NN2 is not active. Attempting to make $NN2 active..."
    
    # Check if nn1 is active
    if [ "$NN1_STATE" == "active" ]; then
        echo "$NN1 is currently active. Trying to failover to $NN2..."
        hdfs haadmin -failover $NN1 $NN2
        
        # Recheck the state after failover attempt
        NN2_STATE=$(get_service_state $NN2)
        if [ "$NN2_STATE" == "active" ]; then
            echo "$NN2 is now active."
        else
            echo "Failed to make $NN2 active. Please check the system manually."
        fi
    else
        echo "$NN1 is not active. Attempting to directly make $NN2 active..."
        hdfs haadmin -transitionToActive $NN2
        
        # Recheck the state after transition attempt
        NN2_STATE=$(get_service_state $NN2)
        if [ "$NN2_STATE" == "active" ]; then
            echo "$NN2 is now active."
        else
            echo "Failed to make $NN2 active. Please check the system manually."
        fi
    fi
else
    echo "$NN2 is already active. No action needed."
fi

journey
32 声望20 粉丝

引用和评论

0 条评论