写在开篇

为了在线上装置环境依赖,给glibc库降级,因为线上环境libc.so版本低,不反对装置,所以手贱把动静库中的libc.so.6给移走了,间接导致Linux零碎解体,零碎瘫痪,所有用户均被强制退出。
意识到短少对libc.so的意识,认为跟一般的lib包相似,间接把新版的so软连过来就能够满足装置和降级,当初哦豁....... 软链不软链曾经不重要了,反正腿是软趴趴的。

1、什么是libc.so

libc.so.6 是很根底的库(glibc),是软连贯到在Linux零碎中根本的命令,有很多可执行文件都会依赖这个共享库。当不小心把这个库改名字或者移走了,都会导致不同水平的异样,能够借助LD_PRELOAD变量和"ldconfig"命令来复原这个共享库。前提是终端没有断开的状况下操作。
libc.so.6是一个相似于WINDOWS下的一个快捷指向型的文件,而 linux有两种库,别离为:glibc、libc
  • 阐明
  • libc 是Linux下的ANSI C 函数库;
  • glibc 是Linux下的GUN C 函数库:

2、操作流程

  • 作零碎版本是:Red Hat Enterprise Linux Server release 6.8
1、问题呈现
因为笔者这里是间接在生产环境上操作,过后是做软连贯没胜利,报错:文件已存在,软连贯失败。于是咱们就想着把它给移走。还没来得及做新软链就间接导致报错。
  • 基本上非系统命令都有这一条 libc.so.6 => /lib64/libc.so.6 ,因而libc.so.6至关重要,相对不能删,不能改名,不能移走,能不能笼罩就不晓得了,想作死的能够试试

    [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]# 
    过后就吓尿了,生产环境被我玩坏了,怎么破。起初查起因才晓得很多命令都依赖glibc,我把它的软链接移走了零碎找不到此库,那必定玩完。
  • 留神:呈现这样的状况只有不关机重启,就不会影响业务运行,不够肯定要留神磁盘的应用状况。
  • 终端输出用户名后回车ENTER,间接提醒以下报错,无奈登录。

2、尝试单点登入,会呈现卡界面状况。如图:

单用户模式曾经救不回来了,原本就是一个无知的少年,当初更是雪上加霜。
3、解决问题
过后执行命令误操作之后,只有一直开近程连贯还有挽回的余地。但近程异样断开连接之后很多人就没有辙了。只能尝试急救模式Rescue mode
  1. 如果过后近程连贯会话放弃,能够尝试应用以下命令:

    [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 ~]# 
  2. 阐明:LD_PRELOAD容许你定义在程序运行前优先加载的动态链接库,因而在应用ln前就加载了lib库,而不是等到应用ln时加载,这样就能长期应用命令了
  3. 也能够应用ldconfid命令来复原

    [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、如果近程连贯曾经退出,只能应用急救模式尝试修复。首先筹备好零碎安装盘,应用安装盘启动零碎。
  1. 抉择第三个选项:Rescue installed system

  1. 抉择语言和键盘(默认配置):

  1. 稍等一会儿会呈现要不要设置网络,一般来说网络没问题就不必设置了,我这里抉择No:

  1. rescue模式选项:
    1) Continue, 救济模式程序会主动查找零碎中已有的文件系统,并把他们挂载到/mnt/sysimage目录下。
    2) Read-Only,则会以只读的形式挂载已有的文件系统。
    3) Skip,则须要本人手动挂载。
    4) Advanced ,高级选项。

  1. 原零碎挂载门路/mnt/sysimage,如果想取得原零碎root环境,执行行命令:chroot /mnt/sysimage 即可。

  1. 间接抉择shell start shell 进入shell 命令行

  1. 因为执行过这个命令 "mv /lib64/libc.so.6 ." ,导致执行chroot /mnt/sysimge会报错:

  1. 退出shell& reboot 重启主机就OK啦!
    本文转载于:https://mp.weixin.qq.com/s/JI...