centos7 GLIBC版本升级


在安装大模型平台软件的时,要求GLIBC版本至少是2.27,说明系统中GLIBC版本过低,需要升级该GLIBC;

1 解决方法

1.1升级操作系统

直接安装Centos 8 系统或者升级Centos 7系统到Centos8 ,(升级之前需要备份重要数据)

1.2 前提配置环境

配置镜像环境,这一步很重要。

替换镜像

#
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-SCLo-scl-rh.repo.bak  CentOS-Sources.repo  CentOS-fasttrack.repo      docker-ce.repo     epel.repo
CentOS-CR.repo    CentOS-Media.repo      CentOS-SCLo-scl.repo         CentOS-Vault.repo    CentOS-x86_64-kernel.repo  epel-testing.repo

请将 /etc/yum.repos.d/CentOS-Base.repo 文件的内容替换为以下内容:

# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
[base]  
name=CentOS-$releasever - Base  
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS7   

[updates]  
name=CentOS-$releasever - Updates  
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS7   

[extras]  
name=CentOS-$releasever - Extras  
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS7
# 将文件的内容替换为上述内容。
vi /etc/yum.repos.d/CentOS-Base.repo

请将 /etc/yum.repos.d/CentOS-SCLo-scl.repo 文件的内容替换为以下内容:

# CentOS-SCLo-sclo.repo
#
# Please see http://wiki.centos.org/SpecialInterestGroup/SCLo for more
# information

[centos-sclo-rh]  
name=CentOS SCLo rh  
baseurl=https://mirrors.aliyun.com/centos/7.9.2009/sclo/x86_64/rh/  
enabled=1  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS7    

[centos-sclo-sclo]  
name=CentOS SCLo sclo  
baseurl=https://mirrors.aliyun.com/centos/7.9.2009/sclo/x86_64/sclo/  
enabled=1  
gpgcheck=1  
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS7
# 将文件的内容替换为上述内容。
vi /etc/yum.repos.d/CentOS-SCLo-scl.repo
# 打开文件
cp /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo.bak
rm -f /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo

# 命令来下载最新版本的 GPG 密钥
curl -o /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS7 https://repo.ius.io/RPM-GPG-KEY-IUS-7
# 确认 GPG 密钥文件的内容
cat /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS7
# 输出内容应该是类似于以下的 GPG 密钥信息,如果是 HTML 文件或者错误的内容,可能需要重新下载:
-----BEGIN PGP PUBLIC KEY BLOCK-----  
...  
-----END PGP PUBLIC KEY BLOCK-----

之后更新仓库配置

确保 /etc/yum.repos.d/CentOS-SCLo-scl.repo 和其他相关的 .repo 文件使用新的 GPG 密钥:

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS7

另外的密匙

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
vim /etc/yum.repos.d/CentOS-Base.repo

# 内容如下

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#
[base]  
name=CentOS-$releasever - Base  
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/  
gpgcheck=1  
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7   

[updates]  
name=CentOS-$releasever - Updates  
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/  
gpgcheck=1  
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7   

[extras]  
name=CentOS-$releasever - Extras  
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/  
gpgcheck=1  
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
vi /etc/yum.repos.d/CentOS-SCLo-scl.repo

# 内容如下

[centos-sclo-rh]
name=CentOS SCLo rh
baseurl=https://mirrors.aliyun.com/centos/7.9.2009/sclo/x86_64/rh/  
enabled=1  
gpgcheck=1  
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7    

[centos-sclo-sclo]  
name=CentOS SCLo sclo  
baseurl=https://mirrors.aliyun.com/centos/7.9.2009/sclo/x86_64/sclo/  
enabled=1  
gpgcheck=1  
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  1. 清理和更新缓存
    保存文件后,执行以下命令以清理缓存并生成新的缓存:

    yum clean all  
    yum makecache  
    
  2. 检查配置
    确认新配置是否生效:

    yum repolist  
    
  3. 重启包管理器

    在某些情况下,可能需要重启 Yum 或更新系统:

    yum update  
    
  4. 安装软件
    尝试安装之前提到的 devtoolset-8-gcc 等软件包。

安装必要环境:组件gcc 8.0 make 4.0 python 3.0 bison

安装gcc 8.0

gcc --version
# gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
# 前提升级一下

安装 Development Tools 组:

CentOS 7 提供了一个名为 "Development Tools" 的软件包组,其中包含了 GCC 编译器及相关工具。您可以通过以下命令安装:

sudo yum groupinstall "Development Tools"

wget https://mirrors.aliyun.com/epel/7/x86_64/Packages/e/epel-release-7-14.noarch.rpm
rpm -ivh epel-release-7-14.noarch.rpm 

sudo yum install glibc-devel

此命令将安装包括 gccg++make 在内的一系列开发工具。

[root@localhost Python-3.5.1]# gcc --version  
gcc (GCC) 8.3.1 20190311 (Red Hat 8.3.1-3)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

1.3 安装升级GLIBC_2.9

yum install -y centos-release-scl
yum install -y devtoolset-8-gcc*
# 如果上一步骤失败,使用这个yum install devtoolset-8-gcc-c++ --nogpgcheck

mv /usr/bin/gcc /usr/bin/gcc-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++-4.8.5
ln -s /opt/rh/devtoolset-8/root/bin/g++ /usr/bin/g++

1.4 安装make 4.0

wget http://ftp.gnu.org/gnu/make/make-4.3.tar.gz
tar -xzvf make-4.3.tar.gz 
cd make-4.3
./configure  --prefix=/usr/local/make
make && make install

cd /usr/bin/ && mv make make.bak
ln -sv /usr/local/make/bin/make /usr/bin/make

1.5 安装python 3.5

Centos 7系统默认带2.0的python ,有一些应用需要升级到3.0,我们这次升级到python 3.5

yum install gcc gcc-c++ libffi-devel openssl-devel python-setuptools vim wget make sqlite-devel zlib* -y  #安装python 常用环境依赖
 
 
wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz        
tar xzvf Python-3.5.1.tgz                                       
 
cd Python-3.5.1                       
 
./configure --with-ssl                               
make                                                                  
make install                                                        
ls -al /usr/bin | grep python    #查看当前python 版本
 
mv /usr/bin/python /usr/bin/python.bak    #python 的软链接重命名
 
ln -s /usr/local/bin/python3 /usr/bin/python    #将 python 链接至 python3

配置yum

升级 Python 之后,由于将默认的 python 指向了 python3,yum 不能正常使用

修改/usr/bin/yum #!/usr/bin/python 修改成python2.7

vim /usr/bin/yum

修改/usr/libexec/urlgrabber-ext-down #!/usr/bin/python 修改成python2.7

vim /usr/libexec/urlgrabber-ext-down

安装 bison

yum -y install bison

2 编译安装GLIBC

下载GLIBC安装包:

cd /home
# 下载挺慢的,提前下载比较好
wget http://ftp.gnu.org/gnu/glibc/glibc-2.29.tar.gz  
tar xzvf glibc-2.29.tar.gz 
cd glibc-2.29/ && mkdir build  && cd build
# 配置环境
 
../configure --prefix=/usr --disable-profile --enable-add-ons --enable-obsolete-nsl --with-headers=/usr/include --with-binutils=/usr/bin --disable-sanity-checks --disable-werror

make                 #编译
 
make install         #编译安装
LD_SO=ld-linux-x86-64.so.2 CC="gcc -B/usr/bin/" /data1/software/miniconda3/envs/R4.23/bin//perl scripts/test-installation.pl /data1/yjz/DS/glibc-2.29/build/
/usr/bin/ld: cannot find -lnss_test2
collect2: error: ld returned 1 exit status
Execution of gcc -B/usr/bin/ failed!
The script has found some problems with your installation!
Please read the FAQ and the README file and check the following:
- Did you change the gcc specs file (necessary after upgrading from
  Linux libc5)?
- Are there any symbolic links of the form libXXX.so to old libraries?
  Links like libm.so -> libm.so.5 (where libm.so.5 is an old library) are wrong,
  libm.so should point to the newly installed glibc file - and there should be
  only one such link (check e.g. /lib and /usr/lib)
You should restart this script from your build directory after you've
fixed all problems!
Btw. the script doesn't work if you're installing GNU libc not as your
primary library!
make[1]: *** [Makefile:111: install] Error 1
make[1]: Leaving directory '/data1/yjz/DS/glibc-2.29'
make: *** [Makefile:12: install] Error 2

在安装 GNU C 库(glibc)时遇到了错误,主要是由于缺少库文件 -lnss_test2,但是不影响,看下一步验证

通过运行以下命令来检查 glibc 是否正确安装:

ldconfig -p | grep libc
    libcap-ng.so.0 (libc6,x86-64) => /lib64/libcap-ng.so.0
    libc.so.6 (libc6,x86-64, OS ABI: Linux 3.2.0) => /lib64/libc.so.6

3 查看版本

ldd --version
# 输出:
ldd (GNU libc) 2.29
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容