中国红客联盟 首页 资讯 国内安全 查看内容

如何安全,高效,优雅的提升linux的glibc版本

2025-3-3 10:33| 发布者: Honkers| 查看: 121| 评论: 0

摘要: 一、发现问题 之前在配置Gorse的时候遇到了下面这个问题: [code]gorse-in-one: /lib64/libc.so.6: version `GLIBC_2.32' not found (required by gorse-in-one) gorse-in-one: /lib64/libc


一、发现问题

之前在配置Gorse的时候遇到了下面这个问题:

[code]gorse-in-one: /lib64/libc.so.6: version `GLIBC_2.32' not found (required by gorse-in-one) gorse-in-one: /lib64/libc.so.6: version `GLIBC_2.34' not found (required by gorse-in-one) [/code]

这个问题是没有找到2.32以及2.34的glibc
可以先查看一下目前可用的glibc版本

[code] strings /lib64/libc.so.6 | grep GLIBC [/code]

运行结果如下

[code]GLIBC_2.2.5 GLIBC_2.2.6 GLIBC_2.3 GLIBC_2.3.2 GLIBC_2.3.3 GLIBC_2.3.4 GLIBC_2.4 GLIBC_2.5 GLIBC_2.6 GLIBC_2.7 GLIBC_2.8 GLIBC_2.9 GLIBC_2.10 GLIBC_2.11 GLIBC_2.12 GLIBC_2.13 GLIBC_2.14 GLIBC_2.15 GLIBC_2.16 GLIBC_2.17 GLIBC_PRIVATE [/code]

可以看出目前并没有那两个版本的glibc
那么,就进入正题,升级glibc版本

二、升级glibc版本

注:

  1. 升级glibc版本存在系统崩溃风险,强烈建议在升级前拍摄系统快照,以便出错时及时恢复
  2. 此操作建议需要的权限较高,建议root成员进行操作,非root成员建议全程使用sudo操作

1. 下载对应的软件包

[code]wget https://mirrors.aliyun.com/gnu/glibc/glibc-2.34.tar.gz [/code]

2. 解压软件包

[code]tar -zxvf glibc-2.34.tar.gz [/code]

3. 查看新版本glibc安装要求,并查看自己版本是否符合需求

[code]cd glibc-2.34 cat INSTALL | grep -E "later|newer" [/code]

结果如下,主要关注python make gcc 三个版本

[code] this option if you want to compile the GNU C Library with a newer later. Note that when CET is enabled, the GNU C Library requires Intel Pentium Pro or newer. With '--enable-cet', it is an error to to build without this option (for example, if building with a newer The tests (and later installation) use some pre-existing files of the * 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 [/code] [code]python -V gcc -v make -v [/code] [code]Python 2.7.5 gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) GNU Make 3.82 [/code]

4. 升级python版本

如果不执行这步,直接进行升级会出现如下报错

[code]configure: error: *** These critical programs are missing or too old: make compiler python *** Check the INSTALL file for required versions. [/code]
4.1 下载软件包
[code]wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz [/code]
4.2 解压
[code]tar -zxf Python-3.8.0.tgz [/code]
4.3 编译

依次执行下列命令

[code]mkdir /usr/local/python3 cd Python-3.8.0 mkdir build ../configure --prefix=/usr/local/python3 make -j 4 make install [/code]
4.4 确认更新后的python版本
[code] python3 -V [/code]

5. 更新make版本

如果不执行这步,直接进行升级会出现如下报错

[code]configure: error: *** These critical programs are missing or too old: make compiler *** Check the INSTALL file for required versions. [/code]
5.1 下载软件包
[code]wget http://ftp.gnu.org/pub/gnu/make/make-4.3.tar.gz [/code]
5.2 解压
[code]tar -zxvf make-4.3.tar.gz [/code]
5.3 编译
[code]cd make-4.3 ./configure --prefix=/usr type make make check # 可能会报一些错误,不过不影响后面的install make install [/code]

这几步稍有点慢,耐心等待

5.4 确认更新后的make版本
[code]make -v [/code] [code]GNU Make 4.3 为 x86_64-pc-linux-gnu 编译 Copyright (C) 1988-2020 Free Software Foundation, Inc. 许可证:GPLv3+:GNU 通用公共许可证第 3 版或更新版本<http://gnu.org/licenses/gpl.html>。 本软件是自由软件:您可以自由修改和重新发布它。 在法律允许的范围内没有其他保证。 [/code]

6. 更新gcc版本

如果不执行这步,直接进行升级会出现如下报错

[code]configure: error: *** These critical programs are missing or too old: compiler *** Check the INSTALL file for required versions. [/code]
6.1 下载软件包
[code]wget http://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.gz [/code]
6.2 解压
[code]tar -zxvf gcc-11.2.0.tar.gz [/code]
6.3 编译
[code]mkdir build cd build/ ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib make -j 4 # 这一步时间非常长 yum -y remove gcc g++ # 删除旧版本 make install # 安装 [/code]

非常慢,耐心等待

6.4 验证gcc版本
[code]gcc -v [/code] [code]Using built-in specs. COLLECT_GCC=/usr/local/bin/gcc COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-pc-linux-gnu/11.2.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib Thread model: posix Supported LTO compression algorithms: zlib gcc version 11.2.0 (GCC) [/code]
6.5 配置全局可用
[code]ln -s /usr/local/bin/gcc /usr/bin/gcc ln -s /usr/local/bin/g++ /usr/bin/g++ # 更新动态库 rm -f /usr/lib64/libstdc++.so.6 ln -s /usr/local/lib64/libstdc++.so.6.0.29 /usr/lib64/libstdc++.so.6 [/code]

7. 编译新版本glibc

[code]cd glibc-2.34 mkdir bulid cd bulid ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin [/code]

8. 安装

这步请务必确保当前用户拥有权限,非root用户请使用sudo运行

[code]make && make install [/code]

接下来大概率会报这样的错误

[code]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 make[1]: *** [Makerules:1041: /home/luolong/glibc-2.35/build/format.lds] Error 127 make[1]: Leaving directory '/home/luolong/glibc-2.35' make: *** [Makefile:12: install] Error 2 [/code]

这时候应该SSH的链接也断开了,很多基础命令也无法使用了 如使用ls命令

[code]ls: relocation error: /lib64/libpthread.so.0: symbol __libc_dl_error_tsd, version GLIBC_PRIVATE not defined in file libc.so.6 with link time reference [/code]

这是正常现象,请键入如下命令

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

PS:如果你并不是root用户,请将[/root/glibc-2.34/build] 改成自己的位置

此时,再次执行

[code]make install [/code]

9. 检查可用glibc版本

[code]strings /lib64/libc.so.6 | grep GLIBC [/code] [code]GLIBC_2.2.5 GLIBC_2.2.6 GLIBC_2.3 GLIBC_2.3.2 GLIBC_2.3.3 GLIBC_2.3.4 GLIBC_2.4 GLIBC_2.5 GLIBC_2.6 GLIBC_2.7 GLIBC_2.8 GLIBC_2.9 GLIBC_2.10 GLIBC_2.11 GLIBC_2.12 GLIBC_2.13 GLIBC_2.14 GLIBC_2.15 GLIBC_2.16 GLIBC_2.17 GLIBC_2.18 GLIBC_2.22 GLIBC_2.23 GLIBC_2.24 GLIBC_2.25 GLIBC_2.26 GLIBC_2.27 GLIBC_2.28 GLIBC_2.29 GLIBC_2.30 GLIBC_2.31 GLIBC_2.32 GLIBC_2.33 GLIBC_2.34 GLIBC_PRIVATE [/code]

成功!!!


免责声明:本内容来源于网络,如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

路过

雷人

握手

鲜花

鸡蛋

发表评论

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2025 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行