広告 Linux

CentOS6とCentOS7のサービス管理コマンドを比較してみた

CentOS7からSystemdが採用されて、これまでやってた操作はCentOS7でどうするんだと悩むことが多いのでまとめ。

操作 〜CentOS6 CentOS7
起動 /etc/rc.d/init.d/[ServiceName] start / service [ServiceName] start systemctl start [ServiceName].service
終了 /etc/rc.d/init.d/[ServiceName] stop / service [ServiceName] stop systemctl stop [ServiceName].service
再起動 /etc/rc.d/init.d/[ServiceName] restart / service [ServiceName] restart systemctl restart [ServiceName].service
設定反映 /etc/rc.d/init.d/[ServiceName] reload / service [ServiceName] reload systemctl reload [ServiceName].service
状態取得 /etc/rc.d/init.d/[ServiceName] status / service [ServiceName] status systemctl status [ServiceName].service
自動起動を有効化 chkconfig [ServiceName] on systemctl enable [ServiceName].service
自動起動を無効化 chkconfig [ServiceName] off systemctl disable [ServiceName].service
自動起動の状態確認 chkconfig --list [ServiceName] systemctl is-enabled [ServiceName].service
サービスの一覧表示 ls -l /etc/rc.d/init.d systemctl --type service

その他便利になったこと

ログを見る

CentOS6までは/var/logあたりをあさっていたけど、CentOS7からはjournalctlコマンドを叩けば見れる。

journalctl -u [ServiceName].service

tail -fっぽくすることもかのうで、上記のコマンドに-fを足してやればいい。

journalctl -f -u [ServiceName].service

強制終了

CentOS6まではkillコマンド叩いていたけど、CentOS7からはコマンドが用意されている。

これまではpsでPID確認してからkillコマンド発行、という流れだったけど少し便利。

systemctl kill -s 9 [ServiceName].service

Sponsor Link

-Linux
-,