hbase+opentsdb 单机版搭建

  • 2019 年 10 月 5 日
  • 笔记

2018年2月19日星期一 Lee

这个实验步骤比较简单,只能用来演示下搭建过程,实际生产环境复杂的很多。

实验环境:

centos6.5 x86_64 IP: 10.0.20.25

这里实验没有用HDFS,生产环境的话,hbase还是要把数据存到hdfs上比较安全的。

1. 安装单机zookeeper

cd /root/ tar xf zookeeper-3.4.8.tar.gz -C ./ mv zookeeper-3.4.8 /opt/zk

cd /opt/zk cat conf/zoo.cfg 内容如下:

tickTime=2000  initLimit=10  syncLimit=5  dataDir=/tmp/zookeeper  clientPort=2181

/opt/zk/bin/zkServer.sh start /opt/zk1/zk1.cfg

/opt/zk/bin/zkCli.sh -server 10.0.20.25:2181

2. 安装单机hbase

tar xf hbase-1.2.6-bin.tar.gz –C /usr/local  cd /usr/local/  ln –s hbase-1.2.6 hbase  cd hbase  mkdir data   // 用来存放hbase的data数据【生产环境下,处于安全性考虑,hbase数据是存放到hdfs的】  cd conf

vim hbase-env.sh 最后追加3行:

export JAVA_HOME=/usr/java/jdk1.8.0_91  export PATH=${JAVA_HOME}/bin:$PATH  export HBASE_MANAGES_ZK=false

cat hbase-site.xml 添加红色部分的代码:

<?xml version="1.0"?>  <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>  <configuration>   <property>      <name>hbase.rootdir</name>      <value>/usr/local/hbase/data/</value>    </property>    <property>      <name>hbase.master.info.port</name>      <value>16001</value>  </property>     <property>      <name>hbase.cluster.distributed</name>      <value>true</value>  <!-- false是单机模式,true是分布式模式。若为false,Hbase和Zookeeper会运行在同一个JVM里面。-->    </property>      <property>      <name>hbase.zookeeper.quorum</name>      <value>localhost:2181</value>    </property>  </configuration>

更详细的可参看:https://www.cnblogs.com/yangsy0915/p/5544533.html

cat regionservers 内容如下: localhost 注意regionservers 里面写的内容和上面的hbase.zookeeper.quorum里面的hostname一样。

启动hbase:

cd /usr/local/hbase/bin  ./start-hbase.sh  即可启动hbase

验证:

ss –lnt | grep 16001 ps aux|grep hbase

补充,HDFS+hbase+3节点zk的 hbase-site.xml配置文件写法:

<configuration>   //设置将数据写入hdfs的目录    <property>      <name>hbase.rootdir</name>      <value>hdfs://master:9000/usr/local/hadoop-2.6.0/hbaseData</value>    </property>   //设置hbase模式为集群模式  <property>      <name>hbase.cluster.distributed</name>      <value>true</value>  </property>   //设置hbase的master端口地址  <property>    <name>hbase.master</name>    <value>hdfs://master:60000</value>  </property>  //HBase Master web界面绑定的端口,默认为0.0.0.0  <property>    <name>hbase.master.info.port</name>    <value>60010</value>  </property>  //连接zookeeper的端口设置      <property>          <name>hbase.zookeeper.property.clientPort</name>          <value>2183</value>      </property>    //设置zookeeper的连接地址(必须为基数个)   <property>             <name>hbase.zookeeper.quorum</name>             <value>master,slave1,slave2</value>     </property>  //Zookeeper的zoo.conf中的路径配置,快照的存储位置  <property>          <name>hbase.zookeeper.property.dataDir</name>          <value>/usr/local/zookeeper-3.4.6/data</value>  </property>  //Zookeeper连接超时时间  <property>    <name>zookeeper.session.timeout</name>    <value>60000</value>  </property>  </configuration>

3. 安装opentsdb

官方网站:http://opentsdb.net/docs/build/html/installation.html#id1

rpm –ivh opentsdb-2.3.0.rpm cd /etc/opentsdb vim opentsdb.conf 内容如下:

tsd.network.port = 4242  tsd.network.bind = 0.0.0.0  tsd.network.worker_threads = 8  tsd.http.staticroot = /usr/share/opentsdb/static/  tsd.http.cachedir = /tmp/opentsdb  tsd.core.auto_create_metrics = true  tsd.core.plugin_path = /usr/share/opentsdb/plugins  tsd.storage.hbase.zk_quorum = localhost:2181

启动之前,需要到hbase上面去创建表:

cd /usr/share/opentsdb/tools  env COMPRESSION=NONE HBASE_HOME=/usr/local/hbase ./create_table.sh

启动及验证: /etc/init.d/opentsdb start

ss -lnt | grep 4242 ps aux|grep opentsdb 访问浏览器的http://10.0.20.25:4242

4. 写数据测试

http api写数据方法:

官方文档:http://opentsdb.net/docs/build/html/api_http/put.html

可以使用chrome插件,如下方式post数据到opentsdb。【返回值204表示提交成功】

也可以使用tcollector来采集系统数据,并写入到opentsdb,方法如下:

git clone https://github.com/OpenTSDB/tcollector.git cd tcollector 如果不修改tcollector.py文件的话,默认采集程序会把采集的东西上送到localhost本地的opentsdb里面。【默认参数如下图】

./tcollector start // 即可在后台启动采集程序 ps aux | grep tcollector

如果需要采集mysql等其他软件的监控状态,需要去 collectors/etc/ 这个目录下的对应脚本里面,添加相关的账户名和密码,以便采集程序搜集信息。

然后,就可以到opentsdb的web界面去绘图了,下面是我采集了好几个小时的数据展示:

放到grfana里面,数据显示会更好看点。

配置大致这样的: