实验环境
- 公司使用的Linux服务器越来越多,经常会有个别服务器出现启动引导、文件系统等故障。为了避免出现上述故障时,无法快速定位故障原因与及时处理故障,公司新招的运维人员小王需要提前进行排障演练并熟悉系统内各种日志文件,以便在需要时能够及时修复系统故障。
需求描述
1.日志文件分析
- 在终端t3中尝试以不存在的用户账号lisi进行登录。
- 新建用户账号zhangsan并以此账号在终端tty4中进行登录,第一次输入错误的密码,第二次输入正确的密码。
[root@localhost /]# useradd zhangsan
[root@localhost /]# passwd zhangsan
更改用户 zhangsan 的密码 。
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost /]#
以张三用户进行登录
- 查看前述用户的登录情况记录。
[root@localhost /]# lastb
lisi ssh:notty 192.168.4.1 Thu Jul 7 15:40 - 15:40 (00:00)
lisi ssh:notty 192.168.4.1 Thu Jul 7 15:40 - 15:40 (00:00)
adminstr ssh:notty 192.168.4.1 Thu Jul 7 15:36 - 15:36 (00:00)
adminstr ssh:notty 192.168.4.1 Thu Jul 7 15:36 - 15:36 (00:00)
adminstr ssh:notty 192.168.4.1 Thu Jul 7 15:36 - 15:36 (00:00)
adminstr ssh:notty 192.168.4.1 Thu Jul 7 15:35 - 15:35 (00:00)
adminstr ssh:notty 192.168.4.1 Thu Jul 7 15:35 - 15:35 (00:00)
adminstr ssh:notty 192.168.4.1 Thu Jul 7 15:35 - 15:35 (00:00)
adminstr ssh:notty 192.168.4.1 Thu Jul 7 15:35 - 15:35 (00:00)
btmp begins Thu Jul 7 15:35:07 2022
[root@localhost /]#
[root@localhost /]#
[root@localhost /]#
[root@localhost /]# w
15:41:24 up 7 min, 3 users, load average: 0.01, 0.31, 0.24
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.4.1 15:34 4.00s 0.06s 0.01s w
administ :0 :0 15:35 ?xdm? 25.87s 0.17s /usr/libexec/gnome-session-binary --session gnome-classic
zhangsan pts/1 192.168.4.1 15:41 8.00s 0.03s 0.03s -bash
[root@localhost /]#
2.故障模拟及修复
- 备份磁盘sda的MBR扇区到其他硬盘,并练习MBR的恢复操作。
[root@localhost ~]# mkdir /backup
[root@localhost ~]# mount /dev/sda1 /backup
[root@localhost ~]#
[root@localhost ~]# dd if=/dev/sda of=/backup/sda bs=512 count=1
记录了1+0 的读入
记录了1+0 的写出
512字节(512 B)已复制,0.000262109 秒,2.0 MB/秒
[root@localhost ~]#
[root@localhost ~]# dd if=/dev/zero of=/dev/sda bs=512 count=1
记录了1+0 的读入
记录了1+0 的写出
512字节(512 B)已复制,0.000157471 秒,3.3 MB/秒
[root@localhost ~]#
[root@localhost ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):
将使用默认值 41943039
分区 1 已设置为 Linux 类型,大小设为 20 GiB
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xf8558862
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 41943039 20970496 83 Linux
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
正在同步磁盘。
[root@localhost ~]#
[root@localhost ~]#reboot
当出现安装向导界面时,选择“Troubleshooting”选项
进入修复故障界面时,再选择"Rescue a CentOS Linux system"
选择 1 确认并按回车键继续
如图,继续以下的操作
- 通过单用户模式进入Linux操作系统,重设root账号的密码。
重新启动时按Esc键进入急救模式
当出现安装向导界面时,选择“Troubleshooting”选项
进入修复故障界面时,再选择"Rescue a CentOS Linux system"
选择 1 确认并按回车键继续
如图,继续以下的操作
完成此操作后使用exit退出并重启
- 将/boot/gub2/gub cg文件移动至/opt/目录下,重启系统。
[root@localhost ~]# cd /boot/grub2
[root@localhost grub2]# ls
device.map fonts grub.cfg grubenv i386-pc locale
[root@localhost grub2]# mv grub.cfg /opt/
[root@localhost grub2]# ls /opt/
grub.cfg rh
[root@localhost grub2]#
[root@localhost grub2]# ls
device.map fonts grubenv i386-pc locale
[root@localhost grub2]#
重新启动时按Esc键进入急救模式
当出现安装向导界面时,选择“Troubleshooting”选项
进入修复故障界面时,再选择"Rescue a CentOS Linux system"
选择 1 确认并按回车键继续
如图,继续以下的操作