systemd-analyze - Linux でのシステム起動パフォーマンス統計の検索
systemd システムとサービス マネージャーを使用していて、Linux システムの起動に時間がかかっていませんか。あるいは、単純にシステムの起動パフォーマンスのレポートを表示したいだけですか? 「はい」の場合、あなたは正しい場所に着地しました。
この記事では、systemd にあるシステム管理用の多数のユーティリティの 1 つであるsystemd-analyze を使用して、Linux システムの起動パフォーマンス統計を分析する方法を説明します。
こちらもお読みください: リモート Linux サーバーで Systemd サービスを制御する方法
システムの起動時間の概要を取得するには、次のように引数なしで systemd-analyze コマンドを実行します。各サービスの起動にかかった時間に関する情報が一覧表示されます。これには、起動中にカーネル、initrd、およびユーザースペースにかかった時間が含まれます。
systemd-analyze
Startup finished in 884ms (kernel) + 3.861s (initrd) + 48.356s (userspace) = 53.102s
実行中のすべてのユニットのリストを、初期化にかかった時間順 (最も長い時間が一番上) で表示したい場合は、blame サブコマンドを使用します。次のコマンドを実行した後、[Enter] を使用してリスト内の他のサービスを表示し、q
を使用して終了します。
systemd-analyze blame
16.159s mariadb.service
12.178s libvirtd.service
10.298s tuned.service
9.836s postfix.service
8.704s lsws.service
7.352s lscpd.service
4.988s [email
4.779s NetworkManager-wait-online.service
4.577s lvm2-monitor.service
4.439s ModemManager.service
4.413s polkit.service
4.280s dev-sda1.device
4.225s systemd-udev-settle.service
3.957s firewalld.service
3.227s rhel-dmesg.service
3.221s abrt-ccpp.service
3.142s rsyslog.service
3.053s avahi-daemon.service
3.042s pure-ftpd.service
2.249s gssproxy.service
2.212s NetworkManager.service
1.889s proc-fs-nfsd.mount
1.780s systemd-tmpfiles-setup-dev.service
1.451s sshd.service
1.267s rhel-readonly.service
1.035s sysstat.service
1.001s rpc-statd-notify.service
910ms systemd-logind.service
739ms kdump.service
738ms network.service
...
上記の出力からわかるように、各ユニットはかかった時間に基づいて並べ替えられているため、起動中にどのサービスに時間がかかっているかを簡単に見つけて、問題を分析できます。
次に、示されているように、critical-chain サブコマンドを使用して、デフォルト ターゲットのタイム クリティカル チェーンのツリーまたは指定されたユニットのリストを表示することもできます。
systemd-analyze critical-chain
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.
multi-user.target @48.342s
└─mariadb.service @31.560s +16.159s
└─network.target @31.558s
└─network.service @30.819s +738ms
└─NetworkManager-wait-online.service @26.035s +4.779s
└─NetworkManager.service @23.821s +2.212s
└─network-pre.target @23.821s
└─firewalld.service @19.863s +3.957s
└─polkit.service @15.381s +4.413s
└─basic.target @12.271s
└─sockets.target @12.271s
└─virtlockd.socket @12.270s
└─sysinit.target @12.251s
└─systemd-update-utmp.service @12.196s +54ms
└─auditd.service @11.705s +486ms
└─systemd-tmpfiles-setup.service @11.609s +93ms
└─rhel-import-state.service @11.397s +211ms
└─local-fs.target @11.363s
└─run-user-0.mount @46.910s
└─local-fs-pre.target @10.575s
└─lvm2-monitor.service @5.996s +4.577s
└─lvm2-lvmetad.service @7.376s
└─lvm2-lvmetad.socket @5.987s
└─-.slice
systemd-analyze critical-chain ntp.service networking.service
最後に、次のように、開始されたシステム サービスの詳細をグラフィカル (SVG 形式) で作成し、その初期化時間を強調表示できるもう 1 つの重要なサブコマンドを見てみましょう。
プロットを表示するには、グラフィカル表示モードまたは X-Window が有効になっていることを確認してください。
systemd-analyze plot > boot_analysis.svg
xviewer boot_analysis.svg
上記のコマンドはすべて、ローカル マシンの起動パフォーマンス統計を出力します。 ssh 経由でリモート ホストからの情報を表示するには、-H
フラグを使用し、図に示すように username@host ディレクティブを指定します。
systemd-analyze time -H [email
systemd-analyze blame -H [email
systemd-analyze critical-chain -H [email
systemd-analyze を使用すると、システムや systemd (サービス マネージャー) などから他の状態やトレース情報を検索することもできます。詳細については、マニュアル ページを参照してください。
man systemd-analyze
こちらもお読みください: SystemD でランレベル (ターゲット) を変更する方法
今のところはここまでです!ご質問がある場合、または共有したい場合は、以下のフィードバック フォームを使用してご連絡ください。