java连接hbase 卡死,Java 調用 hbase 啟動卡死狀態

ase/lib/velocity-1.7.jar:/appcom/hbase/lib/xmlenc-0.52.jar:/appcom/hbase/lib/zookeeper-3.4.5.jar

16/05/17 17:41:17 INFO zookeeper.ZooKeeper: Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

16/05/17 17:41:17 INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=/tmp

16/05/17 17:41:17 INFO zookeeper.ZooKeeper: Client environment:java.compiler=

16/05/17 17:41:17 INFO zookeeper.ZooKeeper: Client environment:os.name=Linux

16/05/17 17:41:17 INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64

16/05/17 17:41:17 INFO zookeeper.ZooKeeper: Client environment:os.version=2.6.32-431.el6.x86_64

16/05/17 17:41:17 INFO zookeeper.ZooKeeper: Client environment:user.name=root

16/05/17 17:41:17 INFO zookeeper.ZooKeeper: Client environment:user.home=/root

16/05/17 17:41:17 INFO zookeeper.ZooKeeper: Client environment:user.dir=/root/hbase-config

16/05/17 17:41:17 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=10.20.20.198:2181,10.20.20.139:2181,10.20.20.176:2181 sessionTimeout=180000 watcher=hconnection

16/05/17 17:41:17 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is 11283@SZB-L0019010

16/05/17 17:41:17 INFO zookeeper.ClientCnxn: Opening socket connection to server SZB-L0019009/10.20.20.139:2181. Will not attempt to authenticate using SASL (unknown error)

16/05/17 17:41:17 INFO zookeeper.ClientCnxn: Socket connection established to SZB-L0019009/10.20.20.139:2181, initiating session

16/05/17 17:41:17 INFO zookeeper.ClientCnxn: Session establishment complete on server SZB-L0019009/10.20.20.139:2181, sessionid = 0x254bd8dbd360002, negotiated timeout = 80000

附上Java代碼

package com.paic.mario.service.impl;

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;

import org.apache.hadoop.hbase.KeyValue;

import org.apache.hadoop.hbase.client.Get;

import org.apache.hadoop.hbase.client.HTable;

import org.apache.hadoop.hbase.client.Result;

import org.apache.hadoop.hbase.client.ResultScanner;

import org.apache.hadoop.hbase.client.Scan;

import org.apache.hadoop.hbase.util.Bytes;

public class  HbaseProbeJava{

// 聲明靜態配置

private static Configuration conf = null;

static {

conf = HBaseConfiguration.create();

}

@SuppressWarnings("resource")

// one data

public static String getOneRow(String tableName, String row) throws Exception {

String returnStr = "";

HTable table = new HTable(conf, tableName);

Get get = new Get(Bytes.toBytes(row));

Result result = table.get(get);

for (KeyValue rowKV : result.raw()) {

returnStr += "RowName:" + new String(rowKV.getRow()) +" ,";

returnStr += "Timestamp:" + rowKV.getTimestamp() +" ,";

returnStr += "FamilyName:" + new String(rowKV.getFamily()) +" ,";

returnStr += "ColomnName:" + new String(rowKV.getQualifier()) +" ,";

returnStr += "Value:" + new String(rowKV.getValue());

}

return returnStr;

}

//all data

@SuppressWarnings("resource")

public static String getAllRows(String tableName) throws Exception {

String returnStr = "";

HTable table = new HTable(conf, tableName);

Scan scan = new Scan();

ResultScanner results = table.getScanner(scan);

for (Result result : results) {

for (KeyValue rowKV : result.raw()) {

returnStr += "RowName:" + new String(rowKV.getRow()) +" ,";

returnStr += "Timestamp:" + rowKV.getTimestamp() +" ,";

returnStr += "FamilyName:" + new String(rowKV.getFamily()) +" ,";

returnStr += "ColomnName:" + new String(rowKV.getQualifier()) +" ,";

returnStr += "Value:" + new String(rowKV.getValue());

}

}

return returnStr;

}

// main

public static void main(String[] args) {

//String argpar = "10.20.20.176:2181==username==password==scores:ztx:xxxx"

String argpar = args[0];

String[] argarray = argpar.split("==");

String host_port = argarray[0];

String username = argarray[1];

String password = argarray[2];

String sqlstatement = argarray[3];

String[] host_portarray = host_port.split(":");

conf.set("hbase.zookeeper.quorum", host_portarray[0]);

conf.set("hbase.zookeeper.port", host_portarray[1]);

String[] sqlstatementarray = sqlstatement.split(":");

try {

String saveReturnStr = "";

if(sqlstatementarray.length == 1){

saveReturnStr = getAllRows(sqlstatementarray[0]);

}else if(sqlstatementarray.length == 2){

saveReturnStr = getOneRow(sqlstatementarray[0], sqlstatementarray[1]);

}

writeFile(saveReturnStr);

} catch (Exception e) {

writeFile("get data error.pls check java");

e.printStackTrace();

}

}

卡在這里不動的原因是   客戶端調用的jar  包與  hbase 的jar 版本 不一致導致的

附上shell腳本如下:

#!/bin/bash

cd /root/hbase-config

Channel=$1

BatchSize=80000

export CLASSPATH=$CLASSPATH:/appcom/hbase

for lib in `ls /appcom/hbase |grep jar`;do

CLASSPATH=$CLASSPATH:/appcom/hbase/$lib

done

for lib in `ls /appcom/hbase/lib |grep jar`;do

CLASSPATH=$CLASSPATH:/appcom/hbase/lib/$lib

done

export JAVA_HOME=/home/jdk1.7.0_79

export JAVA_CMD=$JAVA_HOME/bin/java

export JAVA_COP=$JAVA_HOME/bin/javac

export JAVA_MAIN=HbaseProbeJava

#EXEC_CMD="$JAVA_CMD -Xmx6000m -classpath $CLASSPATH $JAVA_MAIN $Channel"

$JAVA_COP HbaseProbeJava.java

echo $CLASSPATH

export PATH=$PATH.:/home/jdk1.7.0_79/bin

$JAVA_CMD -classpath $CLASSPATH $JAVA_MAIN

echo "11111"

其中 /appcom/hbase  是hbase jar 包目錄

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值