Linuxの起動・シャットダウン のバックアップソース(No.1)

#author("2020-10-31T21:54:55+09:00","default:k1rou","k1rou")
*Linuxの起動・シャットダウン [#b8d380bc]

**Linuxの起動 [#i04b7b09]
***起動時のカーネルの処理を表示 [#i3015c25]
-dmesg
 dmesg
-journalctl -kb

***起動時のログ [#ieee0c02]
-ログファイル
 /var/log/dmesg
 /var/log/messages
 /var/log/boot.log

**Linuxのシャットダウン・再起動 [#l10f5b39]
-shutdown
--即時
 shutdown -h now ※システムを停止
 shutdown -r now ※システムを再起動
 shurdown -k now "comment" ※システムを停止しないで、ログインしているユーザーにメッセージを表示
--指定した時間後
 shutdown -h +15 "comment" ※15分後にシステムを停止。ログインしているユーザーにメッセージを表示
--指定した時刻
 shutdown -r 23:00 ※23時にシステムを再起動

-reboot ※再起動
 reboot
-halt ※システム停止
-poweroff ※システム停止

-systemctl
 systemctl poweroff ※システムを停止
 systemctl reboot ※システムを再起動

**OSを起動する仕組み [#s35b8775]
-アプリケーションの自動起動の設定など
-SysVinitは古くからある仕組みで、新しくsystemd、Upstart が登場している

***SysVinit [#d41740d5]
-System Five Init
-決められた手順に従い直列でシステムを起動する
-UNIXのSystemVで採用されていた起動する仕組みに基づいている

-initプロセスが起動する順序
++/etc/inittab
++/etc/rc.sysinit
++/etc/rc
++/etc/rc<[[ランレベル]]>.d/*

-起動スクリプト
--起動スクリプトを使ったサービスの起動・停止
 /etc/init.d/network start ※起動
 /etc/init.d/network status ※状態を表示
 /etc/init.d/network stop ※停止

-自動起動の設定:initプロセスに設定する
--/etc/rc.d/rc.local
--/etc/rc.local
 ls -l /sbin/init

***systemd [#a804dbd4]
-Unitという単位でシステムを起動する
-サービスを並列で起動する
-※CentOS7以降

-Unitの設定ファイル
--/lib/systemd/system/*
--/etc/systemd/system/* ※ホスト毎の設定

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

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

-systemctl
--サービスの状態を確認
 systemctl status <service-name> ※サービスの稼働状況を表示
 systemctl is-active <service-name> ※サービスが稼働中か表示
--自動起動の設定
 systemctl isenabled <service-name> ※自動起動の設定を表示
 systemctl enable <service-name> ※自動起動ON
 systemctl disable <service-name> ※自動起動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 ※システムを再起動

--サービスの一覧を表示
 ls /usr/lib/systemd/system/

***Upstart [#q025c428]

**関連用語 [#t9b58a9a]
-[[Linuxコマンド]]