救援模式

  • 救援模式需要有系统盘,进入安装系统的界面之后才能进入救援模式

1.关机

关机方式
init 0
halt
poweroff
shutdown -h now

2.将系统盘放入光驱中

救援模式_开机自启

3.进入BIOS界面

将系统启动的顺序,改为从光盘启动
方法一:
开机时,不断按f2
方法二:
在电源里面点击,进入固件

救援模式_centos_02

救援模式_centos_03

  • 选择boot

救援模式_centos_04

  • 把CD-ROM启动顺序排到第一个(按+置顶)

救援模式_重启_05

  • 按f10保存并退出 ->选择yes

救援模式_开机自启_06

  • 进入安装系统的界面

救援模式_centos_07

  • 进入救援模式

救援模式_开机自启_08

救援模式_centos_09

  • 输入1

救援模式_centos_10

# 1.先输入回车
# 2.获取root的环境(root权限)
chroot /mnt/sysimage

案例1-损坏系统扇区(前512字节)

救援模式_重启_11

举例,故意损坏(请勿模仿)
dd </dev/zero >/dev/sda bs=1 count=446

损坏之后的界面

救援模式_centos_12

  • 扇区损坏,需要进入救援模式修复扇区

救援模式_centos_13

# 1.修复扇区
grub2-install /dev/sda
# 2.退出root环境
exit
# 3.重启
reboot

修复grub菜单

救援模式_centos_14

# 1.修复扇区
grub2-install /dev/sda
# 1.5 重置grub.cfg配置文件
grub2-mkconfig -o /boot/grub2/grub.cfg
# 2.退出root环境
exit
# 3.重启
reboot

systemd管理服务

syetemd是system daemon的守护进程,systemd可以为系统的启动和管理提供一套完整的解决方案

救援模式_centos_15

systemd的优势

1.最新系统都采用systemd管理(RedHat7,CentOS7,Ubuntu15...)

2.CentOS7 支持开机并行启动服务,显著提高开机启动效率

3.CentOS7关机只关闭正在运行的服务,而CentOS6,全部都关闭一次。

4.CentOS7服务的启动与停止不在使用脚本进行管理,也就是/etc/init.d下不在有脚本。

5.CentOS7使用systemd解决原有模式缺陷,比如原有service不会关闭程序产生的子进程。

systemd相关配置文件

# 系统中所有服务启动的脚本存放路径
C7:
/usr/lib/systemd/system/
nginx.service
C6:
/etc/init.d/
# 系统运行级别相关目录
C7:
/etc/systemd/system
C6:
[root@localhost <sub>]# ll /etc/rc*.d -d
lrwxrwxrwx. 1 root root 10 May 7 10:46 /etc/rc0.d -> rc.d/rc0.d
lrwxrwxrwx. 1 root root 10 May 7 10:46 /etc/rc1.d -> rc.d/rc1.d
lrwxrwxrwx. 1 root root 10 May 7 10:46 /etc/rc2.d -> rc.d/rc2.d
lrwxrwxrwx. 1 root root 10 May 7 10:46 /etc/rc3.d -> rc.d/rc3.d
lrwxrwxrwx. 1 root root 10 May 7 10:46 /etc/rc4.d -> rc.d/rc4.d
lrwxrwxrwx. 1 root root 10 May 7 10:46 /etc/rc5.d -> rc.d/rc5.d
lrwxrwxrwx. 1 root root 10 May 7 10:46 /etc/rc6.d -> rc.d/rc6.d
# 默认运行级别需要开机自启的服务存放目录
C7:
/etc/systemd/system/multi-user.target.wants/
auditd.service -> /usr/lib/systemd/system/auditd.service
crond.service -> /usr/lib/systemd/system/crond.service
irqbalance.service -> /usr/lib/systemd/system/irqbalance.service
NetworkManager.service -> /usr/lib/systemd/system/NetworkManager.service
nfs-client.target -> /usr/lib/systemd/system/nfs-client.target
nginx.service -> /usr/lib/systemd/system/nginx.service
postfix.service -> /usr/lib/systemd/system/postfix.service
remote-fs.target -> /usr/lib/systemd/system/remote-fs.target
rhel-configure.service -> /usr/lib/systemd/system/rhel-configure.service
rpcbind.service -> /usr/lib/systemd/system/rpcbind.service
rsyslog.service -> /usr/lib/systemd/system/rsyslog.service
sshd.service -> /usr/lib/systemd/system/sshd.service
sysstat.service -> /usr/lib/systemd/system/sysstat.service
tuned.service -> /usr/lib/systemd/system/tuned.service
vmtoolsd.service -> /usr/lib/systemd/system/vmtoolsd.service
C6:
/etc/rc3.d/
K01smartd -> ../init.d/smartd
K10psacct -> ../init.d/psacct
K10saslauthd -> ../init.d/saslauthd
K15svnserve -> ../init.d/svnserve
K50netconsole -> ../init.d/netconsole
K74ntpd -> ../init.d/ntpd
K75ntpdate -> ../init.d/ntpdate
K75quota_nld -> ../init.d/quota_nld
K87restorecond -> ../init.d/restorecond
K89rdisc -> ../init.d/rdisc
K99rngd -> ../init.d/rngd
S01sysstat -> ../init.d/sysstat
S02lvm2-monitor -> ../init.d/lvm2-monitor
S08ip6tables -> ../init.d/ip6tables
S08iptables -> ../init.d/iptables
S10network -> ../init.d/network
S11auditd -> ../init.d/auditd
S12rsyslog -> ../init.d/rsyslog
S13cpuspeed -> ../init.d/cpuspeed
S13irqbalance -> ../init.d/irqbalance
S15mdmonitor -> ../init.d/mdmonitor
S20kdump -> ../init.d/kdump
S22messagebus -> ../init.d/messagebus
S25blk-availability -> ../init.d/blk-availability
S25netfs -> ../init.d/netfs
S26acpid -> ../init.d/acpid
S26haldaemon -> ../init.d/haldaemon

systemd管理服务的命令

# 1.启动服务
C6:
/etc/init.d/服务名 start
service 服务名 start
C7:
systemctl start 服务名
service 服务名 start
# 2.停止服务
C6:
/etc/init.d/服务名 stop
service 服务名 stop
C7:
systemctl stop 服务名
service 服务名 stop
# 3.服务重启
C6:
/etc/init.d/服务名 restart
service 服务名 restart
C7:
systemctl restart 服务名
service 服务名 restart
# 4.服务重新加载
C6:
/etc/init.d/服务名 reload
service 服务名 reload
C7:
systemctl reload 服务名
service 服务名 reload
# 5.检查服务的启动状态
C6:
[root@localhost <sub>]# /etc/init.d/sshd status
openssh-daemon (pid 1508) is running...
S26udev-post -> ../init.d/udev-post
S55sshd -> ../init.d/sshd
S80postfix -> ../init.d/postfix
S82abrt-ccpp -> ../init.d/abrt-ccpp
S82abrtd -> ../init.d/abrtd
S90crond -> ../init.d/crond
S95atd -> ../init.d/atd
S99local -> ../rc.local
C7:
systemctl status sshd
# 6.判断服务是否在运行
[root@localhost </sub>]# systemctl is-active sshd
active
[root@localhost <sub>]# systemctl stop sshd
[root@localhost </sub>]# systemctl is-active sshd
inactive
# 7.禁用某个服务
[root@localhost <sub>]# systemctl mask crond
# 8.取消禁用某个服务
[root@localhost </sub>]# systemctl unmask crond

开机自启服务管理

# 1.查看开机自启的服务有哪些
C6:
[root@localhost <sub>]# chkconfig
C7:
[root@localhost </sub>]# systemctl list-unit-files
# 2.设置开机自启动
C6:
[root@localhost <sub>]# chkconfig sshd on (默认 2 3 4 5 运行级别都自启)
[root@localhost </sub>]# chkconfig |grep sshd
sshd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@localhost <sub>]# chkconfig sshd on
[root@localhost </sub>]# chkconfig |grep sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@localhost <sub>]# chkconfig sshd off
[root@localhost </sub>]# chkconfig |grep sshd
sshd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@localhost <sub>]# chkconfig sshd --level 3 on
[root@localhost </sub>]# chkconfig |grep sshd
sshd 0:off 1:off 2:off 3:on 4:off 5:off 6:off
C7:
[root@localhost <sub>]# systemctl enable sshd
# 3.关闭开机自启
C6:
[root@localhost </sub>]# chkconfig sshd off
C7:
[root@localhost <sub>]# systemctl disable sshd
# 4.查看指定服务是否开机自启
C6:
[root@localhost </sub>]# chkconfig --list sshd
sshd 0:off 1:off 2:off 3:on 4:off 5:off 6:off
C7:
[root@localhost ~]# systemctl is-enabled nginx
enabled:允许开机自启
disabled:不允许开机自启
# 7.如果启动脚本被修改,重新加载启动脚本
C7:
systemctl daemon-reload