openTSDB+HBase+ZK遇到的坑汇总

来源:互联网 发布:西科软件 知乎 编辑:程序博客网 时间:2024/06/05 03:54

1.zookeeper返回的hbase地址是hostname,外网如何访问?

如果需要直接访问zk获取hbase地址进而访问,目前需要本机配置host
ip hostname
如果是要长期解决方法,那么只能通过搭建个Nginx来转发

2.Hbase本地Java测试写数据失败,端口访问不到

答:
这个是因为搭建的单机版本,然后regionServer配置的hostname,
在启动的时候会绑定端口hostname:16201(见/bin/local-regionservers.sh),
然后解析ubuntu的时候绑定的是127.0.0.1:16201,
所以外面访问不到.
解决:
修改hbase所在机器的host

127.0.0.1  myhostname改为10.0.0.1   myhostname

集群模式也一样,即/etc/hosts里面配置的hostname要指向本机ip
使用命令hostname查看本机hostname
http://blog.csdn.net/chaijunkun/article/details/44238163
ps:
(其实搭建hbase时候本应就指定好/etc/hosts里面的hostname对应具体ip,由于本人第一次搭建因此没注意所以踩了这个坑)


3.TSDB使用rest接口写数据OK,但是使用client写入不进数据?

现象:metric创建成功,但是没有数据
代码如下:

package net.opentsdb.core;import com.stumbleupon.async.Callback;import com.stumbleupon.async.Deferred;import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite;import net.opentsdb.utils.Config;import org.hbase.async.HBaseClient;import java.io.IOException;import java.util.HashMap;import java.util.Map;/** * Created by hai on 16/12/22. */public class TSDBExtTest  extends TestCase{    private TSDBExt tsdbExt;    /**     * Create the test case     *     * @param testName name of the test case     */    public TSDBExtTest(String testName )    {        super( testName );    }    /**     * @return the suite of tests being tested     */    public static Test suite()    {        return new TestSuite( TSDBExtTest.class );    }    public void setUp() throws IOException {        String zkquorum = System.getenv("HBASE_ZK");        String zkpath = System.getenv("HBASE_ZK_PATH");        if (null == zkpath) {            zkpath = "/hbase";        }        HBaseClient hbaseClient = new HBaseClient(zkquorum, zkpath);        Config opentsdbConfig = new Config(false);        opentsdbConfig.overrideConfig("tsd.storage.hbase.data_table", "tsdb");        opentsdbConfig.overrideConfig("tsd.storage.hbase.uid_table", "tsdb-uid");        opentsdbConfig.overrideConfig("tsd.core.auto_create_metrics", "true");        opentsdbConfig.overrideConfig("tsd.storage.enable_compaction", "false");        TSDB tsdb = new TSDB(hbaseClient, opentsdbConfig);        tsdbExt = new TSDBExt(tsdb, hbaseClient);    }    public void tearDown() {        tsdbExt.shutdown();    }    /**     * Rigourous Test :-)     */    public void testAtomicIncrementPointBy()    {        long ts = System.currentTimeMillis();        long v1 = 3;        Map<String, String> tags = new HashMap<>();        tags.put("tagk1", "tagv1");        tags.put("tagk2", "tagv2");        Deferred<Long> result = tsdbExt.atomicIncrementPointBy("test.ut10", ts, v1, tags);        result.addCallback(new Callback<Object, Long>() {            @Override            public Object call(Long aLong) throws Exception {                System.out.println("success result: " + aLong);                return null;            }        });        result.addErrback(new Callback<Object, Object>() {            @Override            public Object call(Object o) throws Exception {                System.out.println("error result: " + o);                return null;            }        });        assertTrue( true );        //Thread.sleep(100000);//bug解决    }}

查询openTSDB结果如下:
这里写图片描述

  • 第一次尝试
    看源码,第一次猜测是因为调用sendRPC()有buffer,并且默认flushInternal是1,因此请求被缓存到本地,然后等到缓存满了才发到服务端.
    于是设置:
hbaseClient.setFlushInterval((short)0);hbaseClient.setIncrementBufferSize(100);

然后重新run,发现依旧没有数据。

  • 第二次尝试
    直接debug,一行行的走,此时发现一个非常奇怪的问题,即debug的时候发现数据写入成功了!但是不debug就失败。仔细一想,这玩意是个rpcCallBack,然后debug和不debug不同的只是我的主线程结束时间。
    于是在代码最后加了句sleep(100000);搞定。

(貌似和buffer没关系?那网上说为了提高效率,把buffer设大有什么用?
第二个就是代码里面明明是buffer了,为什么还是一次写入了.代码还没细看,之后慢慢研究)

至此,问题解决.

0 0