【Centos7升级glibc版本2.34】

如何轻松升级Linux 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版本

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

  1. 下载对应的软件包
wget https://mirrors.aliyun.com/gnu/glibc/glibc-2.34.tar.gz
  1. 解压软件包
tar -zxvf glibc-2.34.tar.gz
  1. 查看新版本glibc安装要求,并查看自己版本是否符合需求
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
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 下载软件包

wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz

4.2 解压

tar -zxf Python-3.8.0.tgz 

4.3 编译
依次执行下列命令

mkdir /usr/local/python3
cd Python-3.8.0
mkdir build
cd build/
../configure --prefix=/usr/local/python3
make -j 4
make install

4.4 确认更新后的python版本
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 下载软件包

wget http://ftp.gnu.org/pub/gnu/make/make-4.3.tar.gz

5.2 解压

tar -zxvf make-4.3.tar.gz

5.3 编译

cd make-4.3
./configure --prefix=/usr
type make
make check

可能会报一些错误,不过不影响后面的install

make install

这几步稍有点慢,耐心等待
5.4 确认更新后的make版本

make -v

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

  1. 更新gcc版本
    如果不执行这步,直接进行升级会出现如下报错
    configure: error:
    *** These critical programs are missing or too old: compiler
    *** Check the INSTALL file for required versions.
    6.1 下载软件包
wget http://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.gz

6.2 解压

tar -zxvf gcc-11.2.0.tar.gz

6.3 编译

mkdir /usr/local/bin/gcc
cd gcc-11.2.0
mkdir build
cd build/
../configure --prefix=/usr/local/bin/gcc -enable-checking=release -enable-languages=c,c++ -disable-multilib
make -j 4

注意
configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+
执行

sudo yum install gmp-devel mpfr-devel libmpc-devel

这一步时间非常长

yum -y remove gcc g++

删除旧版本

make install

安装

非常慢,耐心等待
6.4 验证gcc版本

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 配置全局可用

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
  1. 编译新版本glibc
cd glibc-2.34
mkdir bulid
cd bulid
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
  1. 安装
    这步请务必确保当前用户拥有权限,非root用户请使用sudo运行
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
这是正常现象,请键入如下命令
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] 改成自己的位置
此时,再次执行

make install
  1. 检查可用glibc版本
    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
    成功!!!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小杍随笔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值