Redis 扩展模块 -- RedisTimeSeries 的安装方法

摘要

RedisTimeSeries 简介

  • RedisTimeSeries 是 Redis 官方提供的一个 时序数据模块(Time Series Module),用于高效地存储、查询和分析时间序列数据。它可以作为 Redis 的一个模块加载使用(在 Redis Stack 中内置支持),将时序数据建模、存储和聚合能力扩展到 Redis 之外。

  • 该模块以 Redis Module 方式加载,可无缝集成到现有 Redis 实例中。

  • Redis8+,RedisTimeSeries 已经内置在 Redis 中,可以在安装redis同时安装全部 Stack 模块。

安装 RedisTimeSeries

  • 虽然Redis CloudDownload Center中提供了所有Redis模块编译后的.so文件,但是并不保证一定兼容,所以最稳妥的方式是通过源码自己编译。

安装时需要科学上网,主要是安装依赖时需要从海外网下载,如果要部署在国内服务器,可能会连接失败。
可以在海外的相同配置的服务器上进行编译,之后将编译好的redistimeseries.so上传到国内服务器即可。

  • 安装依赖

1
2
3
4
5
6
7
8
9
10
sudo dnf install -y \
gcc \
gcc-c++ \
make \
cmake \
autoconf \
automake \
libtool \
pkgconfig \
openssl-devel
  • 编译 RedisTimeSeries

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
mkdir -p /usr/local/soft/modules/
cd /usr/local/soft/modules
# clone 代码,这里 --recursive 是为了拉取子模块
git clone --recursive https://github.com/RedisTimeSeries/RedisTimeSeries.git
cd RedisTimeSeries
# 推荐切换到稳定的release版本
git checkout v1.12.9
# 更新子模块,非必须,如果上面 clone 时没有加上 --recursive ,这个步骤就不能省略
git submodule update --init --recursive

# 检查并安装需要的依赖
./sbin/setup
## 输出
# readies version: af92230
dnf install -q -y ca-certificates
dnf install -q -y wget unzip
dnf install -q -y git jq
/usr/local/soft/modules/RedisTimeSeries/deps/readies/bin/enable-utf8
dnf install -q -y autoconf libtool m4 automake
dnf install -q -y openssl
dnf install -q -y which
/usr/local/soft/modules/RedisTimeSeries/deps/readies/bin/getepel
dnf install -q -y openssl-devel
/usr/local/soft/modules/RedisTimeSeries/deps/readies/bin/getgcc --modern
dnf install -q -y valgrind
/usr/bin/python3 /usr/local/soft/modules/RedisTimeSeries/deps/readies/bin/getcmake --usr
dnf install -q -y lcov
/usr/local/soft/modules/RedisTimeSeries/deps/readies/bin/getaws
/usr/bin/python3 /usr/local/soft/modules/RedisTimeSeries/deps/readies/bin/getrmpytools --reinstall --modern
/usr/bin/python3 -m pip install --disable-pip-version-check --user -r /usr/local/soft/modules/RedisTimeSeries/tests/flow/requirements.txt
NO_PY2=1 /usr/local/soft/modules/RedisTimeSeries/deps/readies/bin/getpudb
amazon_linux_2023


# 编译 RedisTimeSeries
make
# 编译过程未报错说明编译成功,编译后的文件位于 `bin/linux-x64-release/redistimeseries.so`

./sbin/setup 报错

  • 本人使用的是 Amazon Linux 2023(内核 6.1),即 EL9,类似于CentOS 9,第一次运行会报错,大致报错信息如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
./sbin/setup
## 错误信息
……
Status code: 403 for https://dyn.su/el9/base/x86_64/raven-release.el9.noarch.rpm (IP: 172.67.157.246)

In /usr/local/soft/modules/RedisTimeSeries/deps/readies/bin/getepel:
346 # xinstall --allowerasing https://dl.fedoraproject.org/pub/epel/epel-release-latest-${EPEL}.noarch.rpm
347 fi
348
349 >>> install_raven
350 install_remi
351 # install_centos_stream_repos
352

command failed: /usr/local/soft/modules/RedisTimeSeries/deps/readies/bin/getepel

In /usr/local/soft/modules/RedisTimeSeries/sbin/setup:
18 python3 -m pip list
19 fi
20
21 >>> $ROOT/sbin/system-setup.py $SETUP_ARGS
22 if [[ $VERBOSE == 1 ]]; then
23 python3 -m pip list
24 fi

Redis 启用模块

  • 将生成的 redistimeseries.so 拷贝到 redis 的 modules 目录下(非必须),目录不存在则创建

1
2
# 注意 .so 文件需要包含可执行权限
cp bin/linux-x64-release/redistimeseries.so /usr/local/soft/redis-7.4.7/modules/redistimeseries.so
  • 本文采用 loadmodule 加载模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 将 redistimeseries.so 添加到 redis.conf 中,需要重启 redis
loadmodule /usr/local/soft/redis-7.4.7/modules/redistimeseries.so

# 启动redis
redis-server redis.conf

# 登录测试
redis-cli --user admin --pass 123456
# 查看模块
127.0.0.1:6379> MODULE LIST
# 输出
1) 1) "name"
2) "timeseries"
3) "ver"
4) (integer) 11209
5) "path"
6) "/usr/local/soft/redis-7.4.7/modules/redistimeseries.so"
7) "args"
8) (empty array)
2) 1) "name"
2) "ReJSON"
3) "ver"
4) (integer) 20816
5) "path"
6) "/usr/local/soft/redis-7.4.7/modules/rejson.so"
7) "args"
8) (empty array)
3) 1) "name"
2) "bf"
3) "ver"
4) (integer) 20817
5) "path"
6) "/usr/local/soft/redis-7.4.7/modules/redisbloom.so"
7) "args"
8) (empty array)
4) 1) "name"
2) "search"
3) "ver"
4) (integer) 21025
5) "path"
6) "/usr/local/soft/redis-7.4.7/modules/redisearch.so"
7) "args"
8) (empty array)