Hbase+opentsdb 单机版搭建

hbase+opentsdb 单机版搭建

安装环境:

OS:centos7.4 x86_64
IP: 192.168.1.100
  • 这里没有用HDFS,生产环境的话,hbase还是要把数据存到hdfs上比较安全的。

1. 安装单机zookeeper

mkdir /app/zk -pv
cd /app/zk
tar -xvf zookeeper-3.4.8.tar.gz
mv zookeeper-3.4.8/* . && rm -rf zookeeper-3.4.8
cp -rf conf/zoo_simpe.cfg conf/zoo.cfg
cat conf/zoo.cfg 
内容如下:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/app/testuser/zookeeper
clientPort=2181
  • 启动zookeeper
bin/zkServer.sh start conf/zoo.cfg
bin/zkCli.sh -server 192.168.1.100:2181 

2. 安装单机hbase

tar xf hbase-1.2.6-bin.tar.gz –C /app
cd /app
ln –s hbase-1.2.6 hbase
cd hbase
mkdir /app/testuser/hbase  // 用来存放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>16010</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 16010
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

下载安装包
cd /app
wget https://github.com/OpenTSDB/opentsdb/releases/download/v2.3.1/opentsdb-2.3.1.noarch.rpm
rpm -ivh opentsdb-2.3.1.noarch.rpm
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://192.168.1.100:4242
  • 访问如下图
    《Hbase+opentsdb 单机版搭建》 openTSDB.png

4. 写数据测试

http api写数据方法:

官方文档http://opentsdb.net/docs/build/html/api_http/put.html
可以使用chrome插件,如下方式post数据到opentsdb。【返回值204表示提交成功】

《Hbase+opentsdb 单机版搭建》 谷歌插件.png

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

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

《Hbase+opentsdb 单机版搭建》 image.png

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

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

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

《Hbase+opentsdb 单机版搭建》 image.png

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

《Hbase+opentsdb 单机版搭建》 image.png

配置大致这样的:

《Hbase+opentsdb 单机版搭建》 image.png

    原文作者:泡菜爱上WaSabi
    原文地址: https://www.jianshu.com/p/dd045a1a753f
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞