簡述systemd的新特性及unit常見型別分析

2021-08-20 19:49:45 字數 4263 閱讀 4248

systemd可以管理系統中所有資源。不同的資源統稱為unit(單位)。unit表示不同型別的systemd物件,通過配置檔案程序標識和配置;檔案中主要包含了系統服務、監聽socket、儲存的系統快照以及其它與init相關的資訊。

systemctl命令是系統服務管理器指令,它實際上將 service 和 chkconfig 這兩個命令組合到一起。

語法

systemctl  [options...]  command  [name...]
舊指令和新指令對比

systemctl [ start | stop | restart | stauts ] 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.servcie

過載或條件式重啟服務:systemctl reload-or-try-restart name.service

systemctl [ enable | disable ] name.service

設定服務開機自啟: chkconfig name on ==> systemctl enable name.service

禁止服務開機自啟: chkconfig name off ==> systemctl disable name.service

檢視某服務是否能開機自啟: chkconfig --list name ==> systemctl is-enabled name.service

禁止某服務設定為開機自啟: systemctl mask name.service

取消此禁止: systemctl unmask name.servcie

檢視系統上所有的服務:systemctl [command] [-type=type] [-all]

檢視所有的系統服務: systemctl

檢視所有啟動的unit: systemctl list-units

檢視所有啟動檔案: systemctl list-unit-files

檢視所有已啟動的服務:systemctl list-units --type service

檢視所有service型別的unit(已啟動及未啟動): chkconfig --lsit ==> systemctl list-units -t service --all

檢視某服務當前啟動與否的狀態: systemctl is-active name.service

檢視服務的依賴關係:systemctl list-dependencies name.service

設定執行級別

語法

systemctl [command] [unit.target]
命令

get-default :取得當前的target

set-default :設定指定的target為預設的執行級別

isolate :切換到指定的執行級別

unit.target :為5.1表中列出的執行級別

執行級別:

0  init 0 ==>  runlevel0.target,  poweroff.target

1 init 1 ==> runlevel1.target, rescue.target

2 init 2 ==> runlevel2.tartet, multi-user.target

3 init 3 ==> runlevel3.tartet, multi-user.target

4 init 4 ==> runlevel4.tartet, multi-user.target

5 init 5 ==> runlevel5.target, graphical.target

6 init 6 ==> runlevel6.target, reboot.target

例項:

systemctl get-default   獲得當前的執行級別

systemctl set-default name.target 修改預設執行級別

systemctl set-default multi-user.target 設定預設的執行級別為mulit-user

systemctl isolate multi-user.target 在不重啟的情況下,切換到執行級別mulit-user下

systemctl isolate graphical.target 在不重啟的情況下,切換到圖形介面下

systemctl rescue 切換至救援模式

systemctl emergency 強制進入緊急救援模式

其他命令

systemctl halt 關機

systemctl poweroff 關機

systemctl reboot 重啟

systemctl suspend 掛起

systemctl hibernate 快照

systemctl hybrid-sleep 快照並掛起

1.配置目錄

/usr/lib/systemd/system/
2.檔案組成

[unit]:定義與unit型別無關的通用選項;用於提供unit的描述資訊、unit行為及依賴關係等;

[install]:定義由「systemctl enable」以及"systemctl disable「命令在實現服務啟用或禁用時用到的一些選項;

3.unit段的常用選項

description:描述資訊; 意義性描述;

after:定義unit的啟動次序;表示當前unit應該晚於哪些unit啟動;其功能與before相反;

requies:依賴到的其它units;強依賴,被依賴的units無法啟用時,當前unit即無法啟用;

wants:依賴到的其它units;弱依賴;

conflicts:定義units間的衝突關係;

4.service段的常用選項

type:用於定義影響execstart及相關引數的功能的unit程序啟動型別;

型別:******:預設值,執行execstart指定的命令,啟動主程序

forking:以 fork 方式從父程序建立子程序,建立後父程序會立即退出

oneshot:一次性程序,systemd 會等當前服務退出,再繼續往下執行

dbus:當前服務通過d-bus啟動

notify:當前服務啟動完畢,會通知systemd,再繼續往下執行

idle:若有其他任務執行完畢,當前服務才會執行

environmentfile:環境配置檔案;

execstart:指明啟動unit要執行命令或指令碼; execstartpre, execstartpost

execstop:指明停止unit要執行的命令或指令碼;

restart:定義何種情況 systemd 會自動重啟當前服務,可能的值包括always(總是重啟)、on-success、on-failure、on-abnormal、on-abort、on-watchdog

5.install段的常用選項:

alias:

requiredby:被哪些units所依賴;

wantedby:被哪些units所依賴;

6.新建立、修改unit檔案需過載此配置檔案

systemctl  daemon-reload
例項:編譯安裝的nginx並通過systemd來管理

簡述PHP7 4 新特性和廢棄的功能

php7.4 新特性 php7.4 上月 28 號已經發布了。又帶來了一些新特性。可以讓我們的 寫的更少了。1.屬性新增限定型別 www.cppcns.com user new user user age 10 user name 張三 error user age zhang 需要傳遞int 2....

簡述jdk5 jdk8各個版本的新特性

只是從應用角度簡述一下自己知道的不同版本的新特新並不全面 1.增加了for each 可以用for each對實現iterable介面的類進行遍歷 2.泛型也是1.5引入的 3.callable介面也是1.5引入的 但是建立執行緒的方式就是2種,jdk官方說的誰說也不好使可以看下thread原始碼備...

JDK1 5及1 7的新特性

a jdk1.5的新特性 自動拆裝箱 泛型 增強for 可變引數 列舉 b 列舉概述 就是乙個類只能存在幾個固定的物件,那麼這個就是列舉.我們就可以使用這些物件可以表示一些固定的值.舉例 一周只有7天,一年只有12個月等。c 案例演示 自己實現列舉類 a 案例演示 通過enum實現列舉類 a 案例演...