centos7 升级glibc内核2.17到2.34

把自己实践过的记录整理下来,时间久了可能不一定很准确,还是应该当时刚做完就记录的,也不是没时间,还是太懒了,没养成随时记录笔记的好习惯。

[root@iZf8z4cfpxgbggro9k9blwZ ~]# ldd --version
ldd (GNU libc) 2.34
Copyright (C) 2021 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.
[root@iZf8z4cfpxgbggro9k9blwZ ~]# 

现在已经是升级成功之后的显示,之前2.17安装nodejs18的一个库总是报错,升级之后,也主要是为了使用高版本的nodejs

[root@iZf8z4cfpxgbggro9k9blwZ ~]# node --version
v22.14.0
[root@iZf8z4cfpxgbggro9k9blwZ ~]# npm -v
10.9.2

 接下来进入正式步骤,主要参考这2篇:

  1. 参考1
  2. 参考2
  • 下载新glibc2.34,并检查安装要求

先看个全览,新建了一个/opt文件夹,存放升级需要的文件包:

[root@iZf8z4cfpxgbggro9k9blwZ ~]# cd /opt
[root@iZf8z4cfpxgbggro9k9blwZ opt]# ls
containerd  gcc-9.3.0  gdb-7.8.2  glibc-2.34  make-4.3  node-v22.14  termcap-1.3.1
[root@iZf8z4cfpxgbggro9k9blwZ opt]# 

  1、下载glibc2.34

cd /opt
wget https://mirrors.aliyun.com/gnu/glibc/glibc-2.34.tar.gz
tar -zxvf glibc-2.34.tar.gz
//可以添加参数-C指定存放目录

  2、查看安装要求

cd glibc-2.34
cat INSTALL | grep -E  "later|newer"


* GNU 'make' 4.0 or newer
   * GCC 6.2 or newer
     building the GNU C Library, as newer compilers usually produce
     of release, this implies GCC 7.4 and newer (excepting GCC 7.5.0,
   * GNU 'binutils' 2.25 or later
     binutils 2.26 or newer.
   * GNU 'texinfo' 4.7 or later
   * GNU 'bison' 2.7 or later
   * GNU 'sed' 3.02 or newer
   * Python 3.4 or later
   * GDB 7.8 or later with support for Python 2.7/3.4 or later
   * GNU 'gettext' 0.10.36 or later
to have the header files from a 3.2 or newer kernel around for
reference.  (For the ia64 architecture, you need version 3.2.18 or newer

可以挨着检查一下自己的系统相关软件目前版本是否符合要求:如:

[root@iZf8z4cfpxgbggro9k9blwZ upglibc]# python --version
Python 2.7.5
[root@iZf8z4cfpxgbggro9k9blwZ upglibc]# python3 --version
Python 3.6.8
[root@iZf8z4cfpxgbggro9k9blwZ upglibc]# gcc --version
gcc (GCC) 9.3.0
Copyright © 2019 Free Software Foundation, Inc.

[root@iZf8z4cfpxgbggro9k9blwZ upglibc]# bison --version
bison (GNU Bison) 3.0.4
Written by Robert Corbett and Richard Stallman.

[root@iZf8z4cfpxgbggro9k9blwZ upglibc]# 

注意的是binutils的版本检查,可以使用ld --version as --version
以上都是升级之后的了

看一下我下载的相关升级包:

[root@iZf8z4cfpxgbggro9k9blwZ home]# cd upglibc/
[root@iZf8z4cfpxgbggro9k9blwZ upglibc]# ls
gcc-9.3.0.tar.gz  gdb-7.8.2.tar.xz   gmp-6.1.0.tar.bz2  make-4.3.tar.gz   mpfr-3.1.4.tar.bz2
gdb-7.8.2.tar     glibc-2.34.tar.gz  isl-0.18.tar.bz2   mpc-1.0.3.tar.gz  termcap-1.3.1.tar.gz
  • 开始一个个升级
  1. 升级python3
  2. 升级make
  3. 升级gcc需要的依赖
  4. 升级gcc
  5. 升级gdb
  6. 升级glibc

1、升级python3


`yum install python3 python3 --version `

2、升级make

`wget https://mirrors.aliyun.com/gnu/make/make-4.3.tar.gz tar -xzvf make-4.3.tar.gz -C /opt cd /opt/make-4.3/ mkdir build cd build ../configure --prefix=/usr && make && make install `

3、升级gcc依赖

`wget ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 wget ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz wget https://gcc.gnu.org/pub/gcc/infrastructure/isl.0.18.tar.bz2 ` 或者在gcc目录下,通过执行./contrib/download_prerequisites下载(可能失败); 有些文章写的好像还解压make了这4个前置依赖安装包,但是好像并不需要,下载包和gcc在同一目录,那就行了

4、升级gcc

`mkdir build cd build ../configure --enable-checking=release --enable-language=c,c++ --disable-multilib --prefix=/usr ` 然后make编译,这一步非常慢,1个小时左右,我的是2核cpu所有是j2,cat /proc/cpuinfo| grep "processor"| wc -l查看; `make -j2 //1个小时…… make install gcc --version `

5、升级gdb

`gdb --version wget https://gcc.gnu.org/pub/gdb/releases/gdb-7.8.2.tar.xz xz -dk gdb-7.8.2.tar.xz tar -xvf gdb-7.8.2.tar -C /opt mkdir build cd build ../configure --prefix=/usr//自动配置环境变量,否则gdb --version 还是原来的版本; ` 可能会提升安装textinfo,wget https://mirrors.aliyun.com/gnu/termcap/termcap-1.3.1.tar.gz

6、最后关键的一步,升级glibc

strings /lib64/libc.so.6 | grep GLIBC//查看一下当前的glibc; `wget https://mirrors.aliyun.com/gnu/glibc/glibc-2.34.tar.gz tar -xzvf glibc-2.34.tar.gz -C /opt cd /opt/glibc-2.34/ mkdir build ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin --disable-sanity-checks --disable-werror make -j2//时间比较慢 make install `

  • 遇到的问题

1. make install报错: gcc: relocation error: /lib64/libc.so.6: symbol __tunable_get_val, version GLIBC_PRIVATE not defined in file ld-linux-x86-64.so.2 with link time reference

解决办法,原文链接:https://blog.csdn.net/chenhz2284/article/details/139584458:

LD_PRELOAD=/lib64/libc-2.17.so sln /opt/glibc-2.34/build/libc.so.6  /lib64/libc.so.6
LD_PRELOAD=/lib64/libc-2.17.so sln /opt/glibc-2.34/build/dlfcn/libdl.so.2  /lib64/libdl.so.2
LD_PRELOAD=/lib64/libc-2.17.so sln /opt/glibc-2.34/build/nptl/libpthread.so.0 /lib64/libpthread.so.0
LD_PRELOAD=/lib64/libc-2.17.so sln /opt/glibc-2.34/build/elf/ld-linux-x86-64.so.2  /usr/lib64/ld-linux-x86-64.so.2

 

2.错误信息: /usr/bin/ld: cannot find -lnss_test2 collect2: error: ld returned 1 exit status

解决办法:

修改glibc-2.28/scripts/test-installation.pl, 将第128行:
    && $name ne “nss_test1” && $name ne “libgcc_s”) {
修改成:
    && $name ne “nss_test1” && $name ne “nss_test2” && $name ne “nss_nis” && $name ne “nss_nisplus” && $name ne “libgcc_s”) {
原文链接:https://blog.csdn.net/freflying1119/article/details/141937402

 

3.重新本地化环境 //重新生成本地化环境 localedef -c -i en_US -f UTF-8 en_US.UTF-8 locale

strings /lib64/libc.so.6 | grep GLIBC//再查看一下当前的glibc,是否升级成功;

posted on 2025-05-29 13:18  flyworm  阅读(1398)  评论(0)    收藏  举报