openTSDB的分布式集群的安装和使用

本文详细介绍如何在CentOS 7环境下搭建OpenTSDB集群,包括必要的前置软件安装如Hadoop、HBase及gnuplot,并通过示例展示如何利用Java客户端进行数据的写入与查询。

1  安装提前

            确保安装了jdk

            确保安装了hadoop集群

            确保安装了hbase的集群

    本次在centos7上测试成功

    192.168.100.200   master  (zk、namenode、resourcemanager、HMaster、TSDMain)  

    192.168.100.201   slave1    (zk、datanode、nodemanager、HRegionServer、TSDMain)

    192.168.100.202  slave2     (zk、datanode、nodemanager、HRegionServer、TSDMain)


   说明:TSDMain即openTSDB的进程,openTSDB本身没有分布式的实现方案,而是借助于HBase的分布式集群方案

               也就是说,master、slave1、slave2三个物理节点之上的openTSDB访问同一个HBase集群,返回相同的数据镜像


2 安装gnuplot

          Opentsdb运行需要gnuplot 插件

          [root@localhost local]# rpm -ivh gnuplot-common-4.6.2-3.el7.x86_64.rpm

          [root@localhost local]# rpm -ivh gnuplot-4.6.2-3.el7.x86_64.rpm    


3 验证gnuplot的安装以及png的安装成功

          [root@localhost bin]# gnuplot

          gnuplot> set terminal png


4 安装openTSDB

         在三个节点上操作相同

         [root@localhost local]# rpm –ivh opentsdb-2.3.0.rpm

         初始表

         [root@localhost opentsdb-2.3.0]# env COMPRESSION=NONE HBASE_HOME=/usr/local/hbase-1.3.0/ /usr/local/opentsdb/share/opentsdb/tools/create_table.sh

         修改配置文件

        [root@master home]# vi /etc/opentsdb/opentsdb.conf 

        tsd.core.auto_create_metrics = true

        tsd.storage.hbase.zk_quorum = master,slave1,slave2

        启动

        [root@localhost bin]# ./tsdb tsd  --config=/usr/local/opentsdb/share/opentsdb/etc/opentsdb/opentsdb.conf

        [root@master bin]# cd /usr/share/opentsdb/bin

        [root@master bin]# chmod +x tsdb

        [root@master bin]# ./tsdb tsd &

 

        http://192.168.100.200:4242/

        http://192.168.100.200:4242/

        http://192.168.100.200:4242/


5    基本使用


       opentsdb的java客户端采用github上的开源项目https://github.com/OpenTSDB/opentsdb

       在192.168.100.200节点存入数据

      

    @Test
    public void testPutData() {
        OpentsdbClient client = new OpentsdbClient("http://192.168.100.200:4242");
        try {
            Map<String, String> tagMap = new HashMap<String, String>();
            tagMap.put("host", "192.168.100.200");
 
            client.putData("anysense-alarm", DateUtils.String2Date("20160627 12:15", "yyyyMMdd HH:mm"), 210l, tagMap);
            
 
        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }

        在192.168.100.201、192.168.100.202节点查询

      

    @Test
    public void testGetData() {
    	OpentsdbClient client = new OpentsdbClient("http://192.168.100.202:4242");
        try {
            Filter filter = new Filter();
            filter.setType("regexp");
            filter.setTagk("host");
            filter.setFilter("192.168.100.200");
            filter.setGroupBy(Boolean.TRUE);
            String resContent = client.getData("anysense-alarm", filter, Aggregator.avg.name(), "1h",
                    "2016-06-27 12:00:00", "2016-06-30 13:00:00");
            System.out.println(resContent);
 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }







评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值