今天在一台测试机上使用yum命令安装包时,出现error: Failed to initialize NSS library错误,rpm命令也同样如此,但是系统还可以正常使用。
完整报错内容如下:
error: Failed to initialize NSS library There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: cannot import name ts Please install a package which provides this module, or verify that the module is installed correctly. It's possible that the above module doesn't match the current version of Python, which is: 2.7.5 (default, Aug 4 2022, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] If you cannot solve this problem yourself, please go to the yum faq at: http://yum.baseurl.org/wiki/Faq
|-------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | error: Failed to initialize NSS library There was a problem importing one of the Python modules required to run yum. The error leading to this problem was: cannot import name ts Please install a package which provides this module, or verify that the module is installed correctly. It's possible that the above module doesn't match the current version of Python, which is: 2.7.5 (default, Aug 4 2022, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] If you cannot solve this problem yourself, please go to the yum faq at: http://yum.baseurl.org/wiki/Faq |
发生这种情况的原因可能是仅升级了个别的nss-softokn-freebl包组,没有同时升级nss或nspr等,也有可能是rpm指定卸载了某个包组导致异常。
网上的方法无非是rpm2cpio提取库,但是如果你不知道是由于什么操作导致的,解决起来也会比较麻烦,所以rpm2cpio要提取多个软件包组,并不能指定一个。
包组可通过https://centos.pkgs.org/查找并下载到本地,进行提取
rpm2cpio nss-util-3.44.0-4.el7_7.x86_64.rpm | cpio -idmv yes | cp -R ./usr/lib64/* /usr/lib64/
|-----|---------------------------------------------------------------------------------------------------| | 1 2 | rpm2cpio nss-util-3.44.0-4.el7_7.x86_64.rpm | cpio -idmv yes | cp -R ./usr/lib64/* /usr/lib64/ |
此时再次执行rpm/yum命令,如果依旧报错,则继续提取相关库
rpm2cpio nss-softokn-freebl-3.44.0-8.el7_7.x86_64.rpm | cpio -idmv yes | cp -R ./usr/lib64/* /usr/lib64/ rpm2cpio nspr-4.21.0-1.el7.x86_64.rpm | cpio -idmv yes | cp -R ./usr/lib64/* /usr/lib64/
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 | rpm2cpio nss-softokn-freebl-3.44.0-8.el7_7.x86_64.rpm | cpio -idmv yes | cp -R ./usr/lib64/* /usr/lib64/ rpm2cpio nspr-4.21.0-1.el7.x86_64.rpm | cpio -idmv yes | cp -R ./usr/lib64/* /usr/lib64/ |
确保库已经成功覆盖至/usr/lib64/
如果到此,问题还是依旧,我建议你执行strace rpm,查看调用了哪些/lib64/下的库,然后进行提取覆盖
如果当然系统没有strace命令,可以通过rpm2cpio提取的方法,将bin文件提取出来,扔到系统bin目录下
思路就是如此,可以参考以上思路进行排查。
如果在cp覆盖的时候提示cannot access /lib64/libsoftokn3.so: No data available内容,建议通过rsync重新拷贝/lib64目录至/lib64.bak,将异常的文件过滤掉,然后将/lib64.bak与/lib64名称互换。