Systemd服務

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

(0)
kangkang
上一篇 2015-02-28 17:47
下一篇 2015-03-02 14:03

相關推薦

  • N22-第二周作業-對Linux的基礎操作命令的理解及用法示例

    1、Linux上的文件管理類命令都有哪些,其常用的使用方法及其相關示例演示。 Linux上文件管理類命令常用的有:pwd、ls、cd、cp、touch、mv、rm、rmdir   1)pwd:顯示當前工作目錄     2)ls:列出指定目錄下的內容    常用的選項有:   -a:列出目錄中的所有文…

    Linux干貨 2016-08-22
  • RAID磁盤冗余探究

    RAID磁盤冗余探究 RAID的全稱是Redundant Arrays of Inexpensive Disk,可以翻譯為廉價的磁盤冗余陣列。由加利福尼亞大學伯克利分校的一位教授在1988年提出,是一種磁盤管理方式。其產生的初衷是為了降低成本,但是為了達到RAID的功能,其造價并不便宜,所以后來改為Redundant Arrays of Independen…

    2017-08-26
  • 谷歌三大核心技術(三)Google BigTable中文版

    摘要 Bigtable是一個分布式的結構化數據存儲系統,它被設計用來處理海量數據:通常是分布在數千臺普通服務器上的PB級的數據。Google的很多項目使用Bigtable存儲數據,包括Web索引、Google Earth、Google Finance。這些應用對Bigtable提出的要求差異非常大,無論是在數據量上(從URL到網頁到衛星圖像)還是在響應速度上…

    Linux干貨 2015-04-13
  • web服務介紹二)

    apache指令說明:http://httpd.apache.org/docs/2.2/mod/directives.html Listen 172.18.100.67:8081  監聽某個指定地址和端口啟動前檢查一下語法:    httpd -t 如果要監聽多個端口,要多行寫    Listen 80&nb…

    Linux干貨 2017-04-20
  • 萬能的AWK

    awk:文本三劍客之一 #報告生成器,主要用來實現格式化文本輸出,它能夠實現在處理文本文件時對文檔中的某字段有條件顯示并以非常美觀的文本; 它是編程語言的解釋器;它也是一種完整的編程語言,它支持條件判斷、循環、變量、數組、函數等等各種各樣的編程語言所能實現的功能。 用法:awk [options] ‘program’ FILE &#8…

    2017-04-22
  • 文本處理工具

    分頁查看文件內容 less和more命令介紹 分頁查看文件內容:less和more less:一頁一頁地查看文件或STDIN輸出   # less FILE less的快捷鍵:     Ctrl+u:向上翻半屏     Ctrl+d:向下翻…

    Linux干貨 2016-08-07
欧美性久久久久