天天看點

systemd--systemctl

systemd

POST---BOOT Sequence ---bootloader---kernel+initramfs(initrd)--rootfs---/sbin/init

init :

centos5:sysv init

centos6:unstart

centos7:systemd

systemd新特性:

系統引導時實作服務并行啟動;

按需激活程序

系統狀态快照

基于依賴關系定義服務控制邏輯

核心概念:unit

配置檔案進行辨別和配置;檔案中主要包含系統服務,監聽socket,儲存系統快照以及其他與init相關的資訊

儲存至:/usr/lib/systemd/system

/run/systemd/system

/etc/systemd/system

ls -ltr /lib/systemd/system/runlevel*.target

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

targe 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

檢視級别:

runleve ==> systemctl list-units -type target --all

擷取預設運作級别:

/etc/inittab ==> systemctl get-default

設定預設運作級别:

/etc/inittab ==> systemctl set-default multi-user.target

 或者

 ln -svf /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target

 ln -svf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

切換至緊急救援模式:

systemctl rescue

切換至emergency模式:

systemctl emergency

其他常用指令:

關機:systemctl halt ,systemctl poweroff

重新開機:systemctl reboot

挂起:systemctl suspend

快照:systemctl hibernate

快照并挂起:systemctl hybird-sleep

     本文轉自阿倫艾弗森 51CTO部落格,原文連結:http://blog.51cto.com/perper/1955152,如需轉載請自行聯系原作者

上一篇: httpd
下一篇: SELinux