0
0
0
0
专栏/.../

TiDB 版本升级:glibc 2.17 升级到 glibc 2.28 最佳实践

 pepezzzz  发表于  2025-01-08

一、准备

现有环境版本记录

[ecs-user@centos79 ~]$ rpm -qa |grep glibc
glibc-common-2.17-326.el7_9.3.x86_64
glibc-2.17-326.el7_9.3.x86_64
glibc-devel-2.17-326.el7_9.3.x86_64
glibc-headers-2.17-326.el7_9.3.x86_64
[ecs-user@centos79 ~]$ ldd --version
ldd (GNU libc) 2.17
Copyright (C) 2012 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.
[ecs-user@centos79 ~]$ ls -l /lib64/libc.so.6
lrwxrwxrwx 1 root root 12 Jun 28  2024 /lib64/libc.so.6 -> libc-2.17.so
[root@vm172-16-201-10 src]# strings /lib64/libc.so.6 | grep GLIBC|more
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 源码包里版本依赖要求

[root@vm172-16-201-10 glibc-2.28]# grep '^   \*' INSTALL 
   * Python 2.7/3.4 or later
   * PExpect 4.0
   * GDB 7.8 or later with support for Python 2.7/3.4 or later
   * GNU 'make' 4.0 or newer
   * GCC 4.9 or newer
   * GNU 'binutils' 2.25 or later
   * GNU 'texinfo' 4.7 or later
   * GNU 'awk' 3.1.2, or higher
   * GNU 'bison' 2.7 or later
   * Perl 5
   * GNU 'sed' 3.02 or newer
   * GNU 'autoconf' 2.69 (exactly)
   * GNU 'gettext' 0.10.36 or later

手工版本检查

# which gcc g++ c++
/usr/bin/gcc
/usr/bin/g++
/usr/bin/c++
# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
# make --version
GNU Make 3.82
Built for x86_64-redhat-linux-gnu
Copyright (C) 2010  Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

主要升级 GCC 和 Make 工具的版本

二、安装 glibc 2.28

安装 gcc

  1. 离线环境下载依赖包
yum install -y gcc-c++
yum install -y m4
yum install -y bzip2
cd /usr/local/src

# 阿里云镜像站:
wget https://mirrors.aliyun.com/gnu/make/make-4.2.1.tar.gz
wget https://mirrors.aliyun.com/gnu/gcc/gcc-8.1.0/gcc-8.1.0.tar.gz
wget https://mirrors.aliyun.com/gnu/gmp/gmp-6.1.0.tar.bz2
wget https://mirrors.aliyun.com/gnu/mpfr/mpfr-3.1.4.tar.bz2
wget https://mirrors.aliyun.com/gnu/mpc/mpc-1.0.3.tar.gz
wget https://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
wget https://mirrors.aliyun.com/gnu/glibc/glibc-2.28.tar.gz
# 源站点:
wget http://ftp.gnu.org/gnu/make/make-4.2.1.tar.gz
wget http://ftp.gnu.org/gnu/gcc/gcc-8.1.0/gcc-8.1.0.tar.gz
wget http://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2
wget http://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz
wget http://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2
wget https://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz

tar xf make-4.2.1.tar.gz
tar xf gcc-8.1.0.tar.gz
tar xf gmp-6.1.0.tar.bz2
tar xf mpfr-3.1.4.tar.bz2 
tar xf mpc-1.0.3.tar.gz 
tar xf isl-0.18.tar.bz2
tar xf glibc-2.28.tar.gz

# 依赖包移动到 gcc 目录下

mv gmp-6.1.0 gcc-8.1.0/
mv isl-0.18 gcc-8.1.0/
mv mpc-1.0.3 gcc-8.1.0/
mv mpfr-3.1.4 gcc-8.1.0/

cd gcc-8.1.0/
ln -sf gmp-6.1.0 gmp
ln -sf isl-0.18 isl
ln -sf mpc-1.0.3 mpc
ln -sf mpfr-3.1.4 mpfr
  1. 编译 gcc ,需要 30 分钟左右

https://gcc.gnu.org/install/configure.html 查看编译参数

cd /usr/local/src/gcc-8.1.0
mkdir build;cd build
../configure --prefix=/usr/local/gcc810 --disable-multilib
make -j `nproc`
# gcc 的编译过程大概需要半小时,-j `nproc` 代表与节点 CPU 数量一致,也可以直接写为 make -j 8 指定线程数。
make install

源码包里 configure 过程中也会有版本依赖检查提示:

checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln -s works... yes
checking whether as is GNU as... yes
checking whether ld is GNU ld... yes
checking for as... as
checking version of as... 2.27, ok
checking for ld... ld
checking version of ld... 2.27, ok
checking for gnumake... no
checking for gmake... gmake
checking version of gmake... 4.2.1, ok
checking for gnumsgfmt... no
checking for gmsgfmt... no
checking for msgfmt... msgfmt
checking version of msgfmt... 0.19.8.1, ok
checking for makeinfo... no
checking for sed... sed
checking version of sed... 4.2.2, ok
checking for gawk... gawk
checking version of gawk... 4.0.2, ok
checking for bison... bison
checking version of bison... 3.0.4, ok
checking if gcc is sufficient to build libc... no
checking for nm... nm
checking for python3... python3
configure: error: 
*** These critical programs are missing or too old: compiler
*** Check the INSTALL file for required versions.

make 结果输出:

----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/gcc810/lib/../lib64

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
make[4]: Nothing to be done for 'install-data-am'.
make[4]: Leaving directory '/usr/local/src/gcc-8.1.0/build/x86_64-pc-linux-gnu/libatomic'
make[3]: Leaving directory '/usr/local/src/gcc-8.1.0/build/x86_64-pc-linux-gnu/libatomic'
make[2]: Leaving directory '/usr/local/src/gcc-8.1.0/build/x86_64-pc-linux-gnu/libatomic'
make[1]: Leaving directory '/usr/local/src/gcc-8.1.0/build'
  1. 添加系统 lib 库
vi /etc/profile
# 添加如下:
export LD_LIBRARY_PATH=/usr/local/gcc810/lib64:/lib64
# 重新登录后验证:
env |grep -i ld
输出如下:
LD_LIBRARY_PATH=/usr/local/gcc810/lib64:/lib64
  1. 添加到系统 bin 下

使用软链接或者用 alternatives 进行管理,不能直接拷贝二进制文件。

cd /usr/bin/
mv gcc gcc485
mv g++ g++485
mv c++ c++485

alternatives --install /usr/bin/gcc gcc /usr/local/gcc810/bin/gcc 10  --slave /usr/bin/g++ g++ /usr/local/gcc810/bin/g++ --slave /usr/bin/c++ c++  /usr/local/gcc810/bin/c++

验证如下:

# alternatives  --display gcc
gcc - status is auto.
 link currently points to /usr/local/gcc810/bin/gcc
/usr/local/gcc810/bin/gcc - priority 10
 slave g++: /usr/local/gcc810/bin/g++
 slave c++: /usr/local/gcc810/bin/c++
Current `best' version is /usr/local/gcc810/bin/gcc.
# ls -l /usr/bin/gcc /usr/bin/g++ /usr/bin/c++
lrwxrwxrwx 1 root root 21 Jan  7 23:14 /usr/bin/c++ -> /etc/alternatives/c++
lrwxrwxrwx 1 root root 21 Jan  7 23:14 /usr/bin/g++ -> /etc/alternatives/g++
lrwxrwxrwx 1 root root 21 Jan  7 23:14 /usr/bin/gcc -> /etc/alternatives/gcc
# ls -l /etc/alternatives/c++  /etc/alternatives/g++  /etc/alternatives/gcc 
lrwxrwxrwx 1 root root 25 Jan  7 23:14 /etc/alternatives/c++ -> /usr/local/gcc810/bin/c++
lrwxrwxrwx 1 root root 25 Jan  7 23:14 /etc/alternatives/g++ -> /usr/local/gcc810/bin/g++
lrwxrwxrwx 1 root root 25 Jan  7 23:14 /etc/alternatives/gcc -> /usr/local/gcc810/bin/gcc
# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc810/libexec/gcc/x86_64-pc-linux-gnu/8.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/usr/local/gcc810 --disable-multilib
Thread model: posix
gcc version 8.1.0 (GCC) 
  1. 添加 libstdc++.so.6.0.25 到系统 lib 下
ls  -l /lib64/libstdc++.so.6
lrwxrwxrwx 1 root root 19 Jul 10  2023 /lib64/libstdc++.so.6 -> libstdc++.so.6.0.19
ln -sf /usr/local/gcc810/lib64/libstdc++.so.6.0.25 /lib64/libstdc++.so.6
ls  -l /lib64/libstdc++.so.6
lrwxrwxrwx 1 root root 43 Jan  7 12:31 /lib64/libstdc++.so.6 -> /usr/local/gcc810/lib64/libstdc++.so.6.0.25

安装 make

make --version
which make
cd /usr/local/src/make-4.2.1
./configure
make -j 4 && make install
mv /usr/bin/make /usr/bin/make3
cp /usr/local/bin/make /usr/bin
make --version

输出如下:

GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

安装 glibc

https://www.gnu.org/software/libc/manual/2.28/html_node/Configuring-and-compiling.html

cd /usr/local/src/glibc-2.28/
vim scripts/test-installation.pl

第 128 行

    next if ($build_mathvec == 0 && $name eq "mvec");
    if ($name ne "nss_ldap" && $name ne "db1"
        && $name ne "thread_db"
        && $name ne "nss_test1" && $name ne "libgcc_s" && $name ne "nss_test2") {
      $link_libs .= " -l$name";
      $versions{$name} = $version;

执行

cd /usr/local/src/glibc-2.28/
mkdir build;cd build
../configure --prefix=/usr --with-headers=/usr/include --with-binutils=/usr/bin --enable-obsolete-nsl
make -j 8
make install
localedef -f UTF-8 -i en_US en_US.UTF-8

make install 提示

rm -f /usr/local/src/glibc-2.28/build/stubs.h
/usr/local/src/glibc-2.28/build/elf/sln /usr/local/src/glibc-2.28/build/elf/symlink.list
rm -f /usr/local/src/glibc-2.28/build/elf/symlink.list
test ! -x /usr/local/src/glibc-2.28/build/elf/ldconfig || LC_ALL=C \
  /usr/local/src/glibc-2.28/build/elf/ldconfig  \
                        /lib64 /usr/lib64
LD_SO=ld-linux-x86-64.so.2 CC="gcc -B/usr/bin/" /usr/bin/perl scripts/test-installation.pl /usr/local/src/glibc-2.28/build/
Your new glibc installation seems to be ok.
make[1]: Leaving directory '/usr/local/src/glibc-2.28'

升级后效果

# ldd --version
ldd (GNU libc) 2.28
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.
Written by Roland McGrath and Ulrich Drepper.
# ls -l /lib64/libc.so.6
lrwxrwxrwx 1 root root 12 Jan  7 21:21 /lib64/libc.so.6 -> libc-2.28.so
# strings  /lib64/libc.so.6  |grep -i glibc |more
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

三、问题记录

问题1:

gcc configure 命令执行过程报错:

checking whether g++ supports C++11 features by default... no
checking whether g++ supports C++11 features with -std=gnu++11... no
checking whether g++ supports C++11 features with -std=gnu++0x... no
checking whether g++ supports C++11 features with -std=c++11... no
checking whether g++ supports C++11 features with +std=c++11... no
checking whether g++ supports C++11 features with -h std=c++11... no
checking whether g++ supports C++11 features with -std=c++0x... no
checking whether g++ supports C++11 features with +std=c++0x... no
checking whether g++ supports C++11 features with -h std=c++0x... no
configure: error: *** A compiler with support for C++11 language features is required.

解决方案

yum install -y gcc-c++

问题2:

gcc configure 命令执行过程报错:

configure: error: Building GCC requires GMP 4.2+, MPFR 3.1.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at
https://gcc.gnu.org/pub/gcc/infrastructure/.  See also
http://gcc.gnu.org/install/prerequisites.html for additional info.  If
you obtained GMP, MPFR and/or MPC from a vendor distribution package,
make sure that you have installed both the libraries and the header
files.  They may be located in separate packages.

configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.
Try the --with-gmp, --with-mpfr and/or --with-mpc options to specify
their locations.  Source code for these libraries can be found at
their respective hosting sites as well as at
ftp://gcc.gnu.org/pub/gcc/infrastructure/. 

解决方案

下载以下的包,解压到 gcc 目录下,创建无版本号的软链接,不再需要手工 make 这几个库。如果是联网环境也可以直接执行 ./contrib/download_prerequisites (即要求在 gcc 的解压目录下执行)。

more contrib/download_prerequisites

gmp='gmp-6.1.0.tar.bz2'
mpfr='mpfr-3.1.4.tar.bz2'
mpc='mpc-1.0.3.tar.gz'
isl='isl-0.18.tar.bz2'

base_url='ftp://gcc.gnu.org/pub/gcc/infrastructure/'

问题3:

gcc configure 命令执行过程报错:

configure: error: I suspect your system does not have 32-bit development libraries (libc and headers). If you have them, rerun configure with --enable-multilib. If you do not have them, and want to build a 64-bit-only compiler, rerun configure with --disable-multilib.

解决方案:

指定配置参数。

./configure --prefix=/usr/local/gcc810  --disable-multilib 

问题4:

Glibc make install 过程报错

LD_SO=ld-linux-x86-64.so.2 CC="gcc -B/usr/bin/" /usr/bin/perl scripts/test-installation.pl /opt/module/mysql-lib/glibc-2.28/build/
/usr/bin/ld: cannot find -lnss_test2
collect2: error: ld returned 1 exit status
Execution of gcc -B/usr/bin/ failed!

解决方案:

vim /scripts/test-installation.pl
        && $name ne "nss_test1" && $name ne "libgcc_s" && $name ne "nss_test2") {

问题5:

Glibc make install 过程报错

undefined reference to '_nsl_default_nss@GLIBC_PRIVATE'

解决方案:

configure 增加 --enable-obsolete-nsl

问题6:

登录提示

-bash: warning: setlocale: LC_TIME: cannot change locale (en_US.UTF-8)

解决方案:

localedef -f UTF-8 -i en_US en_US.UTF-8

四、参考文档

GLIBC 部分:

https://garlicspace.com/2020/07/18/centos7-%E5%8D%87%E7%BA%A7-glibc-gcc/

0
0
0
0

版权声明:本文为 TiDB 社区用户原创文章,遵循 CC BY-NC-SA 4.0 版权协议,转载请附上原文出处链接和本声明。

评论
暂无评论