RHEL9下dnf安装nginx-module-otel报错:找不到libcares.so.2
问题描述
在RHEL9系统(UBI9容器环境)中安装nginx-module-otel时,因系统无法提供libcares.so.2()(64bit)依赖而失败,具体报错如下:
[root@6c96e0f290a0 c-ares-1.34.4]# dnf install nginx-module-otel Updating Subscription Management repositories. Unable to read consumer identity Subscription Manager is operating in container mode. This system is not registered with an entitlement server. You can use subscription-manager to register. nginx stable repo 56 kB/s | 41 kB 00:00 Error: Problem: cannot install the best candidate for the job - nothing provides libcares.so.2()(64bit) needed by nginx-module-otel-1:1.26.2+0.1.0-1.el9.ngx.x86_64 (try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
已通过源码编译安装c-ares并更新了库缓存,但DNF依然无法识别该共享库。调试信息显示库文件已存在,以下是完整复现步骤及调试细节。
复现步骤
1. 启动UBI镜像
docker run -it --name ubi registry.access.redhat.com/ubi9/ubi:9.0.0-1703 /bin/bash
2. 容器内执行命令
# 安装开发工具 dnf install -y wget gcc gcc-c++ make # 从源码构建c-ares wget "https://github.com/c-ares/c-ares/releases/download/v1.34.4/c-ares-1.34.4.tar.gz" tar xzf c-ares-1.34.4.tar.gz cd c-ares-1.34.4 ./configure --prefix=/usr --libdir=/lib64 make make install ldconfig # [可选] 安装re2 dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm dnf config-manager --set-enabled epel /usr/bin/crb enable dnf install -y re2-devel # 创建nginx仓库文件 cat > /etc/yum.repos.d/nginx.repo << 'EOF' [nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/rhel/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true EOF # 导入nginx签名密钥 rpm --import https://nginx.org/keys/nginx_signing.key # 安装otel dnf install nginx-module-otel
调试信息
[root@6c96e0f290a0 c-ares-1.34.4]# ls -l /lib64/*ares* -rw-r--r-- 1 root root 2808910 Jan 20 08:49 /lib64/libcares.a -rwxr-xr-x 1 root root 959 Jan 20 08:49 /lib64/libcares.la lrwxrwxrwx 1 root root 18 Jan 20 08:49 /lib64/libcares.so -> libcares.so.2.19.3 lrwxrwxrwx 1 root root 18 Jan 20 08:49 /lib64/libcares.so.2 -> libcares.so.2.19.3 -rwxr-xr-x 1 root root 1179640 Jan 20 08:49 /lib64/libcares.so.2.19.3 [root@6c96e0f290a0 c-ares-1.34.4]# ls -l /usr/lib64/*ares* -rw-r--r-- 1 root root 2808910 Jan 20 08:49 /usr/lib64/libcares.a -rwxr-xr-x 1 root root 959 Jan 20 08:49 /usr/lib64/libcares.la lrwxrwxrwx 1 root root 18 Jan 20 08:49 /usr/lib64/libcares.so -> libcares.so.2.19.3 lrwxrwxrwx 1 root root 18 Jan 20 08:49 /usr/lib64/libcares.so.2 -> libcares.so.2.19.3 -rwxr-xr-x 1 root root 1179640 Jan 20 08:49 /usr/lib64/libcares.so.2.19.3 [root@6c96e0f290a0 c-ares-1.34.4]# ldconfig -p | grep ares libcares.so.2 (libc6,x86-64) => /lib64/libcares.so.2 libcares.so (libc6,x86-64) => /lib64/libcares.so [root@6c96e0f290a0 c-ares-1.34.4]# ldconfig -v | grep ares ldconfig: Can't stat /libx32: No such file or directory ldconfig: Path `/usr/lib' given more than once (from <builtin>:0 and <builtin>:0) ldconfig: Path `/usr/lib64' given more than once (from <builtin>:0 and <builtin>:0) ldconfig: Can't stat /usr/libx32: No such file or directory libcares.so.2 -> libcares.so.2.19.3
解决方案
DNF的依赖检查基于RPM包的元数据,手动编译安装的库不会被DNF识别为已提供的依赖,因此即使文件存在,依然会报错。以下是两种解决方法:
方法一:创建本地RPM包提供依赖(推荐)
- 安装rpm构建工具:
dnf install -y rpm-build
- 创建spec文件
~/rpmbuild/SPECS/libcares.spec:
Name: libcares Version: 1.34.4 Release: 1%{?dist} Summary: Asynchronous DNS resolver library License: MIT URL: https://c-ares.org/ %description Asynchronous DNS resolver library. %files /lib64/libcares.so.2 /lib64/libcares.so.2.19.3
- 构建RPM包:
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} rpmbuild -bb ~/rpmbuild/SPECS/libcares.spec
- 安装构建好的RPM包:
rpm -ivh ~/rpmbuild/RPMS/x86_64/libcares-1.34.4-1.el9.x86_64.rpm
完成后再执行dnf install nginx-module-otel即可成功安装。
方法二:强制跳过依赖检查(仅测试环境使用)
如果只是临时测试,可以直接用rpm强制安装,跳过依赖检查:
dnf download nginx-module-otel rpm -ivh --nodeps nginx-module-otel-*.rpm
这种方法可能导致运行时依赖缺失,生产环境禁止使用。
内容的提问来源于stack exchange,提问作者kaushal agrawal
相关产品推荐
相关产品推荐

