0
点赞
收藏
分享

微信扫一扫

开机启动流程(二)

开机启动流程

[TOC]

救援模式

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

# 1.关机
init 0
halt
poweroff
shutdown -h now

# 2.将系统盘放入光驱中

开机启动流程(二)_centos

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

开机启动流程(二)_centos_02

开机启动流程(二)_nginx_03

按方向键选择Boot

开机启动流程(二)_nginx_04

方向键(上下)选到CD-ROM Drive,按shift+把它调到第一行

开机启动流程(二)_开机自启_05

然后按f10,保存退出,选择yes

开机启动流程(二)_centos_06

进入安装系统的界面,选择救援模式

开机启动流程(二)_nginx_07

选择进入救援模式

开机启动流程(二)_nginx_08

开机启动流程(二)_nginx_09

输入1就是选择继续,然后回车

开机启动流程(二)_centos_10

开机启动流程(二)_centos_11

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

开机启动流程(二)_centos_12

​弄完后记得进入BIOS把Hard那个调回第一行,免得它进来老是从光盘启动​


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

开机启动流程(二)_nginx_13

dd </dev/zero >/dev/sda bs=1 count=446

开机启动流程(二)_nginx_14

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

开机启动流程(二)_nginx_15

# 1.修复扇区
grub2-install /dev/sda

# 2.退出root环境
exit

# 3.重启
reboot

修复grub菜单

开机启动流程(二)_centos_16

先删除
rm -fr /boot/grub2

开机启动流程(二)_开机自启_17

grub菜单已损坏,需要进入救援模式修复

开机启动流程(二)_开机自启_18

​这里在修复grub.cfg配置文件时少写了一个/grub2。加上去就可以了​

# 1.修复扇区
grub2-install /dev/sda

# 1.5 重置grub.cfg配置文件
grub2-mkconfig -o /boot/grub2/grub.cfg

# 2.退出root环境
exit

# 3.重启
reboot

systemd管理服务

开机启动流程(二)_开机自启_19

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 ~]# 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
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

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...

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:不允许开机自启

# 5.如果启动脚本被修改,重新加载启动脚本

C7:
systemctl daemon-reload


举报

相关推荐

0 条评论