下载目录
https://github.com/OpenTSDB/opentsdb/releases
https://github.com/OpenTSDB/opentsdb/releases/download/v2.4.0/opentsdb-2.4.0.noarch.rpm
安装 GnuPlot
yum install gnuplot -y
直接安装OpenTSDB会报错
[root@ecs-t-001-0001 openTSDB]# rpm -ivh opentsdb-2.4.0.noarch.rpm error: Failed dependencies: gnuplot is needed by opentsdb-2.4.0-1.noarch
安装OpenTSDB
[root@ecs opt]# rpm -ivh opentsdb-2.4.0.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:opentsdb-2.4.0-1 ################################# [100%]
默认配置目录
/etc/opentsdb - Configuration files
/tmp/opentsdb - Temporary cache files
/usr/share/opentsdb - Application files
/usr/share/opentsdb/bin - The "tsdb" startup script that launches a TSD or commandline tools
/usr/share/opentsdb/lib - Java JAR library files
/usr/share/opentsdb/plugins - Location for plugin files and dependencies
/usr/share/opentsdb/static - Static files for the GUI
/usr/share/opentsdb/tools - Scripts and other tools
/var/log/opentsdb - Logs
修改配置
进入目录 /usr/share/opentsdb/etc/opentsdb 修改配置文件 opentsdb.conf
> vim opentsdb.conf
tsd.storage.hbase.zk_quorum = zk:2181
tsd.network.port = 10080
tsd.http.staticroot = /usr/share/opentsdb/static/
tsd.http.cachedir = /tmp/opentsdb
tsd.core.plugin_path = /usr/share/opentsdb/plugins
初始化OpenTSDB表
进入目录/usr/share/opentsdb/tools,修改create_table.sh
我们加入的内容
HBASE_HOME=/opt/cloudera/parcels/CDH-6.3.2-1.cdh6.3.2.p0.1605554/lib/hbase
COMPRESSION=SNAPPY
全部内容
[root@ecs tools]# cat create_table.sh
#!/bin/sh
# Small script to setup the HBase tables used by OpenTSDB.
HBASE_HOME=/opt/cloudera/parcels/CDH-6.3.2-1.cdh6.3.2.p0.1605554/lib/hbase
COMPRESSION=SNAPPY
test -n "$HBASE_HOME" || {
echo >&2 'The environment variable HBASE_HOME must be set'
exit 1
}
test -d "$HBASE_HOME" || {
echo >&2 "No such directory: HBASE_HOME=$HBASE_HOME"
exit 1
}
TSDB_TABLE=${TSDB_TABLE-'tsdb'}
UID_TABLE=${UID_TABLE-'tsdb-uid'}
TREE_TABLE=${TREE_TABLE-'tsdb-tree'}
META_TABLE=${META_TABLE-'tsdb-meta'}
BLOOMFILTER=${BLOOMFILTER-'ROW'}
# LZO requires lzo2 64bit to be installed + the hadoop-gpl-compression jar.
COMPRESSION=${COMPRESSION-'LZO'}
# All compression codec names are upper case (NONE, LZO, SNAPPY, etc).
COMPRESSION=`echo "$COMPRESSION" | tr a-z A-Z`
# DIFF encoding is very useful for OpenTSDB's case that many small KVs and common prefix.
# This can save a lot of storage space.
DATA_BLOCK_ENCODING=${DATA_BLOCK_ENCODING-'DIFF'}
DATA_BLOCK_ENCODING=`echo "$DATA_BLOCK_ENCODING" | tr a-z A-Z`
TSDB_TTL=${TSDB_TTL-'FOREVER'}
case $COMPRESSION in
(NONE|LZO|GZIP|SNAPPY) :;; # Known good.
(*)
echo >&2 "warning: compression codec '$COMPRESSION' might not be supported."
;;
esac
case $DATA_BLOCK_ENCODING in
(NONE|PREFIX|DIFF|FAST_DIFF|ROW_INDEX_V1) :;; # Know good
(*)
echo >&2 "warning: encoding '$DATA_BLOCK_ENCODING' might not be supported."
;;
esac
# HBase scripts also use a variable named `HBASE_HOME', and having this
# variable in the environment with a value somewhat different from what
# they expect can confuse them in some cases. So rename the variable.
hbh=$HBASE_HOME
unset HBASE_HOME
exec "$hbh/bin/hbase" shell <<EOF
create '$UID_TABLE',
{NAME => 'id', COMPRESSION => '$COMPRESSION', BLOOMFILTER => '$BLOOMFILTER', DATA_BLOCK_ENCODING => '$DATA_BLOCK_ENCODING'},
{NAME => 'name', COMPRESSION => '$COMPRESSION', BLOOMFILTER => '$BLOOMFILTER', DATA_BLOCK_ENCODING => '$DATA_BLOCK_ENCODING'}
create '$TSDB_TABLE',
{NAME => 't', VERSIONS => 1, COMPRESSION => '$COMPRESSION', BLOOMFILTER => '$BLOOMFILTER', DATA_BLOCK_ENCODING => '$DATA_BLOCK_ENCODING', TTL => '$TSDB_TTL'}
create '$TREE_TABLE',
{NAME => 't', VERSIONS => 1, COMPRESSION => '$COMPRESSION', BLOOMFILTER => '$BLOOMFILTER', DATA_BLOCK_ENCODING => '$DATA_BLOCK_ENCODING'}
create '$META_TABLE',
{NAME => 'name', COMPRESSION => '$COMPRESSION', BLOOMFILTER => '$BLOOMFILTER', DATA_BLOCK_ENCODING => '$DATA_BLOCK_ENCODING'}
EOF
创建成功
[root@ecs tools]# sh create_table.sh
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
For Reference, please visit: http://hbase.apache.org/2.0/book.html#shell
Version 2.1.0-cdh6.3.2, rUnknown, Fri Nov 8 05:44:07 PST 2019
Took 0.0006 seconds
create 'tsdb-uid',
{NAME => 'id', COMPRESSION => 'SNAPPY', BLOOMFILTER => 'ROW', DATA_BLOCK_ENCODING => 'DIFF'},
{NAME => 'name', COMPRESSION => 'SNAPPY', BLOOMFILTER => 'ROW', DATA_BLOCK_ENCODING => 'DIFF'}
Created table tsdb-uid
Took 1.0398 seconds
Hbase::Table - tsdb-uid
create 'tsdb',
{NAME => 't', VERSIONS => 1, COMPRESSION => 'SNAPPY', BLOOMFILTER => 'ROW', DATA_BLOCK_ENCODING => 'DIFF', TTL => 'FOREVER'}
Created table tsdb
Took 0.7233 seconds
Hbase::Table - tsdb
create 'tsdb-tree',
{NAME => 't', VERSIONS => 1, COMPRESSION => 'SNAPPY', BLOOMFILTER => 'ROW', DATA_BLOCK_ENCODING => 'DIFF'}
Created table tsdb-tree
Took 0.7198 seconds
Hbase::Table - tsdb-tree
create 'tsdb-meta',
{NAME => 'name', COMPRESSION => 'SNAPPY', BLOOMFILTER => 'ROW', DATA_BLOCK_ENCODING => 'DIFF'}
Created table tsdb-meta
Took 0.7197 seconds
Hbase::Table - tsdb-meta
启动TSDB
nohup sh /usr/share/opentsdb/bin/tsdb tsd >tsdb-start.log &
访问页面
写入数据
上面如果没有设置 tsd.core.auto_create_metrics = true 参数时,需要手动创建 metric
tsdb mkmetric sys.cpu.user
否则会提示异常如下
[root@ecs-t-001-0002 ~]# telnet ip port
Escape character is '^]'.
put sys.cpu.user 1588302377 42.5 host=webserver01 cpu=0
put: unknown metric: No such name for 'metrics': 'sys.cpu.user'
加入两条数据,我们使用 telnet 方式添加数据,
put sys.cpu.user 1588292377 45.5 host=webserver01 cpu=0
put sys.cpu.user 1588302377 41.5 host=webserver01 cpu=0
再web页面我们简单查询看一下数据,右下角的一根线就是我们刚刚插入的两个点连成的线
这回我们插入四条数据,写入两个host
put sys.cpu.user 1588292377 45.5 host=webserver01 cpu=0
put sys.cpu.user 1588302377 41.5 host=webserver01 cpu=0
put sys.cpu.user 1588292377 12.5 host=webserver02 cpu=0
put sys.cpu.user 1588302377 80.5 host=webserver02 cpu=0
我们再指定tags查询看看效果,指定webserver02小时如下,结果是从12.5-80.5两个点没问题
看下webserver01,数据也没问题
至此,服务安装与初步使用介绍完成,下一步介绍下Api接口使用
标签:COMPRESSION,ENCODING,DATA,opentsdb,OpenTSDB,安装,tsdb,BLOCK From: https://blog.51cto.com/u_13721902/6249918