CentOS 7のシステム管理「systemd」をイチから理解するCentOS 7で始める最新Linux管理入門(2)(2/4 ページ)

» 2015年12月24日 05時00分 公開
[大喜多利哉@IT]

実運用で、initとsystemdは何が変わるか

 実際にシステムを管理する現場管理者としては、initからsystemdに変わったことで「実運用で、何が変わるのか」が最も気になる部分だと思います。具体例で説明します。

 systemdでは、これまでサービス起動スクリプトで定義されていたものがUnitという形で定義されます。initでいう「サービスの管理」は、「Unitの管理」を意味します。

 CentOS 7で有効化されているUnitをsystemctl list-unitsコマンドで一覧表示します。

 表示項目のうち、UNITはUnit名、LOADはSystemdへの設定読み込み状況、ACTIVEおよびSUBがUnitの実行状態(ACTIVEは起動しているか否か、SUBは稼働中や待ち受け中などの各Unitの状態)、DESCRIPTIONがUnitの概要を表しています。起動対象ながら、起動に失敗した場合はACTIVEやSUBの値がfailedといった表示になります。

# systemctl list-units
UNIT                        LOAD   ACTIVE SUB       DESCRIPTION
proc-sys...t_misc.automount loaded active waiting   Arbitrary Executable File Fo
sys-devi...block-sr0.device loaded active plugged   QEMU_DVD-ROM
sys-devi...block-sr1.device loaded active plugged   QEMU_DVD-ROM
sys-devi...-net-eth0.device loaded active plugged   Virtio network device
sys-devi...-vda-vda1.device loaded active plugged   /sys/devices/pci0000:00/0000
sys-devi...-vda-vda2.device loaded active plugged   /sys/devices/pci0000:00/0000
sys-devi...-vda-vda3.device loaded active plugged   /sys/devices/pci0000:00/0000
sys-devi...block-vda.device loaded active plugged   /sys/devices/pci0000:00/0000
sys-devi...block-fd0.device loaded active plugged   /sys/devices/platform/floppy
sys-devi...tty-ttyS1.device loaded active plugged   /sys/devices/platform/serial
sys-devi...tty-ttyS2.device loaded active plugged   /sys/devices/platform/serial
sys-devi...tty-ttyS3.device loaded active plugged   /sys/devices/platform/serial
sys-devi...tty-ttyS0.device loaded active plugged   /sys/devices/pnp0/00:04/tty/
sys-module-configfs.device  loaded active plugged   /sys/module/configfs
sys-subs...ices-eth0.device loaded active plugged   Virtio network device
-.mount                     loaded active mounted   /
dev-hugepages.mount         loaded active mounted   Huge Pages File System
dev-mqueue.mount            loaded active mounted   POSIX Message Queue File Sys
sys-kernel-config.mount     loaded active mounted   Configuration File System
sys-kernel-debug.mount      loaded active mounted   Debug File System
brandbot.path               loaded active waiting   Flexible branding
systemd-...rd-plymouth.path loaded active waiting   Forward Password Requests to
systemd-...ssword-wall.path loaded active waiting   Forward Password Requests to
chronyd.service             loaded active running   NTP client/server
crond.service               loaded active running   Command Scheduler
dbus.service                loaded active running   D-Bus System Message Bus
fail2ban.service            loaded active running   Fail2Ban Service
firewalld.service           loaded active running   firewalld - dynamic firewall
getty@tty1.service          loaded active running   Getty on tty1
kmod-static-nodes.service   loaded active exited    Create list of required stat
network.service             loaded failed failed    LSB: Bring up/down networkin
NetworkManager.service      loaded active running   Network Manager
polkit.service              loaded active running   Authorization Manager
postfix.service             loaded active running   Postfix Mail Transport Agent
rhel-aut...bel-mark.service loaded active exited    Mark the need to relabel aft
rhel-dmesg.service          loaded active exited    Dump dmesg to /var/log/dmesg
rhel-import-state.service   loaded active exited    Import network configuration
rhel-readonly.service       loaded active exited    Configure read-only root sup
rsyslog.service             loaded active running   System Logging Service
sshd-keygen.service         loaded active exited    OpenSSH Server Key Generatio
sshd.service                loaded active running   OpenSSH server daemon
systemd-fsck-root.service   loaded active exited    File System Check on Root De
systemd-journald.service    loaded active running   Journal Service
systemd-logind.service      loaded active running   Login Service
systemd-random-seed.service loaded active exited    Load/Save Random Seed
systemd-remount-fs.service  loaded active exited    Remount Root and Kernel File
systemd-sysctl.service      loaded active exited    Apply Kernel Variables
systemd-...etup-dev.service loaded active exited    Create static device nodes i
systemd-...es-setup.service loaded active exited    Create Volatile Files and Di
systemd-...-trigger.service loaded active exited    udev Coldplug all Devices
systemd-udevd.service       loaded active running   udev Kernel Device Manager
systemd-update-utmp.service loaded active exited    Update UTMP about System Reb
systemd-...sessions.service loaded active exited    Permit User Sessions
systemd-...le-setup.service loaded active exited    Setup Virtual Console
tuned.service               loaded active running   Dynamic System Tuning Daemon
-.slice                     loaded active active    Root Slice
system-getty.slice          loaded active active    system-getty.slice
system.slice                loaded active active    System Slice
user.slice                  loaded active active    User and Session Slice
dbus.socket                 loaded active running   D-Bus System Message Bus Soc
systemd-initctl.socket      loaded active listening /dev/initctl Compatibility N
systemd-journald.socket     loaded active running   Journal Socket
systemd-shutdownd.socket    loaded active listening Delayed Shutdown Socket
systemd-...d-control.socket loaded active running   udev Control Socket
systemd-udevd-kernel.socket loaded active running   udev Kernel Socket
dev-vda2.swap               loaded active active    /dev/vda2
basic.target                loaded active active    Basic System
cryptsetup.target           loaded active active    Encrypted Volumes
getty.target                loaded active active    Login Prompts
local-fs-pre.target         loaded active active    Local File Systems (Pre)
local-fs.target             loaded active active    Local File Systems
multi-user.target           loaded active active    Multi-User System
network.target              loaded active active    Network
paths.target                loaded active active    Paths
remote-fs.target            loaded active active    Remote File Systems
slices.target               loaded active active    Slices
sockets.target              loaded active active    Sockets
swap.target                 loaded active active    Swap
sysinit.target              loaded active active    System Initialization
timers.target               loaded active active    Timers
systemd-...iles-clean.timer loaded active waiting   Daily Cleanup of Temporary D
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.
81 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
有効化されているUnitをsystemctl list-unitsコマンドで一覧表示した画面

 続いて、インストールされているUnitファイルをsystemctl list-unit-filesコマンドで一覧表示してみます。

 STATE列の表示を見ることで、現在の設定状況を確認できます。「enable」は自動起動設定が有効になっているUnit、「disable」は自動起動設定が無効になっているUnit、「static」は単体では自動起動できないUnitを表します。

# systemctl list-unit-files
UNIT FILE                                   STATE
proc-sys-fs-binfmt_misc.automount           static
dev-hugepages.mount                         static
dev-mqueue.mount                            static
proc-sys-fs-binfmt_misc.mount               static
sys-fs-fuse-connections.mount               static
sys-kernel-config.mount                     static
sys-kernel-debug.mount                      static
tmp.mount                                   disabled
brandbot.path                               disabled
systemd-ask-password-console.path           static
systemd-ask-password-plymouth.path          static
systemd-ask-password-wall.path              static
auditd.service                              disabled
autovt@.service                             disabled
brandbot.service                            static
chrony-wait.service                         disabled
chronyd.service                             enabled
console-getty.service                       disabled
console-shell.service                       disabled
cpupower.service                            disabled
crond.service                               enabled
dbus-org.fedoraproject.FirewallD1.service   enabled
dbus-org.freedesktop.hostname1.service      static
dbus-org.freedesktop.locale1.service        static
dbus-org.freedesktop.login1.service         static
dbus-org.freedesktop.machine1.service       static
dbus-org.freedesktop.NetworkManager.service enabled
dbus-org.freedesktop.nm-dispatcher.service  enabled
dbus-org.freedesktop.timedate1.service      static
dbus.service                                static
debug-shell.service                         disabled
dnsmasq.service                             disabled
dracut-cmdline.service                      static
dracut-initqueue.service                    static
dracut-mount.service                        static
dracut-pre-mount.service                    static
dracut-pre-pivot.service                    static
dracut-pre-trigger.service                  static
dracut-pre-udev.service                     static
dracut-shutdown.service                     static
ebtables.service                            disabled
emergency.service                           static
fail2ban.service                            enabled
firewalld.service                           enabled
getty@.service                              enabled
halt-local.service                          static
initrd-cleanup.service                      static
initrd-parse-etc.service                    static
initrd-switch-root.service                  static
initrd-udevadm-cleanup-db.service           static
iprdump.service                             disabled
iprinit.service                             disabled
iprupdate.service                           disabled
irqbalance.service                          enabled
kdump.service                               disabled
kmod-static-nodes.service                   static
messagebus.service                          static
NetworkManager-dispatcher.service           enabled
NetworkManager-wait-online.service          disabled
NetworkManager.service                      enabled
plymouth-halt.service                       disabled
plymouth-kexec.service                      disabled
plymouth-poweroff.service                   disabled
plymouth-quit-wait.service                  disabled
plymouth-quit.service                       disabled
plymouth-read-write.service                 disabled
plymouth-reboot.service                     disabled
plymouth-start.service                      disabled
plymouth-switch-root.service                static
polkit.service                              static
postfix.service                             enabled
quotaon.service                             static
rc-local.service                            static
rdisc.service                               disabled
rescue.service                              static
rhel-autorelabel-mark.service               static
rhel-autorelabel.service                    static
rhel-configure.service                      static
rhel-dmesg.service                          disabled
rhel-domainname.service                     disabled
rhel-import-state.service                   static
rhel-loadmodules.service                    static
rhel-readonly.service                       static
rsyncd.service                              disabled
rsyslog.service                             enabled
serial-getty@.service                       disabled
spice-vdagentd.service                      enabled
sshd-keygen.service                         static
sshd.service                                enabled
sshd@.service                               static
svnserve.service                            disabled
systemd-ask-password-console.service        static
systemd-ask-password-plymouth.service       static
systemd-ask-password-wall.service           static
systemd-backlight@.service                  static
systemd-binfmt.service                      static
systemd-fsck-root.service                   static
systemd-fsck@.service                       static
systemd-halt.service                        static
systemd-hibernate.service                   static
systemd-hostnamed.service                   static
systemd-hybrid-sleep.service                static
systemd-initctl.service                     static
systemd-journal-flush.service               static
systemd-journald.service                    static
systemd-kexec.service                       static
systemd-localed.service                     static
systemd-logind.service                      static
systemd-machined.service                    static
systemd-modules-load.service                static
systemd-nspawn@.service                     disabled
systemd-poweroff.service                    static
systemd-quotacheck.service                  static
systemd-random-seed.service                 static
systemd-readahead-collect.service           enabled
systemd-readahead-done.service              static
systemd-readahead-drop.service              enabled
systemd-readahead-replay.service            enabled
systemd-reboot.service                      static
systemd-remount-fs.service                  static
systemd-shutdownd.service                   static
systemd-suspend.service                     static
systemd-sysctl.service                      static
systemd-timedated.service                   static
systemd-tmpfiles-clean.service              static
systemd-tmpfiles-setup-dev.service          static
systemd-tmpfiles-setup.service              static
systemd-udev-settle.service                 static
systemd-udev-trigger.service                static
systemd-udevd.service                       static
systemd-update-utmp-runlevel.service        static
systemd-update-utmp.service                 static
systemd-user-sessions.service               static
systemd-vconsole-setup.service              static
tcsd.service                                disabled
teamd@.service                              static
tuned.service                               enabled
wacom-inputattach@.service                  static
wpa_supplicant.service                      disabled
-.slice                                     static
machine.slice                               static
system.slice                                static
user.slice                                  static
dbus.socket                                 static
rsyncd.socket                               disabled
sshd.socket                                 disabled
syslog.socket                               static
systemd-initctl.socket                      static
systemd-journald.socket                     static
systemd-shutdownd.socket                    static
systemd-udevd-control.socket                static
systemd-udevd-kernel.socket                 static
basic.target                                static
bluetooth.target                            static
cryptsetup.target                           static
ctrl-alt-del.target                         disabled
default.target                              enabled
emergency.target                            static
final.target                                static
getty.target                                static
graphical.target                            disabled
halt.target                                 disabled
hibernate.target                            static
hybrid-sleep.target                         static
initrd-fs.target                            static
initrd-root-fs.target                       static
initrd-switch-root.target                   static
initrd.target                               static
iprutils.target                             disabled
kexec.target                                disabled
local-fs-pre.target                         static
local-fs.target                             static
multi-user.target                           enabled
network-online.target                       static
network.target                              static
nss-lookup.target                           static
nss-user-lookup.target                      static
paths.target                                static
poweroff.target                             disabled
printer.target                              static
reboot.target                               disabled
remote-fs-pre.target                        static
remote-fs.target                            enabled
rescue.target                               disabled
rpcbind.target                              static
runlevel0.target                            disabled
runlevel1.target                            disabled
runlevel2.target                            disabled
runlevel3.target                            disabled
runlevel4.target                            disabled
runlevel5.target                            disabled
runlevel6.target                            disabled
shutdown.target                             static
sigpwr.target                               static
sleep.target                                static
slices.target                               static
smartcard.target                            static
sockets.target                              static
sound.target                                static
spice-vdagentd.target                       static
suspend.target                              static
swap.target                                 static
sysinit.target                              static
system-update.target                        static
time-sync.target                            static
timers.target                               static
umount.target                               static
systemd-readahead-done.timer                static
systemd-tmpfiles-clean.timer                static
209 unit files listed.
Unitファイルをsystemctl list-unit-filesコマンドで一覧表示した画面

 例えば、yum install httpdでApacheをインストールすると、以下のように登録されます。

$ systemctl list-unit-files | grep httpd
httpd.service                          disabled

Copyright © ITmedia, Inc. All Rights Reserved.

スポンサーからのお知らせPR

注目のテーマ

AI for エンジニアリング
「サプライチェーン攻撃」対策
1P情シスのための脆弱性管理/対策の現実解
OSSのサプライチェーン管理、取るべきアクションとは
Microsoft & Windows最前線2024
システム開発ノウハウ 【発注ナビ】PR
あなたにおすすめの記事PR

RSSについて

アイティメディアIDについて

メールマガジン登録

@ITのメールマガジンは、 もちろん、すべて無料です。ぜひメールマガジンをご購読ください。