private static Configuration configureHBaseCluster ( Configuration config , int zkClientPort , FileSystem hdfsFs , String bindIP , int masterPort , int regionserverPort ) throws IOException { // Configure the zookeeper port config . set ( HConstants . ZOOKEEPER_CLIENT_PORT , Integer . toString ( zkClientPort ) ) ; // Initialize HDFS path configurations required by HBase Path hbaseDir = new Path ( hdfsFs . makeQualified ( hdfsFs . getHomeDirectory ( ) ) , "hbase" ) ; FSUtils . setRootDir ( config , hbaseDir ) ; hdfsFs . mkdirs ( hbaseDir ) ; config . set ( "fs.defaultFS" , hdfsFs . getUri ( ) . toString ( ) ) ; config . set ( "fs.default.name" , hdfsFs . getUri ( ) . toString ( ) ) ; FSUtils . setVersion ( hdfsFs , hbaseDir ) ; // Configure the bind addresses and ports. If running in Openshift, we only // have permission to bind to the private IP address, accessible through an // environment variable. logger . info ( "HBase force binding to ip: " + bindIP ) ; config . set ( "hbase.master.ipc.address" , bindIP ) ; config . set ( HConstants . MASTER_PORT , Integer . toString ( masterPort ) ) ; config . set ( "hbase.regionserver.ipc.address" , bindIP ) ; config . set ( HConstants . REGIONSERVER_PORT , Integer . toString ( regionserverPort ) ) ; config . set ( HConstants . ZOOKEEPER_QUORUM , bindIP ) ; // By default, the HBase master and regionservers will report to zookeeper // that its hostname is what it determines by reverse DNS lookup, and not // what we use as the bind address. This means when we set the bind // address, daemons won't actually be able to connect to eachother if they // are different. Here, we do something that's illegal in 48 states - use // reflection to override a private static final field in the DNS class // that is a cachedHostname. This way, we are forcing the hostname that // reverse dns finds. This may not be compatible with newer versions of // Hadoop. try { Field cachedHostname = DNS . class . getDeclaredField ( "cachedHostname" ) ; cachedHostname . setAccessible ( true ) ; Field modifiersField = Field . class . getDeclaredField ( "modifiers" ) ; modifiersField . setAccessible ( true ) ; modifiersField . setInt ( cachedHostname , cachedHostname . getModifiers ( ) & ~ Modifier . FINAL ) ; cachedHostname . set ( null , bindIP ) ; } catch ( Exception e ) { // Reflection can throw so many checked exceptions. Let's wrap in an // IOException. throw new IOException ( e ) ; } // By setting the info ports to -1 for, we won't launch the master or // regionserver info web interfaces config . set ( HConstants . MASTER_INFO_PORT , "-1" ) ; config . set ( HConstants . REGIONSERVER_INFO_PORT , "-1" ) ; return config ; }
Configure the HBase cluster before launching it