RHEL9  systemctlコマンドの使い方のサンプル

環境
Red Hat Enterprise Linux release 9.2 (Plow)

操作方法
1.現在のtargetを取得するには、systemctl list-units –type targetを使う。
結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$systemctl list-units --type target
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
cryptsetup.target loaded active active Local Encrypted Volumes
getty.target loaded active active Login Prompts
graphical.target loaded active active Graphical Interface
integritysetup.target loaded active active Local Integrity Protected Volumes
local-fs-pre.target loaded active active Preparation for Local File Systems
local-fs.target loaded active active Local File Systems
multi-user.target loaded active active Multi-User System
network-pre.target loaded active active Preparation for Network
network.target loaded active active Network
nss-user-lookup.target loaded active active User and Group Name Lookups
paths.target loaded active active Path Units
remote-fs-pre.target loaded active active Preparation for Remote File Systems
remote-fs.target loaded active active Remote File Systems
slices.target loaded active active Slice Units
sockets.target loaded active active Socket Units
sound.target loaded active active Sound Card
sshd-keygen.target loaded active active sshd-keygen.target
swap.target loaded active active Swaps
sysinit.target loaded active active System Initialization
timers.target loaded active active Timer Units
veritysetup.target loaded active active Local Verity Protected Volumes
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
22 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
$systemctl list-units --type target UNIT LOAD ACTIVE SUB DESCRIPTION basic.target loaded active active Basic System cryptsetup.target loaded active active Local Encrypted Volumes getty.target loaded active active Login Prompts graphical.target loaded active active Graphical Interface integritysetup.target loaded active active Local Integrity Protected Volumes local-fs-pre.target loaded active active Preparation for Local File Systems local-fs.target loaded active active Local File Systems multi-user.target loaded active active Multi-User System network-pre.target loaded active active Preparation for Network network.target loaded active active Network nss-user-lookup.target loaded active active User and Group Name Lookups paths.target loaded active active Path Units remote-fs-pre.target loaded active active Preparation for Remote File Systems remote-fs.target loaded active active Remote File Systems slices.target loaded active active Slice Units sockets.target loaded active active Socket Units sound.target loaded active active Sound Card sshd-keygen.target loaded active active sshd-keygen.target swap.target loaded active active Swaps sysinit.target loaded active active System Initialization timers.target loaded active active Timer Units veritysetup.target loaded active active Local Verity Protected Volumes LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type. 22 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'.
$systemctl list-units --type target
  UNIT                   LOAD   ACTIVE SUB    DESCRIPTION
  basic.target           loaded active active Basic System
  cryptsetup.target      loaded active active Local Encrypted Volumes
  getty.target           loaded active active Login Prompts
  graphical.target       loaded active active Graphical Interface
  integritysetup.target  loaded active active Local Integrity Protected Volumes
  local-fs-pre.target    loaded active active Preparation for Local File Systems
  local-fs.target        loaded active active Local File Systems
  multi-user.target      loaded active active Multi-User System
  network-pre.target     loaded active active Preparation for Network
  network.target         loaded active active Network
  nss-user-lookup.target loaded active active User and Group Name Lookups
  paths.target           loaded active active Path Units
  remote-fs-pre.target   loaded active active Preparation for Remote File Systems
  remote-fs.target       loaded active active Remote File Systems
  slices.target          loaded active active Slice Units
  sockets.target         loaded active active Socket Units
  sound.target           loaded active active Sound Card
  sshd-keygen.target     loaded active active sshd-keygen.target
  swap.target            loaded active active Swaps
  sysinit.target         loaded active active System Initialization
  timers.target          loaded active active Timer Units
  veritysetup.target     loaded active active Local Verity Protected Volumes

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.
22 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

2.システム起動時のデフォルトのtargetはsystemctl get-defaultで取得できます

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$systemctl get-default
graphical.target
$systemctl get-default graphical.target
$systemctl get-default
graphical.target

3.デフォルトtargetを変更するには、systemctl set-defaultを使う。
# systemctl set-default multi-user.target

4.ユニットの一覧を表示する
$systemctl

全ユニットファイルを表示したい場合はlist-unit-filesを指定する。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# systemctl list-unit-files
# systemctl list-unit-files
# systemctl list-unit-files

5.ユニットの現在の状態を表示するにはstatusコマンドを指定する。以下はhttpdの状態を表示させた場合。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$systemctl status httpd.service
○ httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled)
Active: inactive (dead)
Docs: man:httpd.service(8)
$systemctl status httpd.service ○ httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled) Active: inactive (dead) Docs: man:httpd.service(8)
$systemctl status httpd.service
○ httpd.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; preset: disabled)
     Active: inactive (dead)
       Docs: man:httpd.service(8)

ユニットの起動
# systemctl start httpd.service

ユニットの停止

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# systemctl stop httpd.service
# systemctl stop httpd.service
# systemctl stop httpd.service

自動起動

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# systemctl enable httpd.service
# systemctl enable httpd.service
# systemctl enable httpd.service

 

IT

Posted by arkgame