Linuxの起動・シャットダウン
2023-08-06 (日) 22:33:08
Linuxの起動・シャットダウン †
Linuxの起動 †
起動時のカーネルの処理を表示 †
- dmesg
dmesg
- journalctl
journalctl -kb
起動時のログ †
- ログファイル
/var/log/dmesg /var/log/messages /var/log/boot.log
Linuxのシャットダウン・再起動 †
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を起動する仕組み †
- アプリケーションの自動起動の設定など
- SysVinitは古くからある仕組みで、新しくsystemd、Upstart が登場している
SysVinit †
- 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 †
- 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 であればマルチユーザ
- /etc/systemd/system/default.target
- 起動するターゲットの変更
- default.target のリンク先を変更する(lnコマンド)
systemctl †
- サービスの状態を確認
systemctl status <service-name> ※サービスの稼働状況を表示 systemctl is-active <service-name> ※サービスが稼働中か表示
- 自動起動の設定
systemctl is-enabled <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/