CentOS7.9升级glibc到2.31版本
1、配置yum清华源镜像源
sed -e "s|^mirrorlist=|#mirrorlist=|g" \
-e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009|g" \
-e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.9.2009|g" \
-i.bak \
/etc/yum.repos.d/CentOS-*.repo
yum clean all && yum makecache && yum repolist && yum -y update
2、安装依赖软件python3
yum -y install python3 bzip2 bison gcc libtool gcc-c++ wget vim net-tools unzip zip chrony git tar lrzsz lsof curl telnet git-lfs libxml2-devel libxslt-devel zlib-devel
yum -y groupinstall "Development Tools"
3、安装/升级gcc
# 下载软件包
wget https://mirrors.aliyun.com/gnu/gcc/gcc-9.3.0/gcc-9.3.0.tar.gz
# 解压依赖包
tar -zxf gcc-9.3.0.tar.gz && cd gcc-9.3.0/
# 下载4个依赖包
./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/'
# 预编译
mkdir build && cd build
../configure --enable-checking=release --enable-language=c,c++ --disable-multilib --prefix=/usr/local/gcc
# 查看cpu核数
cat /proc/cpuinfo| grep “processor”| wc -l
# -j4中的数字为cpu核数,及并发工作任务数量,可以提高编译效率,编译时间比较久。
make -j4
# 编译安装
make install
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/gcc/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.
----------------------------------------------------------------------
# 配置软链接
mv /usr/bin/gcc /usr/bin/gcc_4.8.5
ln -s /usr/local/gcc/bin/gcc /usr/bin/gcc
mv /usr/bin/g++ /usr/bin/g++_4.8.5
ln -s /usr/local/gcc/bin/g++ /usr/bin/g++
# 检查gcc版本
gcc -v
升级之前gcc未安装
使用原先升级方式是8.3.3
4、升级make
# 下载软件包
wget https://mirrors.aliyun.com/gnu/make/make-4.3.tar.gz
# 解压
tar -zxf make-4.3.tar.gz && cd make-4.3/
# 预编译
mkdir build && cd build
../configure --prefix=/usr
# -j4中的数字为cpu核数,及并发工作任务数量,可以提高编译效率
make -j4
# 编译安装
make install
# 查看版本
make -v
6、源码编译安装glibc
**注意:**如果make编译完有错误,一定不要执行make install安装操作,有可能会把系统搞崩命令失效的情况。
出现错误的原因就是/usr/lib64中的软连接出现了不匹配的情况。恢复之前的软连接即可恢复系统。
出现问题后,千万不要断开SSH的连接,断开就连不上了会非常麻烦。
# 下载软件包
wget https://mirrors.aliyun.com/gnu/glibc/glibc-2.31.tar.gz
# 解压
tar -zxvf glibc-2.31.tar.gz && cd glibc-2.31/
# 预编译
mkdir build && cd build
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin --disable-sanity-checks --disable-werror
# 编译
make -j4
# 备份lib64
cp -r /usr/lib64 /usr/lib64.back
# 安装
make install
# 出现如下这个报错不用管
# /usr/bin/ld: cannot find -lnss_test2
# collect2: error: ld returned 1 exit status
# Execution of gcc -B/usr/bin/ failed!
# The script has found some problems with your installation!
# Please read the FAQ and the README file and check the following:
# - Did you change the gcc specs file (necessary after upgrading from
# Linux libc5)?
# - Are there any symbolic links of the form libXXX.so to old libraries?
# Links like libm.so -> libm.so.5 (where libm.so.5 is an old library) are wrong,
# libm.so should point to the newly installed glibc file - and there should be
# only one such link (check e.g. /lib and /usr/lib)
# You should restart this script from your build directory after you've
# fixed all problems!
# Btw. the script doesn't work if you're installing GNU libc not as your
# primary library!
# make[1]: *** [Makefile:111: install] Error 1
# make[1]: Leaving directory '/root/glibc-2.28'
# make: *** [Makefile:12: install] Error 2
# 查看版本
ldd --version
echo "查看当前安装的GLIBC版本" ,安装的是2.31版本,查看也是这个版本,但是实际上只到2.30版本
strings /lib64/libc.so.6 | grep ^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_PRIVATE
GLIBC_2.29
GLIBC_2.26
GLIBC_2.25
GLIBC_2.28
GLIBC_2.23
GLIBC_2.8
GLIBC_2.30
GLIBC_2.5
GLIBC_2.9
GLIBC_2.7
GLIBC_2.6
GLIBC_2.18
GLIBC_2.11
GLIBC_2.16
GLIBC_2.13
GLIBC_2.2.6
echo "重新生成本地化文件"
localedef -c -i en_US -f UTF-8 en_US.UTF-8
localedef -c -i zh_CN -f UTF-8 zh_CN.UTF-8
echo "清除系统的缓存"
ldconfig
echo "重新加载 shell 环境"
source /etc/profile
问题:升级glibc版本后,使用yum在线安装软件会卡死
比如:yum -y install telnet 会卡着不动,解决办法如下
获取到进程pid,ps -ef|grep "yum",使用kill -9 pid杀死这个进程,然后再次使用yum进行安装会报错:Error: rpmdb open failed,然后需重构yum数据文件
rm -rf /var/lib/rpm/--db* && rpm --rebuilddb && yum makecache
最后再使用yum进行在线安装就行了
详细过程如下:
[root@localhost ~]# yum -y install telnet
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package telnet.x86_64 1:0.17-66.el7 will be reinstalled
yum^Z
[1]+ Stopped yum -y reinstall telnet
[root@localhost ~]# ps -ef|grep "yum"
root 42588 1305 0 13:16 pts/0 00:00:00 /usr/bin/python /usr/bin/yum -y install telnet
root 42593 1305 0 13:22 pts/0 00:00:00 grep --color=auto yum
[root@localhost ~]# kill -9 42588
[root@localhost ~]# ps -ef|grep "yum"
root 42595 1305 0 13:22 pts/0 00:00:00 grep --color=auto yum
[1]+ Killed yum -y install telnet
[root@localhost ~]# yum -y install telnet
error: rpmdb: BDB0113 Thread/process 42588/140494434354624 failed: BDB1507 Thread died in Berkeley DB library
error: db5 error(-30973) from dbenv->failchk: BDB0087 DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db5 - (-30973)
error: cannot open Packages database in /var/lib/rpm
CRITICAL:yum.main:
Error: rpmdb open failed
[root@localhost ~]# rm -rf /var/lib/rpm/--db*
[root@localhost ~]# rpm --rebuilddb
[root@localhost ~]# yum makecache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Metadata Cache Created
[root@localhost ~]# yum -y install telnet
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package telnet.x86_64 1:0.17-66.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================
Package Arch Version Repository Size
======================================================================================================================
Reinstalling:
telnet x86_64 1:0.17-66.el7 updates 64 k
Transaction Summary
======================================================================================================================
Reinstall 1 Package
Total download size: 64 k
Installed size: 113 k
Downloading packages:
telnet-0.17-66.el7.x86_64.rpm | 64 kB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 1:telnet-0.17-66.el7.x86_64 1/1
Verifying : 1:telnet-0.17-66.el7.x86_64 1/1
Installed:
telnet.x86_64 1:0.17-66.el7
Complete!
[root@localhost ~]#

浙公网安备 33010602011771号