寫在開篇
為了在線上安裝環(huán)境依賴,給glibc庫升級,由于線上環(huán)境libc.so版本低,不支持安裝,所以手賤把動態(tài)庫中的libc.so.6給移走了,直接導(dǎo)致Linux系統(tǒng)崩潰,系統(tǒng)癱瘓,所有用戶均被強制退出。 意識到缺少對libc.so的認識,以為跟普通的lib包類似,直接把新版的so軟連過去就可以滿足安裝和升級,現(xiàn)在哦豁……. 軟鏈不軟鏈已經(jīng)不重要了,反正腿是軟趴趴的。
1、什么是libc.so
libc.so.6 是很基礎(chǔ)的庫(glibc),是軟連接到在Linux系統(tǒng)中基本的命令,有很多可執(zhí)行文件都會依賴這個共享庫。當不小心把這個庫改名字或者移走了,都會導(dǎo)致不同程度的異常,可以借助LD_PRELOAD變量和”ldconfig”命令來恢復(fù)這個共享庫。前提是終端沒有斷開的情況下操作。 libc.so.6是一個類似于WINDOWS下的一個快捷指向型的文件,而 linux有兩種庫,分別為:glibc、libc
- 說明
2、操作流程
- 作系統(tǒng)版本是:Red Hat Enterprise Linux Server release 6.8
1、問題出現(xiàn)
因為筆者這里是直接在生產(chǎn)環(huán)境上操作,當時是做軟連接沒成功,報錯:文件已存在,軟連接失敗。于是我們就想著把它給移走。還沒來得及做新軟鏈就直接導(dǎo)致報錯。
- 基本上非系統(tǒng)命令都有這一條 libc.so.6 => /lib64/libc.so.6 ,因此libc.so.6至關(guān)重要,絕對不能刪,不能改名,不能移走,能不能覆蓋就不知道了,想作死的可以試試
[root@IDC-Redhat 6.8]# ln -s /home/david/libc-2.17.so /lib64/libc.so.6ln: creating symbolic link `/lib64/libc.so.6′: File exists[root@IDC-Redhat 6.8]# mv /lib64/libc.so.6 .who: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directoryawk: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directorydate: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory[root@IDC-Redhat 6.8]#
當時就嚇尿了,生產(chǎn)環(huán)境被我玩壞了,怎么破。后來查原因才知道很多命令都依賴glibc,我把它的軟鏈接移走了系統(tǒng)找不到此庫,那肯定玩完。
- 注意:出現(xiàn)這樣的情況只要不關(guān)機重啟,就不會影響業(yè)務(wù)運行,不夠一定要注意磁盤的使用情況。
- 終端輸入用戶名后回車ENTER,直接提示以下報錯,無法登錄。
2、嘗試單點登入,會出現(xiàn)卡界面情況。如圖:
單用戶模式已經(jīng)救不回來了,本來就是一個無知的少年,現(xiàn)在更是雪上加霜。
3、解決問題
當時執(zhí)行命令誤操作之后,只要不斷開遠程連接還有挽回的余地。但遠程異常斷開連接之后很多人就沒有轍了。只能嘗試急救模式Rescue mode
[root@IDC-Redhat 6.8 ~]# mv /lib64/libc.so.6 .who: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directoryawk: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directorydate: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory[root@IDC-Redhat 6.8 ~]# LD_PRELOAD=/lib64/libc-2.12.so ln -s /lib64/libc-2.12.so /lib64/libc.so.6[root@IDC-Redhat 6.8 ~]# lltotal 120492-rw-r–r–. 1 root root 123361280 Apr 14 23:54 all.tar-rw——-. 1 root root 1098 Apr 14 23:21 anaconda-ks.cfg-rw-r–r–. 1 root root 8835 Apr 14 23:21 install.log-rw-r–r–. 1 root root 3384 Apr 14 23:21 install.log.sysloglrwxrwxrwx. 1 root root 12 Apr 14 23:20 libc.so.6 -> libc-2.12.so[root@IDC-Redhat 6.8 ~]# mvmv: missing file operandTry `mv –help’ for more information.[root@IDC-Redhat 6.8 ~]#
- 說明:LD_PRELOAD允許你定義在程序運行前優(yōu)先加載的動態(tài)鏈接庫,因此在使用ln前就加載了lib庫,而不是等到使用ln時加載,這樣就能臨時使用命令了
2.也可以使用ldconfid命令來恢復(fù)
[root@IDC-Redhat 6.8 ~]# mv /lib64/libc.so.6 .who: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directoryawk: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directorydate: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory[root@IDC-Redhat 6.8 ~]#ldconfid[root@IDC-Redhat 6.8 ~]# lltotal 120492-rw-r–r–. 1 root root 123361280 Apr 14 23:54 all.tar-rw——-. 1 root root 1098 Apr 14 23:21 anaconda-ks.cfg-rw-r–r–. 1 root root 8835 Apr 14 23:21 install.log-rw-r–r–. 1 root root 3384 Apr 14 23:21 install.log.sysloglrwxrwxrwx. 1 root root 12 Apr 14 23:20 libc.so.6 -> libc-2.12.so
4、如果遠程連接已經(jīng)退出,只能使用急救模式嘗試修復(fù)。首先準備好系統(tǒng)安裝盤,使用安裝盤啟動系統(tǒng)。
1、選擇第三個選項:Rescue installed system
2、選擇語言和鍵盤(默認配置):
3、稍等一會兒會出現(xiàn)要不要設(shè)置網(wǎng)絡(luò),一般來說網(wǎng)絡(luò)沒問題就不用設(shè)置了,我這里選擇No:
4、rescue模式選項:
- Continue, 救援模式程序會自動查找系統(tǒng)中已有的文件系統(tǒng),并把他們掛載到/mnt/sysimage目錄下。
- Read-Only,則會以只讀的方式掛載已有的文件系統(tǒng)。
- Skip,則需要自己手動掛載。
- Advanced ,高級選項。
5、原系統(tǒng)掛載路徑/mnt/sysimage,如果想獲得原系統(tǒng)root環(huán)境,執(zhí)行行命令:chroot /mnt/sysimage 即可。
6、直接選擇shell start shell 進入shell 命令行
7、因為執(zhí)行過這個命令 “mv /lib64/libc.so.6 .” ,導(dǎo)致執(zhí)行chroot /mnt/sysimge會報錯:
8、退出shell& reboot 重啟主機就OK啦
本文轉(zhuǎn)載于:業(yè)內(nèi)同行盆友來稿:對libc.so下毒手引發(fā)的慘痛血案,圍觀大型翻車現(xiàn)場…