systemd簡介

1民珍、簡述systemd的新特性

????????RedHat 系的Linux系統(tǒng)队魏,init進(jìn)程的有:

????????CentOS 5 : SysV-->init

????????CentOS 6 : Upstart-->init

????????CentOS 7: Systemd

其中巩螃,Systemd 的新特性有:

????????系統(tǒng)引導(dǎo)時實(shí)現(xiàn)進(jìn)程并行啟動届惋;

????????可以按需啟動進(jìn)程;也可以根據(jù)依賴性進(jìn)行服務(wù)控制掠手;

????????系統(tǒng)狀態(tài)快照;

2柳恐、Unit?(單元)

Systemd 是通過unit 及其配置文件來管理控制系統(tǒng)服務(wù)伐脖、監(jiān)聽的socket热幔、快照及其他與init相關(guān)的信息的。

unit 配置文件通常放置于:

? ? ? ? ? /usr/lib/systemd/system 讼庇、/etc/systemd/system绎巨、/run/systemd/system

unit的常見類型:

? ? ? ? Service unit:? 配置文件以.service 結(jié)尾,用于定義系統(tǒng)服務(wù)

? ? ? ? Target unit: 以.target 結(jié)尾, 用于模擬運(yùn)行級別

? ? ? ? Device unit : 以.device 結(jié)尾蠕啄,用于定義內(nèi)核識別的設(shè)備场勤;

? ? ? ? Socket unit:? 以.socket 結(jié)尾, 用于定義進(jìn)程間通訊的socket文件

? ? ? ? Path unit : 以.path 結(jié)尾,用于定義文件系統(tǒng)中的文件或目錄;

? ? ? ? Mount unit : 以.mount 結(jié)尾,用于定義系統(tǒng)掛載點(diǎn)

? ? ? ? Automount unit: 以.automount結(jié)尾, 用于定義系統(tǒng)的自動掛載點(diǎn)

? ? ? ? Swap unit :? 以.swap 結(jié)尾, 用于標(biāo)識swap設(shè)備;

? ? ? ? Snapshot unit : 以.snapshot 結(jié)尾歼跟, 用于管理系統(tǒng)快照;

比如和媳, service unit 配置文件 內(nèi)容如下:??

>>>> cat /usr/lib/systemd/system/firewalld.service

[Unit]

Description=firewalld - dynamic firewall daemon

Before=network-pre.target

Wants=network-pre.target

After=dbus.service

After=polkit.service

Conflicts=iptables.service ip6tables.service ebtables.service ipset.service

Documentation=man:firewalld(1)

[Service]

EnvironmentFile=-/etc/sysconfig/firewalld

ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS

ExecReload=/bin/kill -HUP $MAINPID

# supress to log debug and error output also to /var/log/messages

StandardOutput=null

StandardError=null

Type=dbus

BusName=org.fedoraproject.FirewallD1

KillMode=mixed

[Install]

WantedBy=multi-user.target

Alias=dbus-org.fedoraproject.FirewallD1.service

從上可以看出, unit 配置文件一般分為三個部分:

? ? ? ? unit : 定義unit 的依賴性、幫助哈街、描述等信息

? ??????????????????Description : unit 意義描述

????????????????????Before: 定義當(dāng)前unit應(yīng)該先于哪些unit 啟動留瞳;

????????????????????After: 定義當(dāng)前unit 應(yīng)該晚于哪些unit 啟動;

? ??????????????????Wants:定義當(dāng)前unit 依賴哪些units ; 弱依賴,即其他units 可有可無;

? ? ? ? ? ? ? ? ? ?Conflicts: 定義沖突的units?

????????????????????Documentation: 幫助信息

? ? ? ? service:定義unit 的相關(guān)選項(xiàng)

? ??????????????????EnvironmentFile: 定義unit 環(huán)境變量信息

????????????????????ExecStart:指明啟動unit 時運(yùn)行的腳本

? ??????????????????ExecStop:指明停止unit 時運(yùn)行的腳本

????????????????????ExecReload:指明重載unit時運(yùn)行的腳本

????????????????????Type:Configures the unit process startup type that affects the functionality of?ExecStart?and related options. /? 配置影響ExecStart及相關(guān)選項(xiàng)的 unit進(jìn)程啟動類型

????????????????????????????simple?– The process started with?ExecStart?is the main process of the service./默認(rèn)選項(xiàng)骚秦,ExecStart 啟動的進(jìn)程是主進(jìn)程;

????????????????????????????forking?– The process started with?ExecStart?spawns a child process that becomes the main process of the service. The parent process exits when the startup is complete./ExecStart 啟動的進(jìn)程會啟動一個子進(jìn)程她倘,子進(jìn)程將會成為服務(wù)的主進(jìn)程。父進(jìn)程在服務(wù)啟動完成之后退出.

????????????????????????????oneshot?– This type is similar to?simple, but the process exits before starting consequent units./ 類似于simple,但是這個進(jìn)程在啟動后續(xù)的unit之前就退出了.

????????????????????????????dbus?– This type is similar to?simple, but consequent units are started only after the main process gains a D-Bus name. /類似于simple,但是只有該主進(jìn)程收到一個D-Bus名稱后才會啟動后續(xù)units .

????????????????????????????notify?– This type is similar to?simple, but consequent units are started only after a notification message is sent via the sd_notify() function. / 類似simple作箍,后續(xù)的units 只有在主進(jìn)程收到sd_notify()函數(shù)的通知后才會啟動;

? ? ? ? ? ? ? ? ? ? ? ? ? ? idle?– similar to?simple, the actual execution of the service binary is delayed until all jobs are finished, which avoids mixing the status output with shell output of services./ 服務(wù)的二進(jìn)制程序被延遲執(zhí)行硬梁,直到所有的任務(wù)完成,以避免狀態(tài)輸出與服務(wù)器的shell 輸出混合;


?????????install?:This section is not interpreted by systemd(1) during runtime. It is used exclusively by the enable and disable commands of the systemctl(1) tool during installation of a unit./這部分在運(yùn)行期間是不會被執(zhí)行胞得。它只在執(zhí)行systemctl enable|disable時使用;


3荧止、實(shí)現(xiàn)systemd 管理niginx 服務(wù)

? ? ? ? 3.1 將nginx 源碼包安裝至/usr/local/nginx 下;

? ? ? ?3.2 創(chuàng)建unit配置文件

?????????????>>> cat /usr/lib/systemd/system/nginx.service

????????????[Unit]

????????????Description=nginx

????????????[Service]

? ? ? ? ? ?ExecStart=/usr/local/nginx/sbin/nginx

????????????ExecStop=/usr/local/nginx/sbin/nginx -s stop

????????????ExecReload=/usr/local/nginx/sbin/nginx -s reload

????????????Type=forking

? ??????

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末阶剑,一起剝皮案震驚了整個濱河市跃巡,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌个扰,老刑警劉巖瓷炮,帶你破解...
    沈念sama閱讀 222,378評論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件葱色,死亡現(xiàn)場離奇詭異递宅,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)苍狰,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,970評論 3 399
  • 文/潘曉璐 我一進(jìn)店門办龄,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人淋昭,你說我怎么就攤上這事俐填。” “怎么了翔忽?”我有些...
    開封第一講書人閱讀 168,983評論 0 362
  • 文/不壞的土叔 我叫張陵英融,是天一觀的道長盏檐。 經(jīng)常有香客問我,道長驶悟,這世上最難降的妖魔是什么胡野? 我笑而不...
    開封第一講書人閱讀 59,938評論 1 299
  • 正文 為了忘掉前任,我火速辦了婚禮痕鳍,結(jié)果婚禮上硫豆,老公的妹妹穿的比我還像新娘。我一直安慰自己笼呆,他們只是感情好熊响,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,955評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著诗赌,像睡著了一般汗茄。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上铭若,一...
    開封第一講書人閱讀 52,549評論 1 312
  • 那天剔难,我揣著相機(jī)與錄音,去河邊找鬼奥喻。 笑死偶宫,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的环鲤。 我是一名探鬼主播纯趋,決...
    沈念sama閱讀 41,063評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼冷离!你這毒婦竟也來了吵冒?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,991評論 0 277
  • 序言:老撾萬榮一對情侶失蹤西剥,失蹤者是張志新(化名)和其女友劉穎痹栖,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體瞭空,經(jīng)...
    沈念sama閱讀 46,522評論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡揪阿,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,604評論 3 342
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了咆畏。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片南捂。...
    茶點(diǎn)故事閱讀 40,742評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖旧找,靈堂內(nèi)的尸體忽然破棺而出溺健,到底是詐尸還是另有隱情,我是刑警寧澤钮蛛,帶...
    沈念sama閱讀 36,413評論 5 351
  • 正文 年R本政府宣布鞭缭,位于F島的核電站剖膳,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏岭辣。R本人自食惡果不足惜潮秘,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,094評論 3 335
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望易结。 院中可真熱鬧枕荞,春花似錦、人聲如沸搞动。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,572評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽鹦肿。三九已至矗烛,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間箩溃,已是汗流浹背瞭吃。 一陣腳步聲響...
    開封第一講書人閱讀 33,671評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留涣旨,地道東北人歪架。 一個月前我還...
    沈念sama閱讀 49,159評論 3 378
  • 正文 我出身青樓,卻偏偏與公主長得像霹陡,于是被迫代替她去往敵國和親和蚪。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,747評論 2 361

推薦閱讀更多精彩內(nèi)容