天天看點

hdfs haadmin使用,DataNode動态上下線,NameNode狀态切換管理,資料塊的balance,HA下hdfs-api變化(來自學習資料)

1.2.4叢集運維測試

ha叢集中兩個namenode狀态的管理指令

[root@mini2 hadoop-2.6.4]# bin/hdfs haadmin

usage: dfshaadmin [-ns <nameserviceid>]

    [-transitiontoactive <serviceid> [--forceactive]]

    [-transitiontostandby <serviceid>]

    [-failover [--forcefence] [--forceactive] <serviceid> <serviceid>]

    [-getservicestate <serviceid>]

    [-checkhealth <serviceid>]

    [-help <command>]

示例: 切換nn2為active

bin/hdfs haadmin -transitiontoactive nn2--forcemanual

datanode動态上下線很簡單,步驟如下:

a)   準備一台伺服器,設定好環境

b)   部署hadoop的安裝包,并同步叢集配置

c)   聯網上線,新datanode會自動加入叢集

d)   如果是一次增加大批datanode,還應該做叢集負載重均衡

(start-balancer.sh -threshold 8  ##指定磁盤使用率,詳情見下節 3)

使用的指令上hdfs  haadmin

可用 hdfs  haadmin –help檢視所有幫助資訊

hdfs haadmin使用,DataNode動态上下線,NameNode狀态切換管理,資料塊的balance,HA下hdfs-api變化(來自學習資料)

可以看到,狀态操作的指令示例:

檢視namenode工作狀态  

hdfs haadmin -getservicestate nn1

将standby狀态namenode切換到active

hdfs haadmin –transitiontoactive nn1

将active狀态namenode切換到standby

hdfs haadmin –transitiontostandby nn2

啟動balancer的指令:

start-balancer.sh -threshold 8

運作之後,會有balancer程序出現:

上述指令設定了threshold為8%,那麼執行balancer指令的時候,首先統計所有datanode的磁盤使用率的均值,然後判斷如果某一個datanode的磁盤使用率超過這個均值threshold,那麼将會把這個datanode的block轉移到磁盤使用率低的datanode,這對于新節點的加入來說十分有用。threshold的值為1到100之間,不顯示的進行參數設定的話,預設是10。

用戶端需要nameservice的配置資訊,其他不變

/**

 * 如果通路的是一個ha機制的叢集

 * 則一定要把core-site.xml和hdfs-site.xml配置檔案放在用戶端程式的classpath下

 * 以讓用戶端能夠了解hdfs://ns1/中  “ns1”是一個ha機制中的namenode對——nameservice

 * 以及知道ns1下具體的namenode通信位址

 * @author

 *

 */

public class uploadfile {

         public static void main(string[] args) throws exception  {

                  configuration conf = new configuration();

                  conf.set("fs.defaultfs", "hdfs://ns1/");

                  filesystem fs = filesystem.get(new uri("hdfs://ns1/"),conf,"hadoop");

                  fs.copyfromlocalfile(new path("g:/eclipse-jee-luna-sr1-linux-gtk.tar.gz"), new path("hdfs://ns1/"));

                  fs.close();

         }

}

繼續閱讀