系统开机启动流程
1. 按下电源
2. BIOS自检 检查磁盘,内存,检查物理硬件
3. MBR引导 主引导记录 0磁头0磁道1扇区
4. GRUB菜单 内核的选项参数
5. 加载kernel内核
6. 启动系统管理systemd
7. 读取运行级别 多用户 3
[root@qls ~]# ll /etc/systemd/system/default.target
8. 系统初始化
[root@qls ~]# ll /usr/lib/systemd/system/sysinit.target
9. 启动系统服务 并行启动
10. getty文件,进入login登录界面
[root@qls ~]# ll /usr/lib/systemd/system/getty.target
centos-6与centos-7的启动区别
init systemd
串行 并行
开机启动慢 开机启动快
容易出故障 不容易出现故障
系统运行级别
[root@qls ~]# ll /usr/lib/systemd/system/runlevel*.target
lrwxrwxrwx. 1 root root 15 Nov 18 10:07 /usr/lib/systemd/system/runlevel0.target -> poweroff.target
0 poweroff 关机
lrwxrwxrwx. 1 root root 13 Nov 18 10:07 /usr/lib/systemd/system/runlevel1.target -> rescue.target
1 rescue 救援模式,单用户模式
lrwxrwxrwx. 1 root root 17 Nov 18 10:07 /usr/lib/systemd/system/runlevel2.target -> multi-user.target
2 multi-user 多用户
lrwxrwxrwx. 1 root root 17 Nov 18 10:07 /usr/lib/systemd/system/runlevel3.target -> multi-user.target
3 multi-user 多用户 ***
lrwxrwxrwx. 1 root root 17 Nov 18 10:07 /usr/lib/systemd/system/runlevel4.target -> multi-user.target
4 multi-user 多用户 #centos-6 没有应用
lrwxrwxrwx. 1 root root 16 Nov 18 10:07 /usr/lib/systemd/system/runlevel5.target -> graphical.target
5 graphical 图形化模式,桌面模式
lrwxrwxrwx. 1 root root 13 Nov 18 10:07 /usr/lib/systemd/system/runlevel6.target -> reboot.target
6 reboot 重启的模式
运行级别的管理
查看系统当前运行级别 [root@qls ~]# systemctl get-default
multi-user.target
修改运行级别
[root@qls ~]# systemctl set-default graphical.target
[root@qls ~]# systemctl get-default
graphical.target
[root@qls ~]# systemctl set-default runlevel3.target
[root@qls ~]# systemctl get-default
systemd系统管理
system daemon 守护进程
系统启动脚本的管理目录
[root@qls ~]# ll /usr/lib/systemd/system
系统管理的目录
[root@qls ~]# ll /etc/systemd/system
系统执行的时候产生的一些文件
[root@qls ~]# ll /run/systemd/system/
systemd怎么管理
管理服务
[root@qls ~]# systemctl start nginx #启动
[root@qls ~]# systemctl status nginx #查看状态
[root@qls ~]# systemctl stop nginx #停止
[root@qls ~]# systemctl restart nginx #重启
[root@qls ~]# systemctl reload nginx #重载,平滑重启
[root@qls ~]# systemctl mask nginx #禁用服务
[root@qls ~]# systemctl unmask nginx #解除禁用
[root@qls ~]# systemctl enable nginx #开机自启动
[root@qls ~]# systemctl disable nginx #开机不启动
status 状态信息
loaded #系统服务已经完成一次加载
disabled #开机不启动
enabled #开机自启动
active (running) #正在运行
active (exited) #系统服务只运行一次就停止了
active (waiting) #系统已经加载,但是需要等待某一个事件才能继续运行
inactive #停止状态
failed #失败
系统的日志
[root@qls ~]# journalctl -xe #快速的到达上一个服务启动的位置
[root@qls ~]# journalctl -f #实时的查看系统日志
[root@qls ~]# journalctl -p err #根据日志级别查看
#日志级别
alert debug err notice crit emerg info warning
#查看指定服务的日志
[root@qls ~]# journalctl -u nginx
系统主机名
查看系统主机名
[root@qls ~]# hostname
qls
[root@qls ~]# hostnamectl
Static hostname: qls
Icon name: computer-vm
Chassis: vm
Machine ID: c80d0ccbcea4452183ba8ad2eff7a159
Boot ID: 6faafe294ab1431ea206f11d837d876b
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1062.4.3.el7.x86_64
Architecture: x86-64
修改系统主机名 ,重新登录生效
[root@qls ~]# hostnamectl set-hostname web
[root@qls ~]# bash
bash
[root@web ~]#
主机名相关配置文件
[root@web ~]# cat /etc/hostname web
字符集的管理
#查看字符集
[root@web ~]# echo $LANG
en_US.UTF-8
#修改字符集,重新登录生效(登录式shell)
[root@web ~]# localectl set-locale LANG=zh_CN.UTF-8
#字符集相关配置文件
[root@web ~]# cat /etc/locale.conf
LANG=zh_CN.UTF-8
系统单用户模式
两种不同的命令规则
biosdevname
net.ifnames
centos-7中
biosdevname=0 net.ifnames=1
命令行修改网卡名称
#修改配置文件名称
[root@qls ~]# mv /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-eth0
#修改配置文件中的设备名称
[root@qls ~]# sed -i 's#ens33#eth0#g' /etc/sysconfig/network-scripts/ifcfg-eth0
#设置命名规则
[root@qls ~]# vim /etc/sysconfig/grub
GRUB_CMDLINE_LINUX="net.ifnames=0 rhgb quiet"
#重新加载
[root@qls ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1062.4.3.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1062.4.3.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-c80d0ccbcea4452183ba8ad2eff7a159
Found initrd image: /boot/initramfs-0-rescue-c80d0ccbcea4452183ba8ad2eff7a159.img
done
#重启生效
[root@qls ~]# reboot
#检查
[root@qls ~]# ip a s eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:d0:a4:e9 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.100/24 brd 10.0.0.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::9d45:c974:b03f:2913/64 scope link noprefixroute
valid_lft forever preferred_lft forever