CentOS6.5升級自帶glibc-2.12到glibc-2.15的過程解析(無需重啓)

在開發時項目所依賴的包需要更高版本的glibc庫支持, 而Centos6.5 中glibc默認版本爲2.12, 這樣調試時可能會遇到報錯。但如果不小心把動態庫中的libc.so.6給刪了,瞬間所有的非系統命令都將無法使用,使用就報錯。因爲libc.so.6 是c運行時庫glibc的軟鏈接,而系統幾乎所有程序都依賴c運行時庫。程序啓動和運行時,是根據libc.so.6 軟鏈接找到glibc庫。刪除libc.so.6將導致系統的幾乎所有程序不能工作。
  每個glibc.so文件有它支持的libc版本,可以通過 strings /lib64/libc.so.6 |grep GLIBC 查看,一定要選擇這條命令列出的版本。
[root@test1 ~]# 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_PRIVATE

如果程序編譯的時候鏈接的libc庫版本不在程序運行環境下的glibc庫支持的libc版本之內,也會報錯。於是,系統的所有命令 ls,cp,cd 等等都無法使用了。我們可以到這裏找你要的版本,http://ftp.gnu.org/gnu/glibc/,然後解壓後安裝

一、首先查看下本機的glibc版本
[root@test1 ~]# /lib64/libc.so.6
GNU C Library stable release version 2.12, by Roland McGrath et al.
Copyright (C) 2010 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.
Compiled by GNU CC version 4.4.7 20120313 (Red Hat 4.4.7-4).
Compiled on a Linux 2.6.32 system on 2013-11-05.
Available extensions:
The C stubs add-on version 2.1.2.
crypt add-on version 2.1 by Michael Glad and others
GNU Libidn by Simon Josefsson
Native POSIX Threads Library by Ulrich Drepper et al
BIND-8.2.3-T5B
RT using linux kernel aio
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html&gt;.

二、編譯安裝
[root@test1 ~]# mkdir -pv /path/to/glibc-2.15/build
[root@test1 ~]# cd /path/to/glibc-2.15/
[root@test1 ~]# wget http://ftp.gnu.org/gnu/glibc/glibc-2.15.tar.gz
[root@test1 ~]# tar xzvf glibc-2.15.tar.gz
[root@test1 ~]# cd /path/to/glibc-2.15/build

[root@test1 build]# ../glibc-2.15/configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
這一步是關鍵,一定不要在glibc解壓的那個目錄執行/configure
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in /path/to/glibc-2.15/build':<br/>configure: error: no acceptable C compiler found in $PATH<br/>Seeconfig.log' for more details
這個報錯是提示你沒有gcc和cc編譯包

要安裝gcc cc 編譯包,使用yum安裝即可。然後再make、 make install

三、檢查驗證

[root@test1 build]# ll /lib64/libc*
-rwxr-xr-x 1 root root 1926800 Nov 6 2013 /lib64/libc-2.12.so
-rwxr-xr-x 1 root root 9801125 Apr 22 11:19 /lib64/libc-2.15.so
lrwxrwxrwx. 1 root root 18 Oct 10 2018 /lib64/libcap-ng.so.0 -> libcap-ng.so.0.0.0
-rwxr-xr-x. 1 root root 18672 Nov 5 2010 /lib64/libcap-ng.so.0.0.0
lrwxrwxrwx. 1 root root 14 Oct 10 2018 /lib64/libcap.so.2 -> libcap.so.2.16
-rwxr-xr-x 1 root root 19016 Aug 23 2011 /lib64/libcap.so.2.16
-rwxr-xr-x. 1 root root 197064 Nov 6 2013 /lib64/libcidn-2.12.so
-rwxr-xr-x 1 root root 267972 Apr 22 11:19 /lib64/libcidn-2.15.so
lrwxrwxrwx 1 root root 15 Apr 22 11:19 /lib64/libcidn.so.1 -> libcidn-2.15.so
lrwxrwxrwx. 1 root root 17 Oct 10 2018 /lib64/libcom_err.so.2 -> libcom_err.so.2.1
-rwxr-xr-x 1 root root 17256 Aug 13 2013 /lib64/libcom_err.so.2.1
-rwxr-xr-x 1 root root 43392 Nov 6 2013 /lib64/libcrypt-2.12.so
-rwxr-xr-x 1 root root 142947 Apr 22 11:19 /lib64/libcrypt-2.15.so
lrwxrwxrwx. 1 root root 22 Oct 10 2018 /lib64/libcryptsetup.so.1 -> libcryptsetup.so.1.1.0
-rwxr-xr-x 1 root root 97072 Feb 29 2012 /lib64/libcryptsetup.so.1.1.0
lrwxrwxrwx 1 root root 16 Apr 22 11:19 /lib64/libcrypt.so.1 -> libcrypt-2.15.so
lrwxrwxrwx 1 root root 12 Apr 22 11:19 /lib64/libc.so.6 -> libc-2.15.so

我們可以看到2.12版本的舊庫文件依然存在,而且還多了2.15版本的庫文件,而且軟鏈接文件全部指向了2.15版本。

再次確認,發現版本已更新爲2.15版了,無需重啓。
[root@test1 build]# /lib64/libc.so.6
GNU C Library stable release version 2.15, by Roland McGrath et al.
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.
Compiled by GNU CC version 4.4.7 20120313 (Red Hat 4.4.7-23).
Compiled on a Linux 2.6.32 system on 2019-04-22.
Available extensions:
crypt add-on version 2.1 by Michael Glad and others
GNU Libidn by Simon Josefsson
Native POSIX Threads Library by Ulrich Drepper et al
BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html&gt;.

注:
1、不要在 glibc源碼包裏直接執行 ./configure 指令,否則你就等着被虐吧,假如安裝包位置是: /path/to/glibc-2.15,正確的姿勢是再建一級目錄,在那個目錄下執行 ./configure 指令
2、不要將 glibc 安裝到默認的目錄【/usr/local】或者 【任何自定義的目錄】,請務必安裝到【/usr】目錄,否則你就等着被虐吧。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章