Hadoop HA namenode 活動節點遷移

一. 官網關於 “活動節點遷移” 的介紹

haadmin

Usage:

hdfs haadmin -checkHealth
hdfs haadmin -failover [–forcefence] [–forceactive]
hdfs haadmin -getServiceState
hdfs haadmin -help
hdfs haadmin -transitionToActive [–forceactive]
hdfs haadmin -transitionToStandby

COMMAND_OPTION Description
-checkHealth check the health of the given NameNode
-failover initiate a failover between two NameNodes
-getServiceState determine whether the given NameNode is Active or Standby
-transitionToActive transition the state of the given NameNode to Active (Warning: No fencing is done)
-transitionToStandby transition the state of the given NameNode to Standby (Warning: No fencing is done)

二. 獲取 namenode 角色狀態

[root@server254-20-22-11 cloudera]# hdfs haadmin -getServiceState ‘namenode81’
active
[root@server254-20-22-11 cloudera]# hdfs haadmin -getServiceState ‘namenode61’
standby

三. namenode active節點角色切換

默認進行"活動節點遷移"時, 會因爲可能產生腦裂場景或其他不正確的狀態, 而導致操作被"拒絕"
CDH6上默認執行"hdfs haadmin"的角色爲yarn, 因爲默認cdh6構建的hdfs用戶是nologin用戶(cat /etc/passwd | grep hdfs), 如下:
hdfs:x:993:990:Hadoop HDFS:/var/lib/hadoop-hdfs:/sbin/nologin
故首先,需將當前hadoop默認用戶設置爲hdfs用戶,才能執行如下命令:

[root@server254-20-22-11 cloudera]# export HADOOP_USER_NAME=hdfs
[root@server254-20-22-11 cloudera]# hdfs haadmin -transitionToActive namenode61
Automatic failover is enabled for NameNode at server254-20-22-12/254.20.22.12:8022
Refusing to manually manage HA state, since it may cause
a split-brain scenario or other incorrect state.
If you are very sure you know what you are doing, please
specify the --forcemanual flag.

可以添加--forcemanual 來規避默認的拒絕策略.

[root@server254-20-22-11 cloudera]# export HADOOP_USER_NAME=hdfs
[root@server254-20-22-11 cloudera]# hdfs haadmin -ns nameservice1 -transitionToActive --forcemanual namenode61

[root@server254-20-22-11 cloudera]# hdfs haadmin -ns nameservice1 -transitionToActive --forcemanual namenode61

You have specified the --forcemanual flag. This flag is dangerous, as it can induce a split-brain scenario that WILL CORRUPT your HDFS namespace, possibly irrecoverably.

It is recommended not to use this flag, but instead to shut down the cluster and disable automatic failover if you prefer to manually manage your HA state.

You may abort safely by answering 'n' or hitting ^C now.

Are you sure you want to continue? (Y or N) Y
20/06/17 11:44:24 WARN ha.HAAdmin: Proceeding with manual HA state management even though
automatic failover is enabled for NameNode at server254-20-22-12/254.20.22.12:8022
transitionToActive: Node namenode81 is already active
Usage: haadmin [-ns <nameserviceId>] [-transitionToActive [--forceactive] <serviceId>]

說明:
可以看到, 實際執行下來後, 節點並未切換到 namenode61 節點(即 server254-20-22-11).
不知道社區版hadoop ha環境下執行這條語句是否可以達到目標, 有這樣環境的小夥伴可以把試驗結果分享一下.

[root@server254-20-22-11 cloudera]# hdfs haadmin -ns nameservice1 -transitionToActive --forcemanual namenode81

You have specified the --forcemanual flag. This flag is dangerous, as it can induce a split-brain scenario that WILL CORRUPT your HDFS namespace, possibly irrecoverably.

It is recommended not to use this flag, but instead to shut down the cluster and disable automatic failover if you prefer to manually manage your HA state.

You may abort safely by answering 'n' or hitting ^C now.

Are you sure you want to continue? (Y or N) Y
20/06/17 11:45:09 WARN ha.HAAdmin: Proceeding with manual HA state management even though
automatic failover is enabled for NameNode at server254-20-22-11/254.20.22.11:8022
20/06/17 11:45:09 WARN ha.HAAdmin: Proceeding with manual HA state management even though
automatic failover is enabled for NameNode at server254-20-22-12/254.20.22.12:8022

說明:
實際的active節點即爲 namenode81, 這條語句還是將active節點切換至 namenode81, 實際場景中, 這並沒有意義.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章