hbase使用随记2

hbase安装过程中的错误解决:

在《hbase使用随机1》中描述了hbase安装的过程,下面是在安装过程中遇到的几个错误:

1、确认hadoop没有问题的情况下,启动hbase时出现了以下错误:

启动hbase后过了一段时间,出现以下错误HMaster: Shutting down HBase cluster: file system not available,导致整个hbase集群crash掉,google了一把,是这样回答的:

Let me also stress this point, no way can the namenode swap. The zookeeper
processes also require a highly responsive io channel (think dedicated or
non loaded disk).

 

If the regionservers start to swap you also risk serious problems.

 

You wouldn't force oracle or mysql to swap, so don't force hbase and hdfs to
swap!

 

You can't allow swapping.

 

按照上述的说法,是regionserver机器上swap导致的问题,于是我把所有regionserver的swap停掉(root用户,使用命令swapoff -a,使用该命令之前,用top命令查看swap是否在使用,否则可能会造成数据丢失,生产系统上慎用),启动hbase后问题果然得到解决!

 

2、按照《hbase使用随机1》中的描述进行了主机名与ip地址的映射(没有添加映射之前没有问题),结果在window上使用网页查看hadoop的时候,却出现了下面的问题:

访问hadoop地址:http://masterip:50070/dfshealth.jsp),其中的Browse the filesystem 是查看文件系统的入口,但是出现无法访问的问题,以下是查询到的解决办法:

通过firebug拦截请求发现,Browse the filesystem这个链接的页面会跳转到另外一个页面,而这个页面的地址是

http://testdb60(其中一台slave机器主机名):50075/browseDirectory.jsp?namenodeInfoPort=50070&dir=%2F

看看nn_browsedfscontent.jsp的源代码:

package org.apache.hadoop.hdfs.server.namenode;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URLEncoder;
import java.util.Vector;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspFactory;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.SkipPageException;
import org.apache.hadoop.util.ServletUtil;
import org.apache.jasper.runtime.HttpJspBase;
import org.apache.jasper.runtime.JspSourceDependent;
import org.apache.jasper.runtime.ResourceInjector;

public final class nn_005fbrowsedfscontent_jsp extends HttpJspBase
  implements JspSourceDependent
{
  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();
  private static Vector _jspx_dependants;
  private ResourceInjector _jspx_resourceInjector;

  //此处是将请求随机转发到一个DataNode节点上
  public void redirectToRandomDataNode(NameNode nn, HttpServletResponse resp)
    throws IOException
  {
    String nodeToRedirect;
    int redirectPort;
    FSNamesystem fsn = nn.getNamesystem();
    String datanode = fsn.randomDataNode();

    if (datanode != null) {
      redirectPort = Integer.parseInt(datanode.substring(datanode.indexOf(58) + 1));
      nodeToRedirect = datanode.substring(0, datanode.indexOf(58));
    }
    else {
      nodeToRedirect = nn.getHttpAddress().getHostName();
      redirectPort = nn.getHttpAddress().getPort();
    }
    // 此处是得到服务器的名称(hostname)
    String fqdn = InetAddress.getByName(nodeToRedirect).getCanonicalHostName();
    String redirectLocation = "http://" + fqdn + ":" + redirectPort + "/browseDirectory.jsp?namenodeInfoPort=" + nn.getHttpAddress().getPort() + "&dir=" + URLEncoder.encode("/", "UTF-8");

    resp.sendRedirect(redirectLocation);
  }

  public Object getDependants()
  {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
  {
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;
    try
    {
      response.setContentType("text/html; charset=UTF-8");
      pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true);

      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;
      this._jspx_resourceInjector = ((ResourceInjector)application.getAttribute("com.sun.appserv.jsp.resource.injector"));

      out.write(10);
      out.write("\n\n<html>\n\n<title></title>\n\n<body>\n");

      NameNode nn = (NameNode)application.getAttribute("name.node");
      redirectToRandomDataNode(nn, response);

      out.write("\n<hr>\n\n<h2>Local logs</h2>\n<a href=\"/logs/\">Log</a> directory\n\n");

      out.println(ServletUtil.htmlFooter());

      out.write(10);
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if ((out != null) && (out.getBufferSize() != 0))
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}

 

    从代码可以看出,当我们点击Browse the filesystem 时后台会将请求随机转发到一台DataNode节点,使用的是slaves文件中配置的服务器列表所反解的域名或主机名,而通过局域网IP未能反解出域名和主机名,所以用的是IP,这样就出问题了,解决办法有两个:视redirectToRandomDataNode方法内生成的URL而定,如果反转域名是主机名的话,你只需要修改本地HOSTS映射就可以了(推荐使用Windows Hosts Editor,软件地址:http://yymmiinngg.iteye.com/blog/360779);如果反转出的域名是主机局域网IP的话,那就需要配置slaves和masters使用域名或外网IP。

 

根据以上解决办法,修改了windows的hosts(c:\windows\system32\driver\etc\hosts)文件,将hadoop集群中的主机名和ip地址映射添加上就可以了,当然如果是有dns服务器的话,就没这么麻烦了。

你可能感兴趣的:(hbase)