0
点赞
收藏
分享

微信扫一扫

通过源代码编译安装TDengine

​​TDengine​​​ 是新兴的时序数据库(Time Series Database),在之前的文章里面介绍了如果通过二进制包进行安装 ​​TDengine学习笔记-安装​​​,以及如何在Docker环境下部署 ​​一分钟在docker中运行TDengine​​。

本文主要介绍如果通过源代码编译安装。

​​TDengine​​​ 提供了非常详细的​​说明文档​​​,以下内容只是对官方文档的总结,和一些小技巧。
以下操作以CentOS 7.9 环境为例。

1.准备编译环境

1.1. 安装cmake3

sudo yum install epel-release
sudo yum update
sudo yum install -y gcc gcc-c++ make cmake3 git
sudo ln -sf /usr/bin/cmake3 /usr/bin/cmake
sudo yum install -y java-1.8.0-openjdk
sudo yum install -y maven

安装后确认

[root@test1 ]# cmake3 --version
cmake3 version 3.17.5

1.2.安装 TaosTools 依赖包

TaosTools 提供压力测试和备份工具,这个是一定要安装的,

sudo yum install zlib-devel xz-devel snappy-devel jansson jansson-devel pkgconfig libatomic libstdc++-static

1.3.设置 Go 环境

go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct

2.下载源代码

从 GitHub 上下载社区版代码,下载完成后,进入TDengine目录,下载子模块代码(包含TaosTools和taosAdapter等重要组件)。

git clone https://github.com/taosdata/TDengine.git
cd TDengine
git submodule update --init --recursive

感谢伟大的长城,我下载了2个多小时。

3.编译代码

cd TDengine
mkdir debug
cd debug
cmake .. -DBUILD_TOOLS=true -DBUILD_HTTP=false -DJEMALLOC_ENABLED=true
make

配置

说明

-DBUILD_TOOLS=true

安装TaosTools

-DBUILD_HTTP=false

安装taosAdapter

-DJEMALLOC_ENABLED=true

安装Jemalloc

TIPS:如果编译时遇到一些奇怪的错误,可以先架构以上配置去掉,只编译核心组件。等编写成功后,将配置加上,再编译一遍。

make完成后,检查/TDengine/debug/build/bin 路径,如果有jemalloc.sh,taosadapter,taosdump 说明上面这是的参数已经成功了。
通过源代码编译安装TDengine_github

4.Jemalloc

新版的TDengine采用了Jemalloc来管理内存。



jemalloc 是由 Jason Evans 在 FreeBSD 项目中引入的新一代内存分配器。
它是一个通用的 malloc 实现,侧重于减少内存碎片和提升高并发场景下内存的分配效率,其目标是能够替代 malloc。


Jemalloc 安装时有一个优化参数 background_thread:true

Enable/disable internal background worker threads. When set to true, background threads are created on demand (the number of background threads will be no more than the number of CPUs or active arenas). Threads run periodically, and handle purging asynchronously. When switching off, background threads are terminated synchronously. Note that after fork(2) function, the state in the child process will be disabled regardless the state in parent process. See stats.background_thread for related stats. opt.background_thread can be used to set the default option. This option is only available on selected pthread-based platforms.

总的来说,就是快速回收内存。如果想在编译TDengine时,就启用该功能,需要修改TDengine/deps/CMakeLists.txt文件
将以下内容:

CONFIGURE_COMMAND   ./autogen.sh COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/build/

修改为:

CONFIGURE_COMMAND   ./autogen.sh COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/build/  --with-malloc-conf=background_thread:true

通过源代码编译安装TDengine_git_02
从图片上看,内存被快速释放了。

5.测试验证

5.1. 启动taosd服务

直接在TDengine/debug/build/bin 路径下执行taosd

./taosd

输出 TDengine is initialized successfully 则表示启动成功。
通过源代码编译安装TDengine_centos_03

5.2. 写入测试数据

./taosBenchmark -d db01 -t 1000 -n 100000 -y

写入完成后,会显示写入速度和延时

[05/26 08:50:55.766454] INFO: Spent 92.9354 seconds to insert rows: 100000000, affected rows: 100000000 with 8 thread(s) into db01 1076016.35 records/second

[05/26 08:50:55.766487] INFO: insert delay, min: 17.21ms, avg: 179.93ms, p90: 278.37ms, p95: 312.38ms, p99: 397.17ms, max: 534.16ms

5.3. 查询数据

​​TDengine​​​ 相关命令可参考 ​​TDengine常用命令及SQL​​

./taos -s "select last_row(*) from db01.meters;"
Welcome to the TDengine shell from Linux, Client Version:2.4.0.18
Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.

taos> select last_row(*) from db01.meters;
ts | current | voltage | phase |
======================================================================================
2017-07-14 10:41:39.999 | 10.64347 | 219 | 0.33825 |
Query OK, 1 row(s) in set (0.003980s)


举报

相关推荐

0 条评论