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

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

    • 一、发现问题
    • 二、升级glibc版本
      • [1. 下载对应的软件包](#1. 下载对应的软件包)
      • [2. 解压软件包](#2. 解压软件包)
      • [3. 查看新版本glibc安装要求,并查看自己版本是否符合需求](#3. 查看新版本glibc安装要求,并查看自己版本是否符合需求)
      • [4. 升级python版本](#4. 升级python版本)
        • [4.1 下载软件包](#4.1 下载软件包)
        • [4.2 解压](#4.2 解压)
        • [4.3 编译](#4.3 编译)
        • [4.4 确认更新后的python版本](#4.4 确认更新后的python版本)
      • [5. 更新make版本](#5. 更新make版本)
        • [5.1 下载软件包](#5.1 下载软件包)
        • [5.2 解压](#5.2 解压)
        • [5.3 编译](#5.3 编译)
        • [5.4 确认更新后的make版本](#5.4 确认更新后的make版本)
      • [6. 更新gcc版本](#6. 更新gcc版本)
        • [6.1 下载软件包](#6.1 下载软件包)
        • [6.2 解压](#6.2 解压)
        • [6.3 编译](#6.3 编译)
        • [6.4 验证gcc版本](#6.4 验证gcc版本)
        • [6.5 配置全局可用](#6.5 配置全局可用)
      • [7. 编译新版本glibc](#7. 编译新版本glibc)
      • [8. 安装](#8. 安装)
      • [9. 检查可用glibc版本](#9. 检查可用glibc版本)

一、发现问题

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

复制代码
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)

这个问题是没有找到2.32以及2.34的glibc

可以先查看一下目前可用的glibc版本

sh 复制代码
 strings /lib64/libc.so.6 | grep GLIBC

运行结果如下

复制代码
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

可以看出目前并没有那两个版本的glibc

那么,就进入正题,升级glibc版本

二、升级glibc版本

注:

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

1. 下载对应的软件包

sh 复制代码
wget https://mirrors.aliyun.com/gnu/glibc/glibc-2.34.tar.gz

2. 解压软件包

sh 复制代码
tar -zxvf glibc-2.34.tar.gz

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

sh 复制代码
cd glibc-2.34
cat INSTALL | grep -E  "later|newer"

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

复制代码
     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
sh 复制代码
python -V
gcc -v
make -v
复制代码
Python 2.7.5
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
GNU Make 3.82

4. 升级python版本

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

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

依次执行下列命令

sh 复制代码
mkdir /usr/local/python3
cd Python-3.8.0
mkdir build
../configure --prefix=/usr/local/python3
make -j 4
make install
4.4 确认更新后的python版本
sh 复制代码
 python3 -V

5. 更新make版本

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

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

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

5.4 确认更新后的make版本
sh 复制代码
make -v
复制代码
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>。
本软件是自由软件:您可以自由修改和重新发布它。
在法律允许的范围内没有其他保证。

6. 更新gcc版本

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

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

非常慢,耐心等待

6.4 验证gcc版本
sh 复制代码
gcc -v
复制代码
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)
6.5 配置全局可用
sh 复制代码
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

7. 编译新版本glibc

sh 复制代码
cd glibc-2.34
mkdir build
cd build
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin

8. 安装

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

sh 复制代码
make && 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
 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

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

复制代码
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

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

sh 复制代码
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

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

此时,再次执行

sh 复制代码
make install

9. 检查可用glibc版本

sh 复制代码
strings /lib64/libc.so.6 | grep GLIBC
复制代码
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

成功!!!

相关推荐
2401_868534785 小时前
分析RTOS与Linux有什么区别
linux·运维·服务器
玛丽莲茼蒿5 小时前
Linux/Unix学习笔记(四)—— 进程管理
linux·学习·unix
㳺三才人子5 小时前
初探 Flask
后端·python·flask·html
星栈独行5 小时前
我在 Rust 全栈项目里用 JWT 做无状态认证
开发语言·后端·rust·前端框架·开源·github·web
Peace6 小时前
【Nginx】
linux·运维·nginx
Java爱好狂.6 小时前
Java程序员体系化学习路线(2026最新版)
java·后端·java面试·java架构师·java程序员·java八股文·java学习路线
网络与设备以及操作系统学习使用者6 小时前
Linux与Windows核心差异深度解析
linux·运维·网络·windows·学习
陈随易6 小时前
Redis 8.8发布,一定要更新
前端·后端·程序员
装不满的克莱因瓶7 小时前
SpringBoot 如何将 lib 目录中jar包打包进最终的jar包里面
spring boot·后端·maven·jar·mvn
筠筠喵呜喵7 小时前
Linux CPU性能优化:D状态和Z状态排查与处理
linux·服务器·性能优化