1. 程式人生 > >hmaster和hregionserver 16020 埠衝突問題

hmaster和hregionserver 16020 埠衝突問題

問題背景:
最近升級了下hadoop、 hbase、 spark,發現hbase升級後主節點上的hregionsever老是啟動不了。
檢視日誌發現如下埠衝突錯誤:

java.lang.RuntimeException: Failed construction of Regionserver: class org.apache.hadoop.hbase.regionserver.HRegionServer
    at org.apache.hadoop.hbase.regionserver.HRegionServer.constructRegionServer(HRegionServer.java
:2487) at org.apache.hadoop.hbase.regionserver.HRegionServerCommandLine.start(HRegionServerCommandLine.java:64) at org.apache.hadoop.hbase.regionserver.HRegionServerCommandLine.run(HRegionServerCommandLine.java:87) at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70) at org.apache
.hadoop.hbase.util.ServerCommandLine.doMain(ServerCommandLine.java:126) at org.apache.hadoop.hbase.regionserver.HRegionServer.main(HRegionServer.java:2502) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect
.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at org.apache.hadoop.hbase.regionserver.HRegionServer.constructRegionServer(HRegionServer.java:2485) ... 5 more Caused by: java.net.BindException: Problem binding to hadoop1/192.168.1.201:16020 : 地址已在使用 at org.apache.hadoop.hbase.ipc.RpcServer.bind(RpcServer.java:2371) at org.apache.hadoop.hbase.ipc.RpcServer$Listener.<init>(RpcServer.java:524) at org.apache.hadoop.hbase.ipc.RpcServer.<init>(RpcServer.java:1899) at org.apache.hadoop.hbase.regionserver.RSRpcServices.<init>(RSRpcServices.java:790) at org.apache.hadoop.hbase.regionserver.HRegionServer.createRpcServices(HRegionServer.java:575) at org.apache.hadoop.hbase.regionserver.HRegionServer.<init>(HRegionServer.java:492) ... 10 more Caused by: java.net.BindException: 地址已在使用 at sun.nio.ch.Net.bind0(Native Method) at sun.nio.ch.Net.bind(Net.java:444) at sun.nio.ch.Net.bind(Net.java:436) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) at org.apache.hadoop.hbase.ipc.RpcServer.bind(RpcServer.java:2369)

經過仔細檢視官方文件,問題解決。特記錄一下。

環境:
hadoop版本 : 2.5.1
hbase 版本 : 1.0.0
spark 版本: 1.3.0
其中hbase主節點上也同時啟動了hregionserver服務。

問題原因:
在hbase升級到1.0.0版本後,預設埠做了改動。其中16020埠是hmaster服務和hregionserver服務各自使用的預設埠,導致埠衝突。

官方文件相關資訊如下
The HMaster server controls the HBase cluster. You can start up to 9 backup HMaster servers, which makes 10 total HMasters, counting the primary. To start a backup HMaster, use the local-master-backup.sh. For each backup master you want to start, add a parameter representing the port offset for that master. Each HMaster uses three ports (16010, 16020, and 16030 by default). The port offset is added to these ports, so using an offset of 2, the backup HMaster would use ports 16012, 16022, and 16032. The following command starts 3 backup servers using ports 16012/16022/16032, 16013/16023/16033, and 16015/16025/16035.

The HRegionServer manages the data in its StoreFiles as directed by the HMaster. Generally, one HRegionServer runs per node in the cluster. Running multiple HRegionServers on the same system can be useful for testing in pseudo-distributed mode. The local-regionservers.sh command allows you to run multiple RegionServers. It works in a similar way to the local-master-backup.sh command, in that each parameter you provide represents the port offset for an instance. Each RegionServer requires two ports, and the default ports are 16020 and 16030. However, the base ports for additional RegionServers are not the default ports since the default ports are used by the HMaster, which is also a RegionServer since HBase version 1.0.0. The base ports are 16200 and 16300 instead. You can run 99 additional RegionServers that are not a HMaster or backup HMaster, on a server. The following command starts four additional RegionServers, running on sequential ports starting at 16202/16302 (base ports 16200/16300 plus 2).

解決方法:
按理說不使用預設配置,定義自己的埠配置就可以解決該問題。
比如使用如下配置:

<property>
<name>hbase.master.port</name>
<value>16000</value>
</property>

<property>
<name>hbase.master.info.port</name>
<value>16010</value>
</property>

<property>
<name>hbase.regionserver.port</name>
<value>16201</value>
</property>

<property>
<name>hbase.regionserver.info.port</name>
<value>16301</value>
</property>
</configuration>

但是實際上 使用start-hbase.sh 指令碼啟動regionserver還是會報埠衝突問題,可能通過這個指令碼啟動程式存在問題。沒有深究看原始碼。
該問題可以通過 使用單獨的regionserver啟動指令碼程式啟動regionserver來規避。
使用方法:

bin/local-regionservers.sh start 1

它使用的埠實際上就是
16201和16301