问题描述
在编译安装 Nginx 时,执行 ./configure 命令遇到以下错误:
./configure: error: the Google perftools module requires the Google perftools library. You can either do not enable the module or install the library.
错误信息表明,配置脚本检测到您启用了 Google perftools 模块(例如 --with-google_perftools_module),但系统中缺少必需的 Google perftools 库(gperftools)。
解决方案
您有两个选择:
- 不启用该模块:在
./configure命令中移除--with-google_perftools_module参数。 - 安装必需的库:安装 Google perftools 开发库,然后重新配置编译 Nginx。这是本文推荐的解决方案。
安装 Google perftools 库
根据您的操作系统,使用对应的包管理器安装。
在 RHEL/CentOS/AlmaLinux/Rocky Linux 上
执行以下命令安装:
yum install gperftools gperftools-devel
说明:需要安装 gperftools-devel 包,它包含了编译所需的头文件和链接库。仅安装 gperftools 可能不足以解决编译错误。
在 Ubuntu/Debian 上
执行以下命令安装:
apt-get update
apt-get install google-perftools libgoogle-perftools-dev
后续步骤
安装完成必要的库之后,请重新运行 Nginx 的 ./configure 命令(包含您所需的所有参数),然后执行 make 和 make install 完成安装。
补充说明
- Google Perftools 模块的作用:此 Nginx 模块用于将内存分配绑定到特定的线程(TCMalloc),可能在高并发场景下提升性能。如果您的应用场景不需要,可以考虑在配置时禁用此模块以简化依赖。
- 版本兼容性:请确保安装的 gperftools 库版本与您正在编译的 Nginx 版本兼容。通常,使用系统包管理器安装的最新稳定版即可。
- 通用性:此解决方案不仅适用于 CentOS,也适用于其他使用
yum或dnf包管理器的 Linux 发行版。