Linux卸载软件,误删了系统libselinux.SO.1文件,执行命令,报如下错误:
[root@host-01 ~]# error while loading shared libraries: libselinux.so.1: cannot open shared object file: No such file or directory
此时ssh远程无法连接,大部分系统命令无法执行,一时间慌了神,赶紧百度有没有解决办法,好在找到大神分享的解决办法,非常感谢! 现将我解决的步骤分享和记录,避免再次犯同样的错误。
解决方案:使用rsync服务同步文件进行恢复(此时rsync命令可以使用)
1.找一台正常的服务器,搭建rsync服务端,并推送文件(误删文件服务器和该正常服务器Linux版本相同)
1)编辑配置文件 vim /etc/rsyncd.conf :
uid = rsync #运行进程的身份。
gid = rsync #运行进程的组。
port =873 #监听端口。
hosts allow =*
#允许同步客户端的IP地址,可以是网段,或者用*表示所有 192.168.1.0/24或192.168.1.0/255.255.255.0
use chroot = yes #是否囚牢,锁定家目录,rsync被黑之后,黑客无法在rsync运行 的家目录之外创建文件,选项设置为yes。
max connections =200 #最大连接数。
read only = false #是否只读,false关闭
list = false #是否允许客户端查看备份内容, 一般不允许。
#以下两个文件需手动创建
auth users = rsyncuser #备份的用户(虚拟用户,不存在系统中)。
secrets file =/etc/rsync.passwd #存放用户的密码文件,格式是 用户名:密码 ,同样是创建。
motd file =/etc/rsyncd.motd #客户端登陆之后弹出的消息,需要创建。
#以下三个文件会自动创建
pid file =/var/run/rsyncd.pid #进程PID,自动生成。
lock file =/var/run/rsync.lock #指max connectios参数的锁文件。
log file =/var/log/rsyncd.log #日志文件位置。
[ftp] #共享模块名称。
path =/home/ftp #路径。
comment = ftp export area #描述。
2)创建rsync服务用户:
[root@host-01 ~]# useradd rsync -s /sbin/nologin
3)创建提示文件和用户密码:
#编辑欢迎信息文件。
[root@host-01 ~]# echo "Welcome to Backup Server" > /etc/rsyncd.motd
[root@host-01 ~]# vim /etc/rsync.passwd #创建并编写密码文件。
rsyncuser:123456 #格式为 用户名称:密码。
[root@host-01 ~]# chmod 600 /etc/rsync.passwd #注意密码文件权限必须是600,否则身份验证会失败。
4)创建备份目录并修改权限
[root@host-01 ~]# mkdir /home/ftp
[root@host-01 ~]# chown rsync:rsync /home/ftp #所有者与所属组需对应rsync配置文件的uid与gid
5)启动rsync服务
[root@host-01 ~]# systemctl start rsyncd
6)推送数据,将该正常服务器的libselinux.SO.1文件推送到共享目录下 /home/ftp/
[root@host-01 ~]# rsync -avz /lib64/libselinux.so.1 rsyncuser@host-01::ftp
welcome to backup server
Password: #输入密码:123456
sending incremental file list
libselinux.so.1
sent 74044 bytes received 27 bytes 21163.14 bytes/sec
total size is 155752 speedup is 2.10
2.用误删文件服务器拉取文件
[root@host-02 ~]# rsync -aPv rsyncuser@host-01::ftp /lib64
welcome to backup server
Password:
receiving incremental file list
./
libselinux.so.1
155752 100% 49.51MB/s 0:00:00 (xfer#1, to-check=0/2)
sent 84 bytes received 155964 bytes 44585.14 bytes/sec
total size is 155752 speedup is 1.00
至此误删文件服务器可以正常执行系统命令,ssh远程连接也恢复正常。