TiDB 版本升级:glibc 2.17 升级到 glibc 2.28 最佳实践
- 2025-01-10 北京
本文字数:6408 字
阅读完需:约 21 分钟
作者: pepezzzz 原文来源:https://tidb.net/blog/61a7bf77
一、准备
现有环境版本记录
[ecs-user@centos79 ~]$ rpm -qa |grep glibcglibc-common-2.17-326.el7_9.3.x86_64glibc-2.17-326.el7_9.3.x86_64glibc-devel-2.17-326.el7_9.3.x86_64glibc-headers-2.17-326.el7_9.3.x86_64[ecs-user@centos79 ~]$ ldd --versionldd (GNU libc) 2.17Copyright (C) 2012 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; 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.6lrwxrwxrwx 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|moreGLIBC_2.2.5GLIBC_2.2.6GLIBC_2.3GLIBC_2.3.2GLIBC_2.3.3GLIBC_2.3.4GLIBC_2.4GLIBC_2.5GLIBC_2.6GLIBC_2.7GLIBC_2.8GLIBC_2.9GLIBC_2.10GLIBC_2.11GLIBC_2.12GLIBC_2.13GLIBC_2.14GLIBC_2.15GLIBC_2.16GLIBC_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 -vUsing built-in specs.COLLECT_GCC=gccCOLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapperTarget: x86_64-redhat-linuxConfigured 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-linuxThread model: posixgcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) # make --versionGNU Make 3.82Built for x86_64-redhat-linux-gnuCopyright (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
离线环境下载依赖包
编译 gcc ,需要 30 分钟左右
https://gcc.gnu.org/install/configure.html 查看编译参数
cd /usr/local/src/gcc-8.1.0mkdir build;cd build../configure --prefix=/usr/local/gcc810 --disable-multilibmake -j `nproc`# gcc 的编译过程大概需要半小时,-j `nproc` 代表与节点 CPU 数量一致,也可以直接写为 make -j 8 指定线程数。make install
源码包里 configure 过程中也会有版本依赖检查提示:
checking for a BSD-compatible install... /usr/bin/install -cchecking whether ln -s works... yeschecking whether as is GNU as... yeschecking whether ld is GNU ld... yeschecking for as... aschecking version of as... 2.27, okchecking for ld... ldchecking version of ld... 2.27, okchecking for gnumake... nochecking for gmake... gmakechecking version of gmake... 4.2.1, okchecking for gnumsgfmt... nochecking for gmsgfmt... nochecking for msgfmt... msgfmtchecking version of msgfmt... 0.19.8.1, okchecking for makeinfo... nochecking for sed... sedchecking version of sed... 4.2.2, okchecking for gawk... gawkchecking version of gawk... 4.0.2, okchecking for bison... bisonchecking version of bison... 3.0.4, okchecking if gcc is sufficient to build libc... nochecking for nm... nmchecking for python3... python3configure: 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 librariesin a given directory, LIBDIR, you must either use libtool, andspecify 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 formore 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'
添加系统 lib 库
添加到系统 bin 下
使用软链接或者用 alternatives 进行管理, 不能直接拷贝二进制文件。
cd /usr/bin/mv gcc gcc485mv g++ g++485mv 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 gccgcc - 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 -vUsing built-in specs.COLLECT_GCC=gccCOLLECT_LTO_WRAPPER=/usr/local/gcc810/libexec/gcc/x86_64-pc-linux-gnu/8.1.0/lto-wrapperTarget: x86_64-pc-linux-gnuConfigured with: ../configure --prefix=/usr/local/gcc810 --disable-multilibThread model: posixgcc version 8.1.0 (GCC)
添加 libstdc++.so.6.0.25 到系统 lib 下
安装 make
make --versionwhich makecd /usr/local/src/make-4.2.1./configuremake -j 4 && make installmv /usr/bin/make /usr/bin/make3cp /usr/local/bin/make /usr/binmake --version
输出如下:
GNU Make 4.2.1Built for x86_64-pc-linux-gnuCopyright (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-nslmake -j 8make installlocaledef -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.listrm -f /usr/local/src/glibc-2.28/build/elf/symlink.listtest ! -x /usr/local/src/glibc-2.28/build/elf/ldconfig || LC_ALL=C \ /usr/local/src/glibc-2.28/build/elf/ldconfig \ /lib64 /usr/lib64LD_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 --versionldd (GNU libc) 2.28Copyright (C) 2018 Free Software Foundation, Inc.This is free software; see the source for copying conditions. There is NOwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.Written by Roland McGrath and Ulrich Drepper.# ls -l /lib64/libc.so.6lrwxrwxrwx 1 root root 12 Jan 7 21:21 /lib64/libc.so.6 -> libc-2.28.so# strings /lib64/libc.so.6 |grep -i glibc |moreGLIBC_2.2.5GLIBC_2.2.6GLIBC_2.3GLIBC_2.3.2GLIBC_2.3.3GLIBC_2.3.4GLIBC_2.4GLIBC_2.5GLIBC_2.6GLIBC_2.7GLIBC_2.8GLIBC_2.9GLIBC_2.10GLIBC_2.11GLIBC_2.12GLIBC_2.13GLIBC_2.14GLIBC_2.15GLIBC_2.16GLIBC_2.17GLIBC_2.18GLIBC_2.22GLIBC_2.23GLIBC_2.24GLIBC_2.25GLIBC_2.26GLIBC_2.27GLIBC_2.28
三、问题记录
问题 1:
gcc configure 命令执行过程报错:
checking whether g++ supports C++11 features by default... nochecking whether g++ supports C++11 features with -std=gnu++11... nochecking whether g++ supports C++11 features with -std=gnu++0x... nochecking whether g++ supports C++11 features with -std=c++11... nochecking whether g++ supports C++11 features with +std=c++11... nochecking whether g++ supports C++11 features with -h std=c++11... nochecking whether g++ supports C++11 features with -std=c++0x... nochecking whether g++ supports C++11 features with +std=c++0x... nochecking whether g++ supports C++11 features with -h std=c++0x... noconfigure: 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 specifytheir locations. Source code for these libraries can be found attheir respective hosting sites as well as athttps://gcc.gnu.org/pub/gcc/infrastructure/. See alsohttp://gcc.gnu.org/install/prerequisites.html for additional info. Ifyou obtained GMP, MPFR and/or MPC from a vendor distribution package,make sure that you have installed both the libraries and the headerfiles. 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 specifytheir locations. Source code for these libraries can be found attheir respective hosting sites as well as atftp://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_test2collect2: error: ld returned 1 exit statusExecution 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/
版权声明: 本文为 InfoQ 作者【TiDB 社区干货传送门】的原创文章。
原文链接:【http://xie.infoq.cn/article/a505412ad253f95bad52a8df7】。文章转载请联系作者。
TiDB 社区干货传送门
TiDB 社区官网:https://tidb.net/ 2021-12-15 加入
TiDB 社区干货传送门是由 TiDB 社区中布道师组委会自发组织的 TiDB 社区优质内容对外宣布的栏目,旨在加深 TiDBer 之间的交流和学习。一起构建有爱、互助、共创共建的 TiDB 社区 https://tidb.net/









评论