#author("2025-04-29T10:30:10+09:00","default:k1rou","k1rou")
*Linuxの起動(systemd) [#g78d20fa]
-Unitという単位でシステムを起動する
-サービスを並列で起動する
-※CentOS7以降
#author("2025-04-29T11:08:35+09:00","default:k1rou","k1rou")

*コマンド [#cab51536]
**systemctl [#if2cd13b]
-サービスの状態を確認
 systemctl status <service-name> ※サービスの稼働状況を表示
 systemctl is-active <service-name> ※サービスが稼働中か表示
-自動起動の設定
 systemctl is-enabled <service-name> ※自動起動の設定を表示
 systemctl enable <service-name> ※自動起動ON
 systemctl disable <service-name> ※自動起動OFF
 systemctl preset <service-name> ※自動起動ONまたはOFF(プリセットポリシーに従う)

--自動起動が設定されているサービスの確認
 ls -l /etc/systemd/system/multi-user.target.wants/
 ※自動起動を有効にするとここにサービスのシンボリックリンクが作成される
-サービスの起動/停止/再起動
 systemctl start <service-name> ※起動
 systemctl stop <service-name> ※停止
 systemctl restart <service-name> ※再起動
 systemctl reload <service-name> ※サービスの設定を再読み込み
-Unitの状態を確認
 systemctl list-dependencies ※Unitの依存関係を表示
 systemctl list-units ※起動している全てのUnitの状態を表示
 systemctl list-unit-files ※全てのUnitを表示
 systemctl list-unit-files -t service ※サービスの一覧を表示
 systemctl list-unit-files -t service --state=enabled ※サービスの一覧を表示(自動起動が有効のみ)
-Unitのマスク(手動でも起動できないようにする)
 systemctl mask <service-name> ※マスク有効
 systemctl unmask <service-name> ※マスク解除
-システムの操作
 systemctl poweroff ※システムを停止
 systemctl reboot ※システムを再起動
-Unitファイルを再読み込み ※Unitファイルを追加・変更したら毎回行う
 systemctl daemon-reload

**設定ファイル [#h119d62b]
***ユニットファイル [#d88528fc]
-標準のユニットファイル(通常はパッケージが提供)
 /usr/lib/systemd/system/ ※Red Hat系
 /lib/systemd/system/ ※Debian系
-ユーザーがカスタマイズして作成(標準より優先される)
 /etc/systemd/system/

*補足 [#i5a6724c]
-起動するターゲットの確認
--/etc/systemd/system/default.target
 ls -l /etc/systemd/system/default.target
 →default.targetのリンク先で確認する
 →multi-user.target であればマルチユーザ

-起動するターゲットの変更
--default.target のリンク先を変更する(lnコマンド) 

*関連用語 [#y8e4920e]
-[[Linuxコマンド]]
-[[Linuxの起動・シャットダウン]]
-[[Linuxの起動(SysVinit)]]


トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS