systemctlでLinuxサービスを管理する
systemctlでLinuxサービスを管理する Systemdは、最近のほとんどのLinuxディストリビューションでデフォルトのinitシステムです。systemctlコマンドは、サービス管理の主要なツールです。この記事では、最も一般的な操作について説明します。 1. サービスステータスの確認 サービスが実行中かどうかを確認する: systemctl status nginx 出力には、アクティブ状態、メインPID、メモリ使用量、最近のログエントリが含まれます。緑色の active running はサービスが正常に動作していることを示します。 実行中のサービスをすべて一覧表示する: systemctl list-units --type=service --state=running 2. サービスの起動と停止 サービスをすぐに起動する: systemctl start nginx 実行中のサービスを停止する: systemctl stop nginx サービスを再起動する: systemctl restart nginx 完全な再起動なしで設定を再読み込みする: systemctl reload nginx 3. サービスの有効化と無効化 サービスを有効にして、起動時に自動的に開始するようにする: systemctl enable nginx サービスを無効にして、起動時に開始しないようにする: systemctl disable nginx 1つのコマンドで有効化と起動を同時に行う: systemctl enable --now nginx 4. journalctlでログを確認する Systemdはjournaldを通じてログを収集します。特定のサービスのログを確認する: journalctl -u nginx ログをリアルタイムで追跡する: journalctl -u nginx -f 最近の50件のみ表示する: ...