ランレベルとサービスの自動起動の設定についてです。
目次
ランレベル
- 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
サービスの自動起動の設定
chkconfigコマンドは、システムの起動や停止に関連するコマンドです。
そのコマンドに--listオプションをつけるとサービスの自動起動は、どのランレベルのときに行われるかという一覧が表示されます。
例
以下は、httpd(Apache)の自動起動について確認した図です。
chkconfig −−list httpd
![]()
1行目は、コマンドです。
2行目の左端の英字名(httpd)がサービス名です。
2行目の数値がランレベルで、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 コマンド一覧
CentOS viのコマンド一覧