CentOS7安装过程中报libstdc++.so.6缺失,libc.so.6缺失

发布时间 2023-06-30 18:30:05作者: 苦逼运维

  在二进制安装Mysql8.0.33过程中,出现了如下报错信息:

./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.11' not found (required by ./mysqld)
./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by ./mysqld)
./mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.22' not found (required by ./mysqld)
./mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by ./mysqld)
./mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./mysqld)
./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ./mysqld)
./mysqld: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by ./mysqld)
./mysqld: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by /usr/local/mysql/bin/../lib/private/libcrypto.so.1.1)
./mysqld: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by /usr/local/mysql/bin/../lib/private/libprotobuf-lite.so.3.19.4)
./mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /usr/local/mysql/bin/../lib/private/libprotobuf-lite.so.3.19.4)
./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /usr/local/mysql/bin/../lib/private/libprotobuf-lite.so.3.19.4)
./mysqld: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /usr/local/mysql/bin/../lib/private/libprotobuf-lite.so.3.19.4)
./mysqld: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /usr/local/mysql/bin/../lib/private/libprotobuf-lite.so.3.19.4)

  查看发现服务器中libstdc++.so.6指向的是同目录的libstdc++.so.6.0.19,并且本地只有libstdc++.so.6.0.19,而其中没有需要的库。根据网上找到的办法,重新下载了libstdc++.so.6.0.25,并且将libstdc++.so.6软连接指向libstdc++.so.6.0.25。之后报错变为了

./mysqld: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

  查下来发现是版本冲突,但是libstdc++-4.8.5-44.el7已经是CentOS的最新版本了。

  之后又找了一下发现需要升级gcc,由于我是内网服务器无法验证yum安装,所以这里提供一个连接,大家自己尝试一下:https://zhuanlan.zhihu.com/p/535657060。我这里采用编译安装gcc

  同样,libc.so.6发现指向的是同目录的libc-2.17.so,其中一样没有需要的库,需要升级glibc。也采用编译安装glibc

  gcc官网:https://gcc.gnu.org/;下载地址:https://ftp.gnu.org/gnu/

(1).GMP编译安装(gcc的依赖包)

  我这里下载gmp-6.2.1.tar.xz

[root@youxi1 ~]# yum -y install m4
[root@youxi1 ~]# tar xvf gmp-6.2.1.tar.xz
[root@youxi1 ~]# cd gmp-6.2.1
[root@youxi1 gmp-6.2.1]# mkdir tmp
[root@youxi1 gmp-6.2.1]# cd tmp/
[root@youxi1 tmp]# ../configure --prefix=/usr/local/gmp-6.2.1
[root@youxi1 tmp]# echo $?
0    //返回0表示成功
[root@youxi1 tmp]# make -j 4 && make install
[root@youxi1 tmp]# echo $?
0 //返回0表示成功

(2).MPFR编译安装(gcc的依赖包)

  我这里下载mpfr-4.2.0.tar.gz

[root@youxi1 tmp]# cd ~
[root@youxi1 ~]# tar zxvf mpfr-4.2.0.tar.gz
[root@youxi1 ~]# cd mpfr-4.2.0
[root@youxi1 mpfr-4.2.0]# mkdir tmp
[root@youxi1 mpfr-4.2.0]# cd tmp
[root@youxi1 tmp]# ../configure --prefix=/usr/local/mpfr-4.2.0 --with-gmp=/usr/local/gmp-6.2.1
[root@youxi1 tmp]# echo $?
0    //返回0表示正常
[root@youxi1 tmp]# make -j 4 && make install
[root@youxi1 tmp]# echo $?
0    //返回0表示正常

(3).MPC编译安装(gcc的依赖包)

  我这里下载mpc-1.3.1.tar.gz

[root@youxi1 tmp]# cd ~
[root@youxi1 ~]# tar zxvf mpc-1.3.1.tar.gz
[root@youxi1 ~]# cd mpc-1.3.1
[root@youxi1 mpc-1.3.1]# mkdir tmp
[root@youxi1 mpc-1.3.1]# cd tmp
[root@youxi1 tmp]# ../configure --prefix=/usr/local/mpc-1.3.1 --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.2.0
[root@youxi1 tmp]# echo $?
0    //返回0表示正常
[root@youxi1 tmp]# make -j 4 && make install
[root@youxi1 tmp]# echo $?
0    //返回0表示正常

(4).添加环境变量

  需要将依赖包添加到环境变量中否则会报错。注意:这里添加LD_LIBRARY_PATH时,echo $LD_LIBRARY_PATH输出是不是空,如果不是空,将值复制补全,不要用LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-1.3.1/lib:/usr/local/gmp-6.2.1/lib:/usr/local/mpfr-4.2.0/lib,在下面安装glibc时我会讲原因

[root@youxi1 tmp]# vi /etc/profile
//最后一行添加
export LD_LIBRARY_PATH=/usr/local/mpc-1.3.1/lib:/usr/local/gmp-6.2.1/lib:/usr/local/mpfr-4.2.0/lib
[root@youxi1 tmp]# source /etc/profile    //重新加载

  如果不添加环境变量,编译安装gcc时,会报如下错误:

error while loading shared libraries: libmpfr.so.6: cannot open shared object file: No such file or directory

(5).gcc编译安装

  我这里下载gcc-13.1.0.tar.gz

[root@youxi1 tmp]# cd ~
[root@youxi1 ~]# tar zxvf gcc-13.1.0.tar.gz
[root@youxi1 ~]# cd gcc-13.1.0
[root@youxi1 gcc-13.1.0]# mkdir tmp && cd tmp
[root@youxi1 tmp]# ../configure --prefix=/usr/local/gcc-13.1.0 --enable-language=c,c++,java --disable-multilib --with-gmp=/usr/local/gmp-6.2.1 --with-mpfr=/usr/local/mpfr-4.2.0 --with-mpc=/usr/local/mpc-1.3.1
[root@youxi1 tmp]# echo $?
0    //返回0表示正常
[root@youxi1 tmp]# make -j 4 && make install
[root@youxi1 tmp]# echo $?
0    //返回0表示正常
[root@youxi1 tmp]# vi /etc/profile
//最后一行添加
export PATH=/usr/local/gcc-13.1.0/bin/:$PATH
[root@youxi1 tmp]# . /etc/profile  //重新加载

(6).替换libstdc.so.6,并进行测试

  替换软链接

[root@youxi1 tmp]# cd /usr/lib64/
[root@youxi1 lib64]# rm -rf libstdc++.so.6
[root@youxi1 lib64]# ln -s /usr/local/gcc-13.1.0/lib64/libstdc++.so.6 ./libstdc++.so.6

  启动二进制mysqld看下报错有没有变少,我启动后报错变成了如下情况:

./mysqld: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by ./mysqld)
./mysqld: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by /usr/local/mysql/bin/../lib/private/libcrypto.so.1.1)
./mysqld: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by /usr/local/mysql/bin/../lib/private/libprotobuf-lite.so.3.19.4)

  一下子问题就去掉大半了,下面就是升级glibc。

(7).glibc编译安装

  我这里下载glibc-ports-2.16.0.tar.gz,glibc-2.37.tar.gz

[root@youxi1 lib64]# cd
[root@youxi1 ~]# tar zxvf glibc-ports-2.16.0.tar.gz
[root@youxi1 ~]# tar zxvf glibc-2.37.tar.gz
[root@youxi1 ~]# mv glibc-ports-2.16.0 glibc-2.37/ports
[root@youxi1 ~]# cd glibc-2.37
[root@youxi1 glibc-2.37]# mkdir tmp
[root@youxi1 glibc-2.37]# cd tmp
[root@youxi1 tmp]# ../configure --prefix=/usr/local/glibc-2.37
checking build system type... aarch64-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
checking for gcc... gcc
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether g++ can link programs... yes
checking for sysdeps preconfigure fragments... aarch64 alpha arc arm csky hppa i386 loongarch m68k microblaze checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
mips nios2 or1k powerpc riscv s390 sh checking for grep that handles long lines and -e... (cached) /bin/grep
checking for egrep... (cached) /bin/grep -E
sparc x86_64 
checking for a BSD-compatible install... /bin/install -c
checking whether ln -s works... yes
checking for /usr/bin/ld... /usr/bin/ld
checking version of /usr/bin/ld... 2.27, ok
checking for gnumake... no
checking for gmake... gmake
checking version of gmake... 3.82, bad
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... no
checking if gcc -B/usr/bin/ is sufficient to build libc... no
checking for python3... no
checking for python... python
checking version of python... 2.7.5, bad
configure: error: 
*** These critical programs are missing or too old: make bison compiler python
*** Check the INSTALL file for required versions.

  报错了,缺的有点多,其中需要升级make、bison、Python。

  yum安装bison

[root@youxi1 tmp]# yum -y install bison

  python下载地址:https://www.python.org/ftp/python,我这里下载Python-3.12.0a1.tar.xz,编译安装升级。

[root@youxi1 tmp]# cd
[root@youxi1 ~]# tar xvf Python-3.12.0a1.tar.xz
[root@youxi1 ~]# cd Python-3.12.0a1
[root@youxi1 Python-3.12.0a1]# mkdir tmp && cd tmp
[root@youxi1 tmp]# ../configure --prefix=/usr/local/python-3.12.0
[root@youxi1 tmp]# echo $?
0    //返回0表示正常
[root@youxi1 tmp]# make -j 8 && make install
[root@youxi1 tmp]# echo $?
0    //返回0表示正常
[root@youxi1 tmp]# cd /bin
[root@youxi1 bin]# ln -s /usr/local/python-3.12.0/bin/python3 ./python3

  make,也是在https://ftp.gnu.org/gnu/这个地址下载,我这里下载make-4.4.tar.gz

[root@youxi1 bin]# cd
[root@youxi1 ~]# tar zxvf make-4.4.tar.gz
[root@youxi1 ~]# cd make-4.4
[root@youxi1 make-4.4]# mkdir tmp && cd tmp
[root@youxi1 tmp]#  ../configure --prefix=/usr/local/make-4.4
[root@youxi1 tmp]# echo $?
0    //返回0表示正常
[root@youxi1 tmp]# make -j 4 && make install
[root@youxi1 tmp]# echo $?
0    //返回0表示正常
[root@youxi1 tmp]# cd /bin
[root@youxi1 bin]# rm -rf gmake
[root@youxi1 bin]# ln -s /usr/local/make-4.4/bin/make ./gmake

  给你们看下,如果/etc/profile中LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc-1.3.1/lib:/usr/local/gmp-6.2.1/lib:/usr/local/mpfr-4.2.0/lib,这么设置会报什么错误。回到glibc目录下重新编译。注意:安装gblic是需要(最少最新版是需要)gmp、mpfr、mpc的,有些说置空的,可能是由于版本原因吧。

[root@youxi1 bin]# cd ~/glibc-2.37/tmp/
[root@youxi1 tmp]# ../configure --prefix=/usr/local/glibc-2.37
checking sysdep dirs... sysdeps/unix/sysv/linux/aarch64 sysdeps/aarch64/nptl sysdeps/unix/sysv/linux/generic sysdeps/unix/sysv/linux/wordsize-64 sysdeps/unix/sysv/linux sysdeps/nptl sysdeps/pthread sysdeps/gnu sysdeps/unix/inet sysdeps/unix/sysv sysdeps/unix sysdeps/posix sysdeps/aarch64/fpu sysdeps/aarch64/multiarch sysdeps/aarch64 sysdeps/wordsize-64 sysdeps/ieee754/ldbl-128 sysdeps/ieee754/dbl-64 sysdeps/ieee754/flt-32 sysdeps/ieee754 sysdeps/generic
checking LD_LIBRARY_PATH variable... contains current directory
configure: error:
*** LD_LIBRARY_PATH shouldn't contain the current directory when
*** building glibc. Please change the environment variable
*** and run configure again.

  这个错误的原因是LD_LIBRARY_PATH包含了--prefix设置的没目录,但可以明确的看到LD_LIBRARY_PATH中并没有这个目录,这里就是由于$LD_LIBRARY_PATH导致的问题。

  讲完问题,现在继续编译安装

[root@youxi1 tmp]# ../configure --prefix=/usr/local/glibc-2.37
[root@youxi1 tmp]# echo $?
0    //返回0表示正常
[root@youxi1 tmp]# make -j 4 && make install
[root@youxi1 tmp]# echo $?
0    //返回0表示正常

  我这里又遇到了一个问题,没有testrun.shT(或testrun.sh)、debugglibc.shT(或debugglibc.sh),这个需要到~/glibc-2.37/Makefile自带的这个文件中去提取出来

 (8).替换libc.so.6

  替换软链接

 

点错了,发布出来了

  

  

  

 

 

 

 

 

参考:https://blog.csdn.net/qq_35107621/article/details/130718534

   https://www.cnblogs.com/moher/p/3236713.html

   https://www.jianshu.com/p/f0a079671f39