POST –> Boot Sequence –> Bootloader –> kernel + initramfs(initrd) –> rootfs –> /sbin/init
init:
CentOS 5: SysV init
CentOS 6: Upstart
CentOS 7: Systemd
Systemd新特性:
系統引導時實現服務并行啟動;
按需激活進程;
系統狀態快照;
基于依賴關系定義服務控制邏輯;
核心概念:unit
配置文件進行標識和配置;文件中主要包含了系統服務、監聽socket、保存的系統快照以及其它與init相關的信息;
保存至:
/usr/lib/systemd/system
/run/systemd/system
/etc/systemd/system
Unit的類型:
Service unit: 文件擴展名為.service, 用于定義系統服務;
Target unit: 文件擴展名為.target,用于模擬實現“運行級別”;
Device unit: .device, 用于定義內核識別的設備;
Mount unit: .mount, 定義文件系統掛載點;
Socket unit: .socket, 用于標識進程間通信用的socket文件;
Snapshot unit: .snapshot, 管理系統快照;
Swap unit: .swap, 用于標識swap設備;
Automount unit: .automount,文件系統的自動掛載點;
Path unit: .path,用于定義文件系統中的一個文件或目錄;
關鍵特性:
基于socket的激活機制:socket與服務程序分離;
基于bus的激活機制:
基于device的激活機制:
基于path的激活機制:
系統快照:保存各unit的當前狀態信息于持久存儲設備中;
向后兼容sysv init腳本;
不兼容:
systemctl命令固定不變
非由systemd啟動的服務,systemctl無法與之通信
管理系統服務:
CentOS 7: service unit
注意:能兼容早期的服務腳本
命令:systemctl COMMAND name.service
啟動:service name start ==> systemctl start name.service
停止:service name stop ==> systemctl stop name.service
重啟:service name restart ==> systemctl restart name.service
狀態:service name status ==> systemctl status name.service
條件式重啟:service name condrestart ==> systemctl try-restart name.service
重載或重啟服務:systemctl reload-or-restart name.service
重載或條件式重啟服務:systemctl reload-or-try-restart name.service
禁止設定為開機自啟:systemctl mask name.service
取消禁止設定為開機自啟:systemctl unmask name.service
查看某服務當前激活與否的狀態:systemctl is-active name.service
查看所有已經激活的服務:
systemctl list-units –type service
查看所有服務:
systemctl list-units –type service –all
chkconfig命令的對應關系:
設定某服務開機自啟:chkconfig name on ==> systemctl enable name.service
禁止:chkconfig name off ==> systemctl disable name.service
查看所有服務的開機自啟狀態:
chkconfig –list ==> systemctl list-unit-files –type service
查看服務是否開機自啟:systemctl is-enabled name.service
其它命令:
查看服務的依賴關系:systemctl list-dependencies name.service
target units:
unit配置文件:.target
運行級別:
0 ==> runlevel0.target, poweroff.target
1 ==> runlevel1.target, rescue.target
2 ==> runlevel2.target, multi-user.target
3 ==> runlevel3.target, multi-user.target
4 ==> runlevel4.target, multi-user.target
5 ==> runlevel5.target, graphical.target
6 ==> runlevel6.target, reboot.target
級別切換:
init N ==> systemctl isolate name.target
查看級別:
runlevel ==> systemctl list-units –type target
獲取默認運行級別:
/etc/inittab ==> systemctl get-default
修改默認級別:
/etc/inittab ==> systemctl set-default name.target
切換至緊急救援模式:
systemctl rescue
切換至emergency模式:
systemctl emergency
其它常用命令:
關機:systemctl halt、systemctl poweroff
重啟:systemctl reboot
掛起:systemctl suspend
快照:systemctl hibernate
快照并掛起:systemctl hybrid-sleep
原創文章,作者:kang,如若轉載,請注明出處:http://www.www58058.com/77624