救援模式

前提:虚拟机设置已经挂载iso镜像

MBR引导被破坏怎么解决?

1
2
#注:仅演示救援模式清空MBR!!!!!!!!!!!!!
dd < /dev/zero >/dev/sda bs=1 count=446
1
2
3
4
5
6
7
8
9
10
#解决办法
# 1.获取root环境
chroot /mnt/sysimage
# 2.修复MBR
grub2-install /dev/sda
# 3.退出
exit
# 4.重启
reboo
过程如下↓

MBR破坏后启动自动跳到这里

image-20240501105112668

进入救援模式前进入BISO,修改优先CD-ROM启动加载

image-20240501102743250

image-20240501094910948

image-20240501105511762

image-20240501105829470

image-20240501111423160

grub菜单误删怎么解决?

1
2
3
#仅做演示删除gruub菜单!!!!!!!!!!!!
[root@lb01 ~]# rm -fr /boot/grub2
[root@lb01 ~]# reboot

解决过程

1
2
3
4
5
6
7
8
9
10
11
# 1.获取root环境
chroot /mnt/sysimage
# 2.修复磁盘MBR
grub2-install /dev/sda
# 3.修复grub菜单配置文件
grub2-mkconfig -o /boot/grub2/grub.cfg
# 4.退出
exit
# 5.重启
reboot
过程图如下

grub菜单被删启动界面

image-20240501112106766

同样进入救援模式

image-20240501113156619

系统损坏拷贝文件?

1
2
3
4
5
bash-4.2# mkfs.xfs -f /dev/sdc
bash-4.2# mkdir /data
bash-4.2# mount /dev/sdc /data
bash-4.2# cp -a /raid0 /data
bash-4.2# umount /dev/sdb

修改网卡名 了解

image-20240501114139869

image-20240501114157577

1
2
biosdevname=0 net.ifnames=0
net.ifnames=0 #不是dell物理机环境

Systemd 进程管理

1
systemd即为system daemon守护进程,systemd主要解决上文的问题而诞生,systemd的目标是,为系统的启动和管理提供一套完整的解决方案。
1
2
3
4
5
#CentOS6启动
1.启动时间长,init进程是串行启动,只有前一个进程启动完,才会启动下一个进程。
2.启动脚本复杂,初始化完成后,系统会加载很多脚本,脚本都会处理各自的情况,这回让脚本多而复杂。
#CentOS7启动
CtOS7所有进程无论有无依赖关系,都并行启动,当然有很多时候进程并没有真正的启动而是只有一个信号或者说是标记,在真正利用的时候,才会真正启动

image-20240501114955720

1
2
3
4
5
6
#systemd优势
1.最新系统都采用systemd管理(RedHat7,CentOS7,Ubuntu15...)
2.CentOS7 支持开机并行启动服务,显著提高开机启动效率
3.CentOS7关机只关闭正在运行的服务,而CentOS6,全部都关闭一次。
4.CentOS7服务的启动与停止不在使用脚本进行管理,也就是/etc/init.d下不在有脚本。
5.CentOS7使用systemd解决原有模式缺陷,比如原有service不会关闭程序产生的子进程。
相关配置文件 CentOS6 CentOS7
服务启动脚本 /etc/init.d/ /usr/lib/systemd/system/
开机启动服务 /etc/rcN.d/ /etc/systemd/system/

systemd相关命令

启动重启服务

System V init(6系统) systemctl命令(7系统) 作用
service nginx start
/etc/init.d/nginx start
systemctl start nginx.service 启动服务
service nginx stop
/etc/init.d/nginx stop
systemctl stop nginx.service 停止服务
service nginx restart
/etc/init.d/nginx restart
systemctl restart nginx.service 重启服务
service nginx reload
/etc/init.d/nginx reload
systemctl reload nginx.service 重新加载配置(不终止服务)
service nginx status
/etc/init.d/nginx status
systemctl status nginx.servre 查看服务运行状态
systemctl is-active sshd.service 查看服务是否在运行中
systemctl mask nginx.servre 禁止服务运行
systemctl unmask nginx.servre 取消禁止服务运行

设置服务开机自启,查看各级别下服务启动状态

System V init(6系 统) systemctl命令(7系统) 作用
chkconfig nginx on systemctl enable nginx.service 开机自动启动
chkconfig nginx off systemctl disable nginx.service 开机不自动启动
chkconfig —list systemctl list-unit-files 查看各个级别下服务的启动与禁 用
chkconfig —list nginx systemctl is-enabled nginx.service 查看特定服务是否为开机自启动
chkconfig—add nginx systemctl daemon-reload 创建新服务文件或者变更设置
1
2
3
4
5
6
7
8
设置开机自启相当于给启动脚本做个软链接
# CentOS7中开机自启
[root@localhost ~]# systemctl enable sshd
ln -s /usr/lib/systemd/system/sshd.service /etc/systemd/system/multiuser.target.wants/
# 取消开机自启
[root@localhost ~]# systemctl disable sshd
Removed symlink /etc/systemd/system/multi-user.target.wants/sshd.service
rm -f /etc/systemd/system/multi-user.target.wants/sshd.service

systemctl服务状态说明

服务状态 状态说明
loaded 服务单元的配置文件已经被处理
active(running) 服务的一个或多个进程在运行中
active(exited) 一次性运行的服务成功被执行并退出(服务运行后完成任务,相关进程会自动退出)
active(waiting) 服务已经运行但在等待某个事件
inactive 服务没有在运行
enable 服务设定为开机运行
disabled 服务设定为开机不运行
static 服务不能被设定开机启动,但可以由其他服务启动该服务