windows7連線hbase建立表
windows7連線hbase建立表的程式碼如下:
package connectHbase;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
public class ConnectHbase {
private static Configuration config;
final private static String SOCKET_TIMEOUT = "ipc.socket.timeout";
final static int DEFAULT_SOCKET_TIMEOUT = 100000; // 100 seconds
public static Configuration getHBaseConfig() {
config = HBaseConfiguration.create();
config.set("hbase.zookeeper.quorum", "192.168.13.129");
config.set("hbase.rootdir", "hdfs://192.168.13.129:9000/hbase");
config.set("hbase.zookeeper.property.clientPort", "2181");
// config.set("hbase.master", "192.168.13.129:60010");
// config.set("hbase.zookeeper.quorum", "192.168.13.129");
// config.getInt(SOCKET_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);// 設定超時時間
System.setProperty("hadoop.home.dir",
"D:/linux/hadoop-2.6.4/hadoop-2.6.4");
return config;
}
public static HTable getTable(Connection conn, String tableName,
String familyName) {
HTable hTable = null;
try {
conn = ConnectionFactory.createConnection(getHBaseConfig());
System.out.println(conn);
HBaseAdmin hBaseAdmin = (HBaseAdmin) conn.getAdmin();
HTableDescriptor desc = new HTableDescriptor(
TableName.valueOf(tableName));
desc.addFamily(new HColumnDescriptor(familyName));
if (!hBaseAdmin.tableExists(tableName)) {
hBaseAdmin.createTable(desc);
}
hTable = (HTable) conn.getTable(TableName.valueOf(tableName));
System.out.println("獲取表成功");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return hTable;
}
public static void main(String[] args) {
Connection conn = null;
String tableName = "xiachenhong";
String familyname = "r";
HTable hTable = ConnectHbase.getTable(conn, tableName, familyname);
}
}
上面的ip地址為hbase所在的ip地址。
System.setProperty("hadoop.home.dir",
"D:/linux/hadoop-2.6.4/hadoop-2.6.4");
上面配置本地的hadoop,配置方法見本人windows連線hadoop學習。
執行上面的程式碼會出現以下錯誤:
Unable to read remote HBase tables from a local java Client due to a timeOut error. Seeing the following error:
java.io.IOException: org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=36, exceptions:
Wed Apr 20 10:32:43 WEST 2016, null, java.net.SocketTimeoutException: callTimeout=60000, callDuration=75181: row 'pentaho_mappings,,' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=localhost,16020,1461071963695, seqNum=0
at com.pentaho.big.data.bundles.impl.shim.hbase.table.HBaseTableImpl.exists(HBaseTableImpl.java:71)
at org.pentaho.big.data.kettle.plugins.hbase.mapping.MappingAdmin.getMappedTables(MappingAdmin.java:502)
at org.pentaho.big.data.kettle.plugins.hbase.output.HBaseOutputDialog.setupMappedTableNames(HBaseOutputDialog.java:818)
at org.pentaho.big.data.kettle.plugins.hbase.output.HBaseOutputDialog.access$900(HBaseOutputDialog.java:88)
at org.pentaho.big.data.kettle.plugins.hbase.output.HBaseOutputDialog$7.widgetSelected(HBaseOutputDialog.java:398)
at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at org.pentaho.big.data.kettle.plugins.hbase.output.HBaseOutputDialog.open(HBaseOutputDialog.java:603)
at org.pentaho.di.ui.spoon.delegates.SpoonStepsDelegate.editStep(SpoonStepsDelegate.java:125)
at org.pentaho.di.ui.spoon.Spoon.editStep(Spoon.java:8783)
at org.pentaho.di.ui.spoon.trans.TransGraph.editStep(TransGraph.java:3072)
at org.pentaho.di.ui.spoon.trans.TransGraph.mouseDoubleClick(TransGraph.java:755)
at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at org.pentaho.di.ui.spoon.Spoon.readAndDispatch(Spoon.java:1347)
at org.pentaho.di.ui.spoon.Spoon.waitForDispose(Spoon.java:7989)
at org.pentaho.di.ui.spoon.Spoon.start(Spoon.java:9269)
at org.pentaho.di.ui.spoon.Spoon.main(Spoon.java:662)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.pentaho.commons.launcher.Launcher.main(Launcher.java:92)
Caused by: org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=36, exceptions:
Wed Apr 20 10:32:43 WEST 2016, null, java.net.SocketTimeoutException: callTimeout=60000, callDuration=75181: row 'pentaho_mappings,,' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=localhost,16020,1461071963695, seqNum=0
at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.throwEnrichedException(RpcRetryingCallerWithReadReplicas.java:270)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:225)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:63)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:200)
at org.apache.hadoop.hbase.client.ClientScanner.call(ClientScanner.java:314)
at org.apache.hadoop.hbase.client.ClientScanner.nextScanner(ClientScanner.java:289)
at org.apache.hadoop.hbase.client.ClientScanner.initializeScannerInConstruction(ClientScanner.java:161)
at org.apache.hadoop.hbase.client.ClientScanner.<init>(ClientScanner.java:156)
at org.apache.hadoop.hbase.client.HTable.getScanner(HTable.java:888)
at org.apache.hadoop.hbase.MetaTableAccessor.fullScan(MetaTableAccessor.java:601)
at org.apache.hadoop.hbase.MetaTableAccessor.tableExists(MetaTableAccessor.java:365)
at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:310)
at org.pentaho.hadoop.hbase.factory.HBase10Admin.tableExists(HBase10Admin.java:41)
at org.pentaho.hbase.shim.common.CommonHBaseConnection.tableExists(CommonHBaseConnection.java:206)
at org.pentaho.hbase.shim.common.HBaseConnectionImpl.access$801(HBaseConnectionImpl.java:35)
at org.pentaho.hbase.shim.common.HBaseConnectionImpl$9.call(HBaseConnectionImpl.java:185)
at org.pentaho.hbase.shim.common.HBaseConnectionImpl$9.call(HBaseConnectionImpl.java:181)
at org.pentaho.hbase.shim.common.HBaseConnectionImpl.doWithContextClassLoader(HBaseConnectionImpl.java:76)
at org.pentaho.hbase.shim.common.HBaseConnectionImpl.tableExists(HBaseConnectionImpl.java:181)
at com.pentaho.big.data.bundles.impl.shim.hbase.HBaseConnectionWrapper.tableExists(HBaseConnectionWrapper.java:72)
at com.pentaho.big.data.bundles.impl.shim.hbase.table.HBaseTableImpl.exists(HBaseTableImpl.java:69)
... 28 more
Caused by: java.net.SocketTimeoutException: callTimeout=60000, callDuration=75181: row 'pentaho_mappings,,' on table 'hbase:meta' at region=hbase:meta,,1.1588230740, hostname=localhost,16020,1461071963695, seqNum=0
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:159)
at org.apache.hadoop.hbase.client.ResultBoundedCompletionService$QueueingFuture.run(ResultBoundedCompletionService.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: no further information
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
at org.apache.hadoop.net.SocketIOWithTimeout.connect(SocketIOWithTimeout.java:206)
at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:530)
at org.apache.hadoop.net.NetUtils.connect(NetUtils.java:494)
at org.apache.hadoop.hbase.ipc.RpcClientImpl$Connection.setupConnection(RpcClientImpl.java:404)
at org.apache.hadoop.hbase.ipc.RpcClientImpl$Connection.setupIOstreams(RpcClientImpl.java:710)
at org.apache.hadoop.hbase.ipc.RpcClientImpl$Connection.writeRequest(RpcClientImpl.java:890)
at org.apache.hadoop.hbase.ipc.RpcClientImpl$Connection.tracedWriteRequest(RpcClientImpl.java:859)
at org.apache.hadoop.hbase.ipc.RpcClientImpl.call(RpcClientImpl.java:1193)
at org.apache.hadoop.hbase.ipc.AbstractRpcClient.callBlockingMethod(AbstractRpcClient.java:216)
at org.apache.hadoop.hbase.ipc.AbstractRpcClient$BlockingRpcChannelImplementation.callBlockingMethod(AbstractRpcClient.java:300)
at org.apache.hadoop.hbase.protobuf.generated.ClientProtos$ClientService$BlockingStub.scan(ClientProtos.java:32651)
at org.apache.hadoop.hbase.client.ScannerCallable.openScanner(ScannerCallable.java:372)
at org.apache.hadoop.hbase.client.ScannerCallable.call(ScannerCallable.java:199)
at org.apache.hadoop.hbase.client.ScannerCallable.call(ScannerCallable.java:62)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:200)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas$RetryingRPC.call(ScannerCallableWithReplicas.java:371)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas$RetryingRPC.call(ScannerCallableWithReplicas.java:345)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:126)
... 4 more
出現上面的錯誤時,我們可以把windows下面的hosts和linux的hosts統一配置為
linux的ip地址和linux的主機名。接下來,我們要重啟linux才能讓修改生效。
重啟過後我們要啟動hadoop->zookeeper->hbase。然後計算執行程式。這個時候程式就執行成功了。
相關文章
- Hbase單機部署 java連線HbaseJava
- 連線zk 報錯連線不上hbase jdbcJDBC
- express入門04 資料庫連線 表結構建立 模型建立Express資料庫模型
- laravel建立軟連線Laravel
- 06 建立MySQL連線MySql
- ElasticSearch連線池建立Elasticsearch
- 【JDBC】使用OracleDataSource建立連線池用於連線OracleJDBCOracle
- zk 啟用kerberos後 hbase連線不上問題ROS
- 表連線型別型別
- SQLSERVER建立連線伺服器SQLServer伺服器
- centos無法建立ssl連線CentOS
- Hbase表設計
- win10如何建立寬頻連線_windows10建立寬頻連線的方法Win10Windows
- 如何正確管理HBase的連線,從原理到實戰
- 線性表——連結串列
- python中socket建立客戶連線Python
- 最多能建立多少個 TCP 連線?TCP
- java本地連線遠端Hbase可是返回zookeeper的地址是localhostJavalocalhost
- CDH+HBase Indexer+Solr為HBase資料建立二級索引IndexSolr索引
- 【譯】MySQL挑戰:建立10萬連線MySql
- Visual Studio和Git建立遠端連線Git
- 使用 jOOQ 連線兩個表
- 1112跨表連線查詢
- MySQL表連線及其優化MySql優化
- Windows7遠端連線提示身份驗證錯誤,要求的函式不支援。Windows函式
- OkHttp 原始碼剖析系列(六)——連線複用機制及連線的建立HTTP原始碼
- linux下mysql安裝、授權、建立使用者、連線navicat、連線entityLinuxMySql
- sql 連線查詢例項(left join)三表連線查詢SQL
- wget下載提示:無法建立SSL連線wget
- 通過驅動建立與MySQL的連線MySql
- TCP連線是如何建立和終止的?TCP
- HTTPS連線建立過程(單向&雙向)HTTP
- OkHttp 原始碼剖析系列(四)——連線建立概述HTTP原始碼
- websocket 建立連線時如何進行授權?Web
- 怎麼建立網站連線資料庫網站資料庫
- 建立 MQTT 連線時如何設定引數?MQQT
- raw.githubusercontent.com 無法建立 SSL 連線Github
- mORMot 1.18 第10章 連線表ORM
- PostgreSQL DBA(155) - Develop(“大表”連線)SQLdev