Redis 启用自动内存碎片清理异常
Redis 启用自动内存碎片清理异常
127.0.0.1:6379> config set activedefrag yes
(error) DISABLED Active defragmentation cannot be enabled: it requires a Redis server compiled with a modified Jemalloc like the one shipped by default with the Redis source distribution
解决办法
-
从源代码编译 Redis 并使用修改后的 Jemalloc
1
- 获取 Redis 源代码:从 Redis 官方 GitHub 仓库或其他可靠来源下载 Redis 源代码。
- 确保安装依赖:安装编译 Redis 所需的工具和库,如 gcc、make 等。
- 配置并编译:进入 Redis 源代码目录,在 Makefile 中指定使用修改后的 Jemalloc。通常可以在编译时通过设置参数来指定,例如执行
make MALLOC=jemalloc
。 - 安装 Redis:编译完成后,执行
make install
将 Redis 安装到系统中。
-
替换动态链接的 Jemalloc 库
2
- 查找当前使用的 Jemalloc 库:使用命令
ldd redis-server
查看 Redis 服务器当前链接的 Jemalloc 库路径。 - 获取修改后的 Jemalloc 库:从 Redis 官方提供的资源或其他可靠渠道获取适合 Redis 主动碎片整理功能的修改版 Jemalloc 库。
- 替换库文件:备份原有的 Jemalloc 库文件,将修改后的 Jemalloc 库文件复制到相应路径,确保文件名和原库文件名一致。
- 设置库搜索路径:如果需要,更新
LD_LIBRARY_PATH
环境变量,确保系统能够找到新的 Jemalloc 库。
- 查找当前使用的 Jemalloc 库:使用命令