ランレベルとサービスの自動起動の設定についてです。
確認環境 ・CentOS 6.8 |
目次
ランレベルとは
- OSの状態のことで0から6まであります。
- ランレベルの内容はOSによって異なります。CentOS(redhat系OS)のランレベルは下の表のようになっています。
ランレベル | 状態 |
---|---|
0 | システムが停止になる状態 |
1 | シングルユーザーモード rootによるログインができない等の緊急時に使用します。 rootと同じ権限を持ちます。 |
2 | 未使用。ユーザーが定義可能です。 |
3 | 通常の操作で使用されます。 マルチユーザーモードでテキストログインです。 |
4 | 未使用。ユーザーが定義可能です。 |
5 | 通常の操作で使用されます。 マルチユーザーモードでGUIログインです。(X ベースのログイン画面) |
6 | システムが再起動になる状態 |
- 以下はredhatのランレベルのリンクです。
https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/6/html/installation_guide/s1-boot-init-shutdown-sysv
サービスの自動起動の設定を確認する
CentOS 6では、chkconfigコマンドでサービスの自動起動の設定を確認できます。
コマンド
chkconfigコマンドで、httpd(Apache)の自動起動について確認したサンプルです。
[test@localhost ~]$ chkconfig --list httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
2行目の左端の英字名(httpd)がサービス名です。
数値の0から6がランレベルです。
onが自動起動する、offが自動起動しないという意味です。
3と5がonなので、ランレベルが3と5のときは自動起動します。
chkconfigコマンドのオプション
chkconfigコマンドの主なオプションは以下のものがあります。
コマンド | 説明 |
---|---|
chkconfig --list | サービスの自動起動の設定を表示する。 |
chkconfig --list サービス | 指定したサービスの自動起動の設定を表示する。 例:chkconfig --list httpd |
chkconfig --level レベル サービス (on/off/reset) | サービスの自動起動の設定を切り替える。 例:chkconfig --level 35 httpd off (httpdサービスはレベル3と5で自動起動しない) |
chkconfig --add サービス | サービスの自動起動の設定を追加する。 chkconfig --add httpd |
chkconfig --del サービス | サービスの自動起動の設定を削除する。 chkconfig --del httpd |
ランレベルの設定箇所
/etc/inittabファイルに現状のランレベルの設定箇所があります。
下のinittabファイルの最終行(26行目)の数値がランレベルです。
ランレベルは5になっています。
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
関連の記事
CentOS bashの設定ファイル
CentOS rcスクリプトとランレベル毎のシンボリックリンク
CentOS シンボリックリンク
CentOS bashの機能
CentOS OpenSSHサーバの設定ファイル(sshd_config)
CentOS コマンド一覧
viのコマンド一覧