Cent7.5误删除libselinux.so.1文件后的修复方法

                                                        Linux中误删除libselinux恢复方法
操作环境:CentOS7.5

背景:安装openssl-devel时报错:
  Error: Protected multilib versions: libselinux-2.5-12.1.el7.x86_64 != libselinux-2.5-14.1.el7.x86_64卸载了libselinux-2.5-14.1.el7.x86_64导致服务器故障。 rpm -e --nodeps libselinux-2.5-14.1.el7.x86_64

执行命令报:

ls: error while loading shared libraries: libselinux.so.1: cannot open shared object file: No such file or directory

修复方法:需要拷贝一个libselinux.so.1文件到/lib64/目录下

  一、不关机修复

    前提条件:需要服务器安装了rsync同时防火墙需要关掉或者放通了873端口。

1、在故障服务器启动一个rsync

# 故障服务器配置
cat > /etc/rsyncd.conf <<EOF
port = 873
uid = root
gid = root
use chroot = yes
read only = yes
 
#limit access to private LANs
max connections =10
pid file = /var/run/rsyncd.pid
log file = /var/log/rsyncd.log
timeout = 300
 
[tmp]
path = /tmp/
list = yes
auth users = root
uid = root
gid = root
 
exclude = *.xml *.properties *.log
secrets file = /etc/rsyncd.pass
read only = no
EOF


echo "root:passwd" > /etc/rsyncd.pass
chmod 600 /etc/rsyncd.pass


# 启动服务
rsync --daemon --config=/etc/rsyncd.conf
# 查看服务是否启动
cat /var/run/rsyncd.pid
# 停止服务
cat /var/run/rsyncd.pid | xargs kill -9 && rm -rf /var/run/rsyncd.pid

 2、在另一台CentOS7.5服务器启动一个客户端。

echo "passwd" > /etc/rsyncd.pass
chmod 600 /etc/rsyncd.pass
rsync -aPv --port 873 /lib64/libselinux.so.1 ServerIP::tmp

3、在故障服务器把客户端拷贝过来的文件在拷贝到/lib64/

rsync -aPv /tmp/libselinux.so.1 /lib64

二、关机修复

说明:服务器没有安装rsync,需要挂在系统版本镜像,重启服务器进入救援模式。

1、进入救援模式的方法,如图选择Troubleshooting,在选择rescue a CentOS system,输入1获得一个有读写权限的shell。


       

2、重新挂载下系统为读写权限

mount -o remount rw /;mount -o remount rw /mnt/sysimage

3、输入ls /lib64/libc.so.6命令查看是否有该文件(因为是光盘自带的系统,并没有挂载在根目录下,所以该文件没有被删除)

4、找到了所需要的文件,只需要把该文件复制到丢失文件的系统里就可以(系统被挂载到了/mnt/sysimage目录中)

cp /lib64/libc.so.6 /mnt/sysimage/lib64(把文件复制到丢失的文件系统里)

5、重启服务器恢复正常。

6、进入救援模式遇到报错情况处理:

进入以下界面时报:

the rescue environment will now attempt to find your linux installation and mount it under the directory : /mnt/sysimage. you can then make any changes you can choose to mount your file systems read-only instead of read-write by choosing 2 if for some reason this process does not work chroot 2

时不能选择1以读写的权限进入系统,只能选择2以只读的模式进入到系统。

重新挂载一个除了系统版本外的ISO镜像,在进入到救援模式后,选择1以读写的方式进入系统,拷贝libselinux.so.1文件到lib64目录下,在重新挂载系统本身版本ISO后就可以选择1以读写的模式进入系统重新拷贝libselinux.so.1文件。

7、重启进入系统时报:

解决方法:

1、系统启动的时候,按下‘e’键进入grub编辑界面,编辑grub菜单,选择“kernel /vmlinuz-XXXXro root=/dev/vogroup00/logvol00 rhgb quiet” 一栏,按‘e’键进入编辑,在末尾增加enforcing=0,即:
kernel /vmlinuz-XXXXro root=/dev/vogroup00/logvol00 rhgb quiet enforcing=0(其中enforcing=0是需要加上去的,其他不动)
按‘b’键继续引导,正常进入系统。

2、如果系统启动按e不能进入到grub界面,那就是libselinux.so.1文件不兼容导致服务器不能启动上来,需要重新进入救援模式把/mnt/sysimage/lib64/libselinux.so.1删除后重新拷贝一个文件进入重启服务器,正常进入系统。

评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值