tft每日頭條

 > 科技

 > linux系統入門到精通

linux系統入門到精通

科技 更新时间:2024-07-01 16:35:03
CentOS7.3學習筆記總結(六十九)- systemd實戰篇

Systemd是linux系統工具,是用來守護進程的,是大多數發行版的标準配置。

對于支持Systemd的軟件,在最初安裝的時候,程序就會自動在/usr/lib/systemd/system目錄中添加一個配置文件,啟動、停止、重啟等程序,以及設置開機自啟動,都可以直接運行systemctl命令來執行相關的操作,我們以apache的httpd軟件為例進行說明。

首先yum安裝httpd軟件:

rpm -qa|grep httpd#查詢是否安裝httpd軟件

yum install httpd

linux系統入門到精通(Linux系統Systemd實戰篇)1

啟動httpd服務:

ss -lntup|grep httpd#查詢httpd是否啟動

systemctl start httpd#使用systemctl啟動httpd軟件

linux系統入門到精通(Linux系統Systemd實戰篇)2

linux系統入門到精通(Linux系統Systemd實戰篇)3

httpd已經啟動,說明httpd可以使用systemctl啟動服務,httpd的啟動配置文件已經生成:

ls -l /usr/lib/systemd/system/httpd.service

linux系統入門到精通(Linux系統Systemd實戰篇)4

重新啟動httpd軟件:

systemctl restart httpd

停止httpd軟件:

systemctl stop httpd#有時執行此命令無響應,可以執行systemctl kill httpd殺死進程,但是我很少使用此命令,我遇到不響應的情況,一般使用killall或者pkill等。

linux系統入門到精通(Linux系統Systemd實戰篇)5

怎麼設置開機自啟動呢?很簡單,直接執行systemctl enable httpd就可以了,它會在/etc/system/system目錄中添加一個符号鍊接,指向/usr/lib/systemd/system/httpd.service。

linux系統入門到精通(Linux系統Systemd實戰篇)6

linux系統入門到精通(Linux系統Systemd實戰篇)7

當然也可以執行取消開機自啟動,命令:

systemctl disable httpd

查詢軟件服務狀态:

systemctl status httpd

linux系統入門到精通(Linux系統Systemd實戰篇)8

主要項目的含義:

Loaded:配置文件的位置,并顯示是否為開機自啟動;

Active:運行狀态,active(running)為正在運行,inactive(dead)為未運行;

Main PID:主進程ID;

linux系統入門到精通(Linux系統Systemd實戰篇)9

Status:程序本身提供的軟件狀态;

CGroup:應用的所有子進程

後面幾行是應用日志。

,

更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!

查看全部

相关科技资讯推荐

热门科技资讯推荐

网友关注

Copyright 2023-2024 - www.tftnews.com All Rights Reserved