• 1
  • 2
  • 3
  • 4
  • 5
阿里云主机ECS 首 页  »  帮助中心  »  云服务器  »  阿里云主机ECS
Hbase/Hdfs如何删除节点
发布日期:2016-3-8 16:3:59

  Hbase/Hdfs如何删除节点

  线上有台服务器随时可能会挂掉,所以需要把在这个服务器上hbase的regionserver和hdfs的datanode节点移除。然后重新拿台新服务器部署接管。

  我先讲一下怎么添加一个hbase的regionserver,然后再讲怎么删除!,

  添加hbase regionserver节点

  添加步骤如下所示:

  1、首先在hbase master上修改regionservers文件,如下所示:

  # cd hbase_install_dir/conf

  # echo "new_hbase_node_hostname" >> ./regionservers

  2、如果你hbase集群使用自身zk集群的话,还需要修改hbase-site.xml文件,反之不用操作!

  # cd hbase_install_dir/conf

  # vim hbase-site.xml

  找到hbase.zookeeper.quorum属性 -->加入新节点

  3、同步以上修改的文件到hbase的各个节点上

  4、然后在新节点上启动hbase regionserver,如下所示:

  # cd hbase_install_dir/bin/

  # ./hbase-daemon.sh start regionserver

  5、然后在hbasemaster启动hbase shell

  用status命令确认一下集群情况

  hbase新增一个 regionserver节点补充完成了,下面介绍删除hbase和hdfs节点!

  集群上既部署有Hadoop,又部署有HBase,因为HBase存储是基于Hadoop HDFS的,所以先要移除HBase节点,之后再移除Hadoop节点。添加则反之。

  移除hbase regionserver节点

  1、首先在0.90.2之前,我们只能通过在要卸载的节点上执行;我的hbase版本(0.98.7)

  # cd hbase_install_dir

  # ./bin/hbase-daemon.sh stop regionserver

  来实现。这条语句执行后,该RegionServer首先关闭其负载的所有Region而后关闭自己。在关闭时,RegionServer在ZooKeeper中的"Ephemeral Node"会失效。此时,Master检测到RegionServer挂掉并把它作为一个宕机节点,并将该RegionServer上的Region重新分配到其他RegionServer。

  注意:使用此方法前,一定要关闭HBase Load Balancer。关闭方法:

  hbase(main):001:0> balance_switch false

  true

  0 row(s) in 0.3290 seconds

  总结:

  这种方法很大的一个缺点是该节点上的Region会离线很长时间。因为假如该RegionServer上有大量Region的话,因为Region的关闭是顺序执行的,第一个关闭的Region得等到和最后一个Region关闭并Assigned后一起上线。这是一个相当漫长的时间。以我这次的实验为例,现在一台RegionServer平均有1000个Region,每个Region Assigned需要4s,也就是说光Assigned就至少需要1个小时。

  2、自0.90.2之后,HBase添加了一个新的方法,即"graceful_stop",在你移除的服务器执行:

  # cd hbase_install_dir

  # ./bin/graceful_stop.sh hostname

  该命令会自动关闭Load Balancer,然后Assigned Region,之后会将该节点关闭。除此之外,你还可以查看remove的过程,已经assigned了多少个Region,还剩多少个Region,每个Region 的Assigned耗时。

  补充graceful stop的一些其他命令参数:

  # ./bin/graceful_stop.sh

  Usage: graceful_stop.sh [--config &conf-dir>] [--restart] [--reload] [--thrift] [--rest] &hostname>

  thrift If we should stop/start thrift before/after the hbase stop/start

  rest If we should stop/start rest before/after the hbase stop/start

  restart If we should restart after graceful stop

  reload Move offloaded regions back on to the stopped server

  debug Move offloaded regions back on to the stopped server

  hostname Hostname of server we are to stop

  最终都需要我们手动打开load balancer:

  hbase(main):001:0> balance_switch false

  true

  0 row(s) in 0.3590 seconds

  然后再开启:

  hbase(main):001:0> balance_switch true

  false

  0 row(s) in 0.3290 seconds

  对比两种方法,建议使用"graceful_stop"来移除hbase RegionServer节点。

  官网说明:http://hbase.apache.org/0.94/book/node.management.html​ http://hbase.apache.org/book.html#decommission​

  移除hdfs datanode节点

  1、首先在core-site.xml文件下新增如下内容

  dfs.hosts.exclude

  /hdfs_install_dir/conf/excludes

  2、然后创建exclude文件,把需要删除节点的主机名写入

  # cd hdfs_install_dir/conf

  # vim excludes

  添加需要删除的节点主机名,比如 hdnode1 保存退出

  3、 然后在namenode节点执行如下命令,强制让namenode重新读取配置文件,不需要重启集群。如下所示

  # cd hdfs_install_dir/bin/

  # ./hadoop dfsadmin -refreshNodes

  它会在后台进行Block块的移动

  4、 查看状态

  等待第三步的操作结束后,需要下架的机器就可以安全的关闭了。如下所示:

  # ./hadoop dfsadmin -report

  可以查看到现在集群上连接的节点

  正在执行Decommission,会显示:

  Decommission Status : Decommission in progress

  执行完毕后,会显示:

  Decommission Status : Decommissioned

  如下所示:

  Name: 10.0.180.6:50010

  Decommission Status : Decommission in progress

  Configured Capacity: 917033340928 (10.83 TB)

  DFS Used: 7693401063424 (7 TB)

  Non DFS Used: 118121652224 (110.00 GB)

  DFS Remaining: 4105510625280(3.63 TB)

  DFS Used%: 64.56%

  DFS Remaining%: 34.45%

  Last contact: Mon Nov 29 23:53:52 CST 2015

  也可以直接通过Hadoop 浏览器查看:

  LIVE的节点可以查看到:http://master_ip:50070/dfsnodelist.jsp?whatNodes=LIVE

  查看看到卸载的节点状态是:Decommission in progress

  等待节点完成移除后,浏览:http://master_ip:50070/dfsnodelist.jsp?whatNodes=DEAD 结果如下:

  

  完成后,删除的节点显示在dead nodes中。且其上的服务停止。Live Nodes中仅剩had2,had3

  以上即为从Hadoop集群中Remove Node的过程,但是,有一点一定要注意:

  hdfs-site.xml配置文件中dfs.replication值必须小于或者等于踢除节点后正常datanode的数量,即:

  dfs.replication <= 集群所剩节点数

  修改备份系数可以参考:http://heylinux.com/archives/2047.html

  重载入删除的datanode节点

  1、首先修改namenode的core-site.xml文件,把我们刚刚加入的内容删除或者注释掉,我这里选择注释掉。

  2、 然后再执行重载namenode的配置文件

  # ./bin/hadoop dfsadmin -refreshNodes

  3、最后去启动datanode上的datanode

  # ./bin/hadoop-daemon.sh start datanode

  starting datanode, logging to /usr/local/hadoop/bin/../logs/hadoop-root-datanode-had1.out

  4、查看启动情况

  # jps

  18653 Jps

  19687 DataNode ---->启动正常

  重新载入HBase RegionServer节点

  只需要重启regionserver进程就可以了。